mirror of
https://github.com/konvajs/konva.git
synced 2025-04-05 12:44:32 +08:00
feat: impliment getSelftRect method for Arc
This commit is contained in:
parent
f771910578
commit
279eaac88c
24
konva.js
24
konva.js
@ -8,7 +8,7 @@
|
|||||||
* Konva JavaScript Framework v8.3.0
|
* Konva JavaScript Framework v8.3.0
|
||||||
* http://konvajs.org/
|
* http://konvajs.org/
|
||||||
* Licensed under the MIT
|
* Licensed under the MIT
|
||||||
* Date: Mon Nov 15 2021
|
* Date: Thu Nov 25 2021
|
||||||
*
|
*
|
||||||
* Original work Copyright (C) 2011 - 2013 by Eric Rowell (KineticJS)
|
* Original work Copyright (C) 2011 - 2013 by Eric Rowell (KineticJS)
|
||||||
* Modified work Copyright (C) 2014 - present by Anton Lavrenov (Konva)
|
* Modified work Copyright (C) 2014 - present by Anton Lavrenov (Konva)
|
||||||
@ -9719,6 +9719,28 @@
|
|||||||
setHeight(height) {
|
setHeight(height) {
|
||||||
this.outerRadius(height / 2);
|
this.outerRadius(height / 2);
|
||||||
}
|
}
|
||||||
|
getSelfRect() {
|
||||||
|
const radius = this.outerRadius();
|
||||||
|
const DEG_TO_RAD = Math.PI / 180;
|
||||||
|
const angle = this.angle() * DEG_TO_RAD;
|
||||||
|
const inc = 1 * DEG_TO_RAD;
|
||||||
|
const xs = [];
|
||||||
|
const ys = [];
|
||||||
|
for (let i = 0; i < angle + inc; i += inc) {
|
||||||
|
xs.push(Math.cos(i));
|
||||||
|
ys.push(Math.sin(i));
|
||||||
|
}
|
||||||
|
const minX = Math.round(radius * Math.min(...xs));
|
||||||
|
const maxX = Math.round(radius * Math.max(...xs));
|
||||||
|
const minY = Math.round(radius * Math.min(...ys));
|
||||||
|
const maxY = Math.round(radius * Math.max(...ys));
|
||||||
|
return {
|
||||||
|
x: minX || 0,
|
||||||
|
y: minY || 0,
|
||||||
|
width: maxX - minX,
|
||||||
|
height: maxY - minY
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Arc.prototype._centroid = true;
|
Arc.prototype._centroid = true;
|
||||||
Arc.prototype.className = 'Arc';
|
Arc.prototype.className = 'Arc';
|
||||||
|
4
konva.min.js
vendored
4
konva.min.js
vendored
File diff suppressed because one or more lines are too long
@ -4,6 +4,7 @@ import { Konva } from '../Global';
|
|||||||
import { GetSet } from '../types';
|
import { GetSet } from '../types';
|
||||||
import { getNumberValidator, getBooleanValidator } from '../Validators';
|
import { getNumberValidator, getBooleanValidator } from '../Validators';
|
||||||
import { _registerNode } from '../Global';
|
import { _registerNode } from '../Global';
|
||||||
|
import { Transform, Util } from '../Util';
|
||||||
|
|
||||||
export interface ArcConfig extends ShapeConfig {
|
export interface ArcConfig extends ShapeConfig {
|
||||||
angle: number;
|
angle: number;
|
||||||
@ -60,6 +61,32 @@ export class Arc extends Shape<ArcConfig> {
|
|||||||
this.outerRadius(height / 2);
|
this.outerRadius(height / 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getSelfRect() {
|
||||||
|
const radius = this.outerRadius()
|
||||||
|
const DEG_TO_RAD = Math.PI / 180;
|
||||||
|
const angle = this.angle() * DEG_TO_RAD;
|
||||||
|
const inc = 1 * DEG_TO_RAD;
|
||||||
|
|
||||||
|
const xs = [];
|
||||||
|
const ys = [];
|
||||||
|
for (let i = 0; i < angle + inc; i += inc ) {
|
||||||
|
xs.push(Math.cos(i));
|
||||||
|
ys.push(Math.sin(i));
|
||||||
|
}
|
||||||
|
|
||||||
|
const minX = Math.round(radius * Math.min(...xs));
|
||||||
|
const maxX = Math.round(radius * Math.max(...xs));
|
||||||
|
const minY = Math.round(radius * Math.min(...ys));
|
||||||
|
const maxY = Math.round(radius * Math.max(...ys));
|
||||||
|
|
||||||
|
return {
|
||||||
|
x: minX || 0,
|
||||||
|
y: minY || 0,
|
||||||
|
width: maxX - minX,
|
||||||
|
height: maxY - minY
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
innerRadius: GetSet<number, this>;
|
innerRadius: GetSet<number, this>;
|
||||||
outerRadius: GetSet<number, this>;
|
outerRadius: GetSet<number, this>;
|
||||||
angle: GetSet<number, this>;
|
angle: GetSet<number, this>;
|
||||||
|
@ -6,5 +6,5 @@
|
|||||||
"lib": ["ES2015", "dom"],
|
"lib": ["ES2015", "dom"],
|
||||||
"module": "CommonJS"
|
"module": "CommonJS"
|
||||||
},
|
},
|
||||||
"include": ["../src/*.ts"]
|
"include": ["../src/**/*.ts"]
|
||||||
}
|
}
|
||||||
|
@ -89,10 +89,10 @@ describe('Arc', function () {
|
|||||||
stage.add(layer);
|
stage.add(layer);
|
||||||
|
|
||||||
assert.deepEqual(arc.getSelfRect(), {
|
assert.deepEqual(arc.getSelfRect(), {
|
||||||
x: -80,
|
x: 0,
|
||||||
y: -80,
|
y: 0,
|
||||||
width: 160,
|
width: 80,
|
||||||
height: 160,
|
height: 80,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -9,5 +9,5 @@
|
|||||||
"declaration": true,
|
"declaration": true,
|
||||||
"removeComments": true
|
"removeComments": true
|
||||||
},
|
},
|
||||||
"include": ["./src/*.ts"],
|
"include": ["./src/**/*.ts"],
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
"outDir": "lib",
|
"outDir": "lib",
|
||||||
"module": "ES2015",
|
"module": "ES2015",
|
||||||
"target": "ES2015",
|
"target": "ES2015",
|
||||||
|
"sourceMap": true,
|
||||||
"noEmitOnError": true,
|
"noEmitOnError": true,
|
||||||
"lib": ["ES2015", "dom"],
|
"lib": ["ES2015", "dom"],
|
||||||
"moduleResolution": "node",
|
"moduleResolution": "node",
|
||||||
@ -11,5 +12,5 @@
|
|||||||
// "noImplicitAny": true,
|
// "noImplicitAny": true,
|
||||||
// "strict": true
|
// "strict": true
|
||||||
},
|
},
|
||||||
"include": ["./src/*.ts"]
|
"include": ["./src/**/*.ts"]
|
||||||
}
|
}
|
||||||
|
@ -6,5 +6,5 @@
|
|||||||
"moduleResolution": "node",
|
"moduleResolution": "node",
|
||||||
"lib": ["ES2015", "dom"]
|
"lib": ["ES2015", "dom"]
|
||||||
},
|
},
|
||||||
"include": ["./src/*.ts"]
|
"include": ["./src/**/*.ts"]
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user