[d565449] | 1 | "use strict";
|
---|
| 2 | Object.defineProperty(exports, "__esModule", { value: true });
|
---|
| 3 | exports.Arc = void 0;
|
---|
| 4 | const Factory_1 = require("../Factory");
|
---|
| 5 | const Shape_1 = require("../Shape");
|
---|
| 6 | const Global_1 = require("../Global");
|
---|
| 7 | const Validators_1 = require("../Validators");
|
---|
| 8 | const Global_2 = require("../Global");
|
---|
| 9 | class Arc extends Shape_1.Shape {
|
---|
| 10 | _sceneFunc(context) {
|
---|
| 11 | var angle = Global_1.Konva.getAngle(this.angle()), clockwise = this.clockwise();
|
---|
| 12 | context.beginPath();
|
---|
| 13 | context.arc(0, 0, this.outerRadius(), 0, angle, clockwise);
|
---|
| 14 | context.arc(0, 0, this.innerRadius(), angle, 0, !clockwise);
|
---|
| 15 | context.closePath();
|
---|
| 16 | context.fillStrokeShape(this);
|
---|
| 17 | }
|
---|
| 18 | getWidth() {
|
---|
| 19 | return this.outerRadius() * 2;
|
---|
| 20 | }
|
---|
| 21 | getHeight() {
|
---|
| 22 | return this.outerRadius() * 2;
|
---|
| 23 | }
|
---|
| 24 | setWidth(width) {
|
---|
| 25 | this.outerRadius(width / 2);
|
---|
| 26 | }
|
---|
| 27 | setHeight(height) {
|
---|
| 28 | this.outerRadius(height / 2);
|
---|
| 29 | }
|
---|
| 30 | getSelfRect() {
|
---|
| 31 | const innerRadius = this.innerRadius();
|
---|
| 32 | const outerRadius = this.outerRadius();
|
---|
| 33 | const clockwise = this.clockwise();
|
---|
| 34 | const angle = Global_1.Konva.getAngle(clockwise ? 360 - this.angle() : this.angle());
|
---|
| 35 | const boundLeftRatio = Math.cos(Math.min(angle, Math.PI));
|
---|
| 36 | const boundRightRatio = 1;
|
---|
| 37 | const boundTopRatio = Math.sin(Math.min(Math.max(Math.PI, angle), (3 * Math.PI) / 2));
|
---|
| 38 | const boundBottomRatio = Math.sin(Math.min(angle, Math.PI / 2));
|
---|
| 39 | const boundLeft = boundLeftRatio * (boundLeftRatio > 0 ? innerRadius : outerRadius);
|
---|
| 40 | const boundRight = boundRightRatio * (boundRightRatio > 0 ? outerRadius : innerRadius);
|
---|
| 41 | const boundTop = boundTopRatio * (boundTopRatio > 0 ? innerRadius : outerRadius);
|
---|
| 42 | const boundBottom = boundBottomRatio * (boundBottomRatio > 0 ? outerRadius : innerRadius);
|
---|
| 43 | return {
|
---|
| 44 | x: boundLeft,
|
---|
| 45 | y: clockwise ? -1 * boundBottom : boundTop,
|
---|
| 46 | width: boundRight - boundLeft,
|
---|
| 47 | height: boundBottom - boundTop,
|
---|
| 48 | };
|
---|
| 49 | }
|
---|
| 50 | }
|
---|
| 51 | exports.Arc = Arc;
|
---|
| 52 | Arc.prototype._centroid = true;
|
---|
| 53 | Arc.prototype.className = 'Arc';
|
---|
| 54 | Arc.prototype._attrsAffectingSize = ['innerRadius', 'outerRadius'];
|
---|
| 55 | (0, Global_2._registerNode)(Arc);
|
---|
| 56 | Factory_1.Factory.addGetterSetter(Arc, 'innerRadius', 0, (0, Validators_1.getNumberValidator)());
|
---|
| 57 | Factory_1.Factory.addGetterSetter(Arc, 'outerRadius', 0, (0, Validators_1.getNumberValidator)());
|
---|
| 58 | Factory_1.Factory.addGetterSetter(Arc, 'angle', 0, (0, Validators_1.getNumberValidator)());
|
---|
| 59 | Factory_1.Factory.addGetterSetter(Arc, 'clockwise', false, (0, Validators_1.getBooleanValidator)());
|
---|