1 | import { getSectorPath } from './graphics';
|
2 | import { isBetween } from './helper';
|
3 | import { BBox } from './bbox';
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 | export function getXDimensionLength(coordinate) {
|
11 | if (coordinate.isPolar && !coordinate.isTransposed) {
|
12 |
|
13 | return (coordinate.endAngle - coordinate.startAngle) * coordinate.getRadius();
|
14 | }
|
15 |
|
16 | var start = coordinate.convert({ x: 0, y: 0 });
|
17 | var end = coordinate.convert({ x: 1, y: 0 });
|
18 |
|
19 | return Math.sqrt(Math.pow(end.x - start.x, 2) + Math.pow(end.y - start.y, 2));
|
20 | }
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 | export function isFullCircle(coordinate) {
|
28 | if (coordinate.isPolar) {
|
29 | var startAngle = coordinate.startAngle, endAngle = coordinate.endAngle;
|
30 | return endAngle - startAngle === Math.PI * 2;
|
31 | }
|
32 | return false;
|
33 | }
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 |
|
41 | export function getDistanceToCenter(coordinate, point) {
|
42 | var center = coordinate.getCenter();
|
43 | return Math.sqrt(Math.pow((point.x - center.x), 2) + Math.pow((point.y - center.y), 2));
|
44 | }
|
45 |
|
46 |
|
47 |
|
48 |
|
49 |
|
50 |
|
51 | export function isPointInCoordinate(coordinate, point) {
|
52 | var result = false;
|
53 | if (coordinate) {
|
54 | if (coordinate.type === 'theta') {
|
55 | var start = coordinate.start, end = coordinate.end;
|
56 | result = isBetween(point.x, start.x, end.x) && isBetween(point.y, start.y, end.y);
|
57 | }
|
58 | else {
|
59 | var invertPoint = coordinate.invert(point);
|
60 | result = isBetween(invertPoint.x, 0, 1) && isBetween(invertPoint.y, 0, 1);
|
61 | }
|
62 | }
|
63 | return result;
|
64 | }
|
65 |
|
66 |
|
67 |
|
68 |
|
69 | export function getAngleByPoint(coordinate, point) {
|
70 | var center = coordinate.getCenter();
|
71 | return Math.atan2(point.y - center.y, point.x - center.x);
|
72 | }
|
73 |
|
74 |
|
75 |
|
76 |
|
77 |
|
78 |
|
79 | export function getCoordinateClipCfg(coordinate, margin) {
|
80 | if (margin === void 0) { margin = 0; }
|
81 | var start = coordinate.start, end = coordinate.end;
|
82 | var width = coordinate.getWidth();
|
83 | var height = coordinate.getHeight();
|
84 | if (coordinate.isPolar) {
|
85 | var startAngle_1 = coordinate.startAngle, endAngle_1 = coordinate.endAngle;
|
86 | var center_1 = coordinate.getCenter();
|
87 | var radius_1 = coordinate.getRadius();
|
88 | return {
|
89 | type: 'path',
|
90 | startState: {
|
91 | path: getSectorPath(center_1.x, center_1.y, radius_1 + margin, startAngle_1, startAngle_1),
|
92 | },
|
93 | endState: function (ratio) {
|
94 | var diff = (endAngle_1 - startAngle_1) * ratio + startAngle_1;
|
95 | var path = getSectorPath(center_1.x, center_1.y, radius_1 + margin, startAngle_1, diff);
|
96 | return {
|
97 | path: path,
|
98 | };
|
99 | },
|
100 | attrs: {
|
101 | path: getSectorPath(center_1.x, center_1.y, radius_1 + margin, startAngle_1, endAngle_1),
|
102 | },
|
103 | };
|
104 | }
|
105 | var endState;
|
106 | if (coordinate.isTransposed) {
|
107 | endState = {
|
108 | height: height + margin * 2,
|
109 | };
|
110 | }
|
111 | else {
|
112 | endState = {
|
113 | width: width + margin * 2,
|
114 | };
|
115 | }
|
116 | return {
|
117 | type: 'rect',
|
118 | startState: {
|
119 | x: start.x - margin,
|
120 | y: end.y - margin,
|
121 | width: coordinate.isTransposed ? width + margin * 2 : 0,
|
122 | height: coordinate.isTransposed ? 0 : height + margin * 2,
|
123 | },
|
124 | endState: endState,
|
125 | attrs: {
|
126 | x: start.x - margin,
|
127 | y: end.y - margin,
|
128 | width: width + margin * 2,
|
129 | height: height + margin * 2,
|
130 | },
|
131 | };
|
132 | }
|
133 |
|
134 |
|
135 |
|
136 |
|
137 |
|
138 | export function getCoordinateBBox(coordinate, margin) {
|
139 | if (margin === void 0) { margin = 0; }
|
140 | var start = coordinate.start, end = coordinate.end;
|
141 | var width = coordinate.getWidth();
|
142 | var height = coordinate.getHeight();
|
143 | var minX = Math.min(start.x, end.x);
|
144 | var minY = Math.min(start.y, end.y);
|
145 | return BBox.fromRange(minX - margin, minY - margin, minX + width + margin, minY + height + margin);
|
146 | }
|
147 |
|
\ | No newline at end of file |