1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.getAxisTitleText = exports.getAxisDirection = exports.getAxisOption = exports.getCircleAxisCenterRadius = exports.getAxisTitleOptions = exports.getAxisThemeCfg = exports.getAxisFactorByRegion = exports.isVertical = exports.getAxisFactor = exports.getAxisRegion = exports.getCircleAxisRelativeRegion = exports.getLineAxisRelativeRegion = void 0;
|
4 | var util_1 = require("@antv/util");
|
5 | var constant_1 = require("../constant");
|
6 | var scale_1 = require("./scale");
|
7 | var matrix_util_1 = require("@antv/matrix-util");
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 | function getLineAxisRelativeRegion(direction) {
|
15 | var start;
|
16 | var end;
|
17 | switch (direction) {
|
18 | case constant_1.DIRECTION.TOP:
|
19 | start = { x: 0, y: 1 };
|
20 | end = { x: 1, y: 1 };
|
21 | break;
|
22 | case constant_1.DIRECTION.RIGHT:
|
23 | start = { x: 1, y: 0 };
|
24 | end = { x: 1, y: 1 };
|
25 | break;
|
26 | case constant_1.DIRECTION.BOTTOM:
|
27 | start = { x: 0, y: 0 };
|
28 | end = { x: 1, y: 0 };
|
29 | break;
|
30 | case constant_1.DIRECTION.LEFT:
|
31 | start = { x: 0, y: 0 };
|
32 | end = { x: 0, y: 1 };
|
33 | break;
|
34 | default:
|
35 | start = end = { x: 0, y: 0 };
|
36 | }
|
37 | return { start: start, end: end };
|
38 | }
|
39 | exports.getLineAxisRelativeRegion = getLineAxisRelativeRegion;
|
40 |
|
41 |
|
42 |
|
43 |
|
44 |
|
45 |
|
46 | function getCircleAxisRelativeRegion(coordinate) {
|
47 | var start;
|
48 | var end;
|
49 | if (coordinate.isTransposed) {
|
50 | start = {
|
51 | x: 0,
|
52 | y: 0,
|
53 | };
|
54 | end = {
|
55 | x: 1,
|
56 | y: 0,
|
57 | };
|
58 | }
|
59 | else {
|
60 | start = {
|
61 | x: 0,
|
62 | y: 0,
|
63 | };
|
64 | end = {
|
65 | x: 0,
|
66 | y: 1,
|
67 | };
|
68 | }
|
69 | return { start: start, end: end };
|
70 | }
|
71 | exports.getCircleAxisRelativeRegion = getCircleAxisRelativeRegion;
|
72 |
|
73 |
|
74 |
|
75 |
|
76 |
|
77 |
|
78 |
|
79 | function getAxisRegion(coordinate, direction) {
|
80 | var region = { start: { x: 0, y: 0 }, end: { x: 0, y: 0 } };
|
81 | if (coordinate.isRect) {
|
82 | region = getLineAxisRelativeRegion(direction);
|
83 | }
|
84 | else if (coordinate.isPolar) {
|
85 | region = getCircleAxisRelativeRegion(coordinate);
|
86 | }
|
87 | var start = region.start, end = region.end;
|
88 | return {
|
89 | start: coordinate.convert(start),
|
90 | end: coordinate.convert(end),
|
91 | };
|
92 | }
|
93 | exports.getAxisRegion = getAxisRegion;
|
94 |
|
95 |
|
96 |
|
97 |
|
98 |
|
99 |
|
100 |
|
101 | function getAxisFactor(coordinate, direction) {
|
102 |
|
103 | if (coordinate.isRect) {
|
104 | return coordinate.isTransposed
|
105 | ? [constant_1.DIRECTION.RIGHT, constant_1.DIRECTION.BOTTOM].includes(direction)
|
106 | ? 1
|
107 | : -1
|
108 | : [constant_1.DIRECTION.BOTTOM, constant_1.DIRECTION.RIGHT].includes(direction)
|
109 | ? -1
|
110 | : 1;
|
111 | }
|
112 |
|
113 | if (coordinate.isPolar) {
|
114 | var startAngle = coordinate.x.start;
|
115 | return startAngle < 0 ? -1 : 1;
|
116 | }
|
117 | return 1;
|
118 | }
|
119 | exports.getAxisFactor = getAxisFactor;
|
120 |
|
121 |
|
122 |
|
123 |
|
124 |
|
125 |
|
126 | function isVertical(region) {
|
127 | var start = region.start, end = region.end;
|
128 | return start.x === end.x;
|
129 | }
|
130 | exports.isVertical = isVertical;
|
131 |
|
132 |
|
133 |
|
134 |
|
135 |
|
136 |
|
137 |
|
138 | function getAxisFactorByRegion(region, center) {
|
139 | var start = region.start, end = region.end;
|
140 | var isAxisVertical = isVertical(region);
|
141 |
|
142 | if (isAxisVertical) {
|
143 |
|
144 | if ((start.y - end.y) * (center.x - start.x) > 0) {
|
145 | return 1;
|
146 | }
|
147 | else {
|
148 | return -1;
|
149 | }
|
150 | }
|
151 | else {
|
152 |
|
153 | if ((end.x - start.x) * (start.y - center.y) > 0) {
|
154 | return -1;
|
155 | }
|
156 | else {
|
157 | return 1;
|
158 | }
|
159 | }
|
160 | }
|
161 | exports.getAxisFactorByRegion = getAxisFactorByRegion;
|
162 |
|
163 |
|
164 |
|
165 |
|
166 |
|
167 |
|
168 |
|
169 |
|
170 | function getAxisThemeCfg(theme, direction) {
|
171 | var axisTheme = (0, util_1.get)(theme, ['components', 'axis'], {});
|
172 | return (0, util_1.deepMix)({}, (0, util_1.get)(axisTheme, ['common'], {}), (0, util_1.deepMix)({}, (0, util_1.get)(axisTheme, [direction], {})));
|
173 | }
|
174 | exports.getAxisThemeCfg = getAxisThemeCfg;
|
175 |
|
176 |
|
177 |
|
178 |
|
179 |
|
180 |
|
181 |
|
182 | function getAxisTitleOptions(theme, direction, axisOptions) {
|
183 | var axisTheme = (0, util_1.get)(theme, ['components', 'axis'], {});
|
184 | return (0, util_1.deepMix)({}, (0, util_1.get)(axisTheme, ['common', 'title'], {}), (0, util_1.deepMix)({}, (0, util_1.get)(axisTheme, [direction, 'title'], {})), axisOptions);
|
185 | }
|
186 | exports.getAxisTitleOptions = getAxisTitleOptions;
|
187 |
|
188 |
|
189 |
|
190 |
|
191 |
|
192 | function getCircleAxisCenterRadius(coordinate) {
|
193 |
|
194 | var x = coordinate.x, y = coordinate.y, center = coordinate.circleCenter;
|
195 | var isReflectY = y.start > y.end;
|
196 | var start = coordinate.isTransposed
|
197 | ? coordinate.convert({
|
198 | x: isReflectY ? 0 : 1,
|
199 | y: 0,
|
200 | })
|
201 | : coordinate.convert({
|
202 | x: 0,
|
203 | y: isReflectY ? 0 : 1,
|
204 | });
|
205 | var startVector = [start.x - center.x, start.y - center.y];
|
206 | var normalVector = [1, 0];
|
207 | var startAngle = start.y > center.y ? matrix_util_1.vec2.angle(startVector, normalVector) : matrix_util_1.vec2.angle(startVector, normalVector) * -1;
|
208 | var endAngle = startAngle + (x.end - x.start);
|
209 | var radius = Math.sqrt(Math.pow((start.x - center.x), 2) + Math.pow((start.y - center.y), 2));
|
210 | return {
|
211 | center: center,
|
212 | radius: radius,
|
213 | startAngle: startAngle,
|
214 | endAngle: endAngle,
|
215 | };
|
216 | }
|
217 | exports.getCircleAxisCenterRadius = getCircleAxisCenterRadius;
|
218 |
|
219 |
|
220 |
|
221 |
|
222 |
|
223 |
|
224 |
|
225 | function getAxisOption(axes, field) {
|
226 | if ((0, util_1.isBoolean)(axes)) {
|
227 | return axes === false ? false : {};
|
228 | }
|
229 | return (0, util_1.get)(axes, [field]);
|
230 | }
|
231 | exports.getAxisOption = getAxisOption;
|
232 |
|
233 |
|
234 |
|
235 |
|
236 |
|
237 |
|
238 | function getAxisDirection(axisOption, def) {
|
239 | return (0, util_1.get)(axisOption, 'position', def);
|
240 | }
|
241 | exports.getAxisDirection = getAxisDirection;
|
242 |
|
243 |
|
244 |
|
245 |
|
246 |
|
247 | function getAxisTitleText(scale, axisOption) {
|
248 | return (0, util_1.get)(axisOption, ['title', 'text'], (0, scale_1.getName)(scale));
|
249 | }
|
250 | exports.getAxisTitleText = getAxisTitleText;
|
251 |
|
\ | No newline at end of file |