Sector.ts
1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import Path, { PathProps } from '../Path';
import * as roundSectorHelper from '../helper/roundSector';
export class SectorShape {
cx = 0
cy = 0
r0 = 0
r = 0
startAngle = 0
endAngle = Math.PI * 2
clockwise = true
/**
* Corner radius of sector
*
* clockwise, from inside to outside, four corners are
* inner start -> inner end
* outer start -> outer end
*
* 5 => [5, 5, 5, 5]
* [5] => [5, 5, 0, 0]
* [5, 10] => [5, 5, 10, 10]
* [5, 10, 15] => [5, 10, 15, 15]
* [5, 10, 15, 20] => [5, 10, 15, 20]
*/
cornerRadius: number | number[] = 0
}
export interface SectorProps extends PathProps {
shape?: Partial<SectorShape>
}
class Sector extends Path<SectorProps> {
shape: SectorShape
constructor(opts?: SectorProps) {
super(opts);
}
getDefaultShape() {
return new SectorShape();
}
buildPath(ctx: CanvasRenderingContext2D, shape: SectorShape) {
roundSectorHelper.buildPath(ctx, shape);
}
isZeroArea() {
return this.shape.startAngle === this.shape.endAngle
|| this.shape.r === this.shape.r0;
}
}
Sector.prototype.type = 'sector';
export default Sector;