2021-05-05 22:54:03 +08:00
|
|
|
import { Factory } from '../Factory';
|
|
|
|
import { Shape, ShapeConfig } from '../Shape';
|
2019-01-02 04:59:27 +08:00
|
|
|
import { GetSet } from '../types';
|
2021-05-05 22:54:03 +08:00
|
|
|
import { getNumberValidator } from '../Validators';
|
|
|
|
import { _registerNode } from '../Global';
|
2019-01-02 04:59:27 +08:00
|
|
|
|
2019-03-10 23:31:13 +08:00
|
|
|
export interface RingConfig extends ShapeConfig {
|
|
|
|
innerRadius: number;
|
|
|
|
outerRadius: number;
|
|
|
|
}
|
|
|
|
|
2019-01-06 16:01:20 +08:00
|
|
|
var PIx2 = Math.PI * 2;
|
2019-01-02 04:59:27 +08:00
|
|
|
/**
|
|
|
|
* Ring constructor
|
|
|
|
* @constructor
|
|
|
|
* @augments Konva.Shape
|
2019-02-19 01:12:03 +08:00
|
|
|
* @memberof Konva
|
2019-01-02 04:59:27 +08:00
|
|
|
* @param {Object} config
|
|
|
|
* @param {Number} config.innerRadius
|
|
|
|
* @param {Number} config.outerRadius
|
|
|
|
* @@shapeParams
|
|
|
|
* @@nodeParams
|
|
|
|
* @example
|
|
|
|
* var ring = new Konva.Ring({
|
|
|
|
* innerRadius: 40,
|
|
|
|
* outerRadius: 80,
|
|
|
|
* fill: 'red',
|
|
|
|
* stroke: 'black',
|
|
|
|
* strokeWidth: 5
|
|
|
|
* });
|
|
|
|
*/
|
2019-03-10 23:31:13 +08:00
|
|
|
export class Ring extends Shape<RingConfig> {
|
2019-01-02 04:59:27 +08:00
|
|
|
_sceneFunc(context) {
|
|
|
|
context.beginPath();
|
|
|
|
context.arc(0, 0, this.innerRadius(), 0, PIx2, false);
|
|
|
|
context.moveTo(this.outerRadius(), 0);
|
|
|
|
context.arc(0, 0, this.outerRadius(), PIx2, 0, true);
|
|
|
|
context.closePath();
|
|
|
|
context.fillStrokeShape(this);
|
|
|
|
}
|
|
|
|
getWidth() {
|
|
|
|
return this.outerRadius() * 2;
|
|
|
|
}
|
|
|
|
getHeight() {
|
|
|
|
return this.outerRadius() * 2;
|
|
|
|
}
|
|
|
|
setWidth(width) {
|
2019-02-19 21:36:16 +08:00
|
|
|
this.outerRadius(width / 2);
|
2019-01-02 04:59:27 +08:00
|
|
|
}
|
|
|
|
setHeight(height) {
|
2019-02-19 21:36:16 +08:00
|
|
|
this.outerRadius(height / 2);
|
2019-01-02 04:59:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
outerRadius: GetSet<number, this>;
|
|
|
|
innerRadius: GetSet<number, this>;
|
|
|
|
}
|
|
|
|
|
2019-01-06 16:01:20 +08:00
|
|
|
Ring.prototype.className = 'Ring';
|
|
|
|
Ring.prototype._centroid = true;
|
2019-02-19 21:36:16 +08:00
|
|
|
Ring.prototype._attrsAffectingSize = ['innerRadius', 'outerRadius'];
|
2019-02-27 21:06:04 +08:00
|
|
|
_registerNode(Ring);
|
2019-01-06 16:01:20 +08:00
|
|
|
|
2019-01-02 04:59:27 +08:00
|
|
|
/**
|
|
|
|
* get/set innerRadius
|
|
|
|
* @method
|
2019-01-06 16:01:20 +08:00
|
|
|
* @name Konva.Ring#innerRadius
|
2019-01-02 04:59:27 +08:00
|
|
|
* @param {Number} innerRadius
|
|
|
|
* @returns {Number}
|
|
|
|
* @example
|
|
|
|
* // get inner radius
|
|
|
|
* var innerRadius = ring.innerRadius();
|
|
|
|
*
|
|
|
|
* // set inner radius
|
|
|
|
* ring.innerRadius(20);
|
|
|
|
*/
|
2019-01-06 16:01:20 +08:00
|
|
|
|
2019-02-25 01:06:04 +08:00
|
|
|
Factory.addGetterSetter(Ring, 'innerRadius', 0, getNumberValidator());
|
2019-01-02 04:59:27 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* get/set outerRadius
|
2019-01-06 16:01:20 +08:00
|
|
|
* @name Konva.Ring#outerRadius
|
2019-01-02 04:59:27 +08:00
|
|
|
* @method
|
|
|
|
* @param {Number} outerRadius
|
|
|
|
* @returns {Number}
|
|
|
|
* @example
|
|
|
|
* // get outer radius
|
|
|
|
* var outerRadius = ring.outerRadius();
|
|
|
|
*
|
|
|
|
* // set outer radius
|
|
|
|
* ring.outerRadius(20);
|
|
|
|
*/
|
2019-02-25 01:06:04 +08:00
|
|
|
Factory.addGetterSetter(Ring, 'outerRadius', 0, getNumberValidator());
|