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