@antv/g2 5.0.0-beta.1 → 5.0.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/g2-lite.min.js +2 -2
- package/dist/g2.min.js +2 -2
- package/esm/animation/morphing.js +10 -8
- package/esm/animation/morphing.js.map +1 -1
- package/esm/api/chart.js +2 -5
- package/esm/api/chart.js.map +1 -1
- package/esm/component/axis.d.ts +1 -2
- package/esm/component/axis.js +81 -198
- package/esm/component/axis.js.map +1 -1
- package/esm/component/legendCategory.d.ts +0 -1
- package/esm/component/legendCategory.js +36 -49
- package/esm/component/legendCategory.js.map +1 -1
- package/esm/component/legendContinuous.js +29 -19
- package/esm/component/legendContinuous.js.map +1 -1
- package/esm/component/utils.d.ts +1 -0
- package/esm/component/utils.js +3 -0
- package/esm/component/utils.js.map +1 -1
- package/esm/composition/facetRect.js +2 -4
- package/esm/composition/facetRect.js.map +1 -1
- package/esm/composition/repeatMatrix.js +2 -2
- package/esm/composition/repeatMatrix.js.map +1 -1
- package/esm/interaction/action/service/legendItemSelection.js.map +1 -1
- package/esm/interaction/action/transformer/setItemState.js.map +1 -1
- package/esm/mark/cell.js +1 -1
- package/esm/shape/area/curve.js +2 -9
- package/esm/shape/area/curve.js.map +1 -1
- package/esm/shape/interval/color.js +2 -2
- package/esm/shape/interval/color.js.map +1 -1
- package/esm/shape/line/curve.js +23 -12
- package/esm/shape/line/curve.js.map +1 -1
- package/esm/shape/line/line.js +6 -2
- package/esm/shape/line/line.js.map +1 -1
- package/esm/shape/line/smooth.js +6 -2
- package/esm/shape/line/smooth.js.map +1 -1
- package/esm/shape/text/advance.js +2 -2
- package/esm/shape/text/advance.js.map +1 -1
- package/esm/shape/utils.d.ts +1 -0
- package/esm/shape/utils.js +8 -1
- package/esm/shape/utils.js.map +1 -1
- package/esm/spec/transform.d.ts +10 -2
- package/esm/stdlib/index.js +2 -2
- package/esm/stdlib/index.js.map +1 -1
- package/esm/theme/dark.js +78 -65
- package/esm/theme/dark.js.map +1 -1
- package/esm/theme/light.js +84 -74
- package/esm/theme/light.js.map +1 -1
- package/esm/transform/groupN.js +2 -0
- package/esm/transform/groupN.js.map +1 -1
- package/esm/transform/index.d.ts +8 -6
- package/esm/transform/index.js +4 -3
- package/esm/transform/index.js.map +1 -1
- package/esm/transform/sample.d.ts +8 -0
- package/esm/transform/sample.js +48 -0
- package/esm/transform/sample.js.map +1 -0
- package/esm/transform/{Select.d.ts → select.d.ts} +0 -0
- package/esm/transform/{Select.js → select.js} +1 -1
- package/esm/transform/{Select.js.map → select.js.map} +1 -1
- package/esm/transform/{SelectX.d.ts → selectX.d.ts} +0 -0
- package/esm/transform/{SelectX.js → selectX.js} +1 -1
- package/esm/transform/{SelectX.js.map → selectX.js.map} +1 -1
- package/esm/transform/{SelectY.d.ts → selectY.d.ts} +0 -0
- package/esm/transform/{SelectY.js → selectY.js} +1 -1
- package/esm/transform/{SelectY.js.map → selectY.js.map} +1 -1
- package/esm/transform/sort.d.ts +1 -1
- package/esm/transform/sort.js +39 -21
- package/esm/transform/sort.js.map +1 -1
- package/lib/animation/morphing.js +10 -8
- package/lib/animation/morphing.js.map +1 -1
- package/lib/api/chart.js +2 -5
- package/lib/api/chart.js.map +1 -1
- package/lib/component/axis.d.ts +1 -2
- package/lib/component/axis.js +80 -197
- package/lib/component/axis.js.map +1 -1
- package/lib/component/legendCategory.d.ts +0 -1
- package/lib/component/legendCategory.js +36 -49
- package/lib/component/legendCategory.js.map +1 -1
- package/lib/component/legendContinuous.js +29 -19
- package/lib/component/legendContinuous.js.map +1 -1
- package/lib/component/utils.d.ts +1 -0
- package/lib/component/utils.js +5 -1
- package/lib/component/utils.js.map +1 -1
- package/lib/composition/facetRect.js +2 -4
- package/lib/composition/facetRect.js.map +1 -1
- package/lib/composition/repeatMatrix.js +2 -2
- package/lib/composition/repeatMatrix.js.map +1 -1
- package/lib/interaction/action/service/legendItemSelection.js.map +1 -1
- package/lib/interaction/action/transformer/setItemState.js.map +1 -1
- package/lib/mark/cell.js +1 -1
- package/lib/shape/area/curve.js +2 -9
- package/lib/shape/area/curve.js.map +1 -1
- package/lib/shape/interval/color.js +2 -2
- package/lib/shape/interval/color.js.map +1 -1
- package/lib/shape/line/curve.js +21 -10
- package/lib/shape/line/curve.js.map +1 -1
- package/lib/shape/line/line.js +5 -1
- package/lib/shape/line/line.js.map +1 -1
- package/lib/shape/line/smooth.js +5 -1
- package/lib/shape/line/smooth.js.map +1 -1
- package/lib/shape/text/advance.js +2 -2
- package/lib/shape/text/advance.js.map +1 -1
- package/lib/shape/utils.d.ts +1 -0
- package/lib/shape/utils.js +9 -1
- package/lib/shape/utils.js.map +1 -1
- package/lib/spec/transform.d.ts +10 -2
- package/lib/stdlib/index.js +1 -1
- package/lib/stdlib/index.js.map +1 -1
- package/lib/theme/dark.js +78 -65
- package/lib/theme/dark.js.map +1 -1
- package/lib/theme/light.js +84 -74
- package/lib/theme/light.js.map +1 -1
- package/lib/transform/groupN.js +2 -0
- package/lib/transform/groupN.js.map +1 -1
- package/lib/transform/index.d.ts +8 -6
- package/lib/transform/index.js +9 -7
- package/lib/transform/index.js.map +1 -1
- package/lib/transform/sample.d.ts +8 -0
- package/lib/transform/sample.js +52 -0
- package/lib/transform/sample.js.map +1 -0
- package/lib/transform/{Select.d.ts → select.d.ts} +0 -0
- package/lib/transform/{Select.js → select.js} +1 -1
- package/lib/transform/{Select.js.map → select.js.map} +1 -1
- package/lib/transform/{SelectX.d.ts → selectX.d.ts} +0 -0
- package/lib/transform/{SelectX.js → selectX.js} +1 -1
- package/lib/transform/{SelectX.js.map → selectX.js.map} +1 -1
- package/lib/transform/{SelectY.d.ts → selectY.d.ts} +0 -0
- package/lib/transform/{SelectY.js → selectY.js} +1 -1
- package/lib/transform/{SelectY.js.map → selectY.js.map} +1 -1
- package/lib/transform/sort.d.ts +1 -1
- package/lib/transform/sort.js +38 -20
- package/lib/transform/sort.js.map +1 -1
- package/package.json +3 -3
- package/src/animation/morphing.ts +12 -8
- package/src/api/chart.ts +2 -5
- package/src/component/axis.ts +233 -310
- package/src/component/legendCategory.ts +52 -68
- package/src/component/legendContinuous.ts +24 -25
- package/src/component/utils.ts +4 -0
- package/src/composition/facetRect.ts +2 -4
- package/src/composition/repeatMatrix.ts +2 -2
- package/src/interaction/action/service/legendItemSelection.ts +1 -2
- package/src/interaction/action/transformer/setItemState.ts +2 -3
- package/src/mark/cell.ts +1 -1
- package/src/shape/area/curve.ts +7 -9
- package/src/shape/interval/color.ts +7 -7
- package/src/shape/line/curve.ts +27 -12
- package/src/shape/line/line.ts +6 -2
- package/src/shape/line/smooth.ts +11 -2
- package/src/shape/text/advance.ts +2 -2
- package/src/shape/utils.ts +8 -1
- package/src/spec/transform.ts +10 -1
- package/src/stdlib/index.ts +2 -0
- package/src/theme/dark.ts +78 -66
- package/src/theme/light.ts +84 -75
- package/src/transform/groupN.ts +2 -0
- package/src/transform/index.ts +8 -6
- package/src/transform/sample.ts +45 -0
- package/src/transform/sort.ts +53 -21
package/src/component/axis.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Coordinate, Vector2 } from '@antv/coord';
|
|
2
|
-
import {
|
|
2
|
+
import { Axis as AxisComponent, AxisStyleProps } from '@antv/gui';
|
|
3
3
|
import { Linear as LinearScale } from '@antv/scale';
|
|
4
|
-
import { deepMix
|
|
4
|
+
import { deepMix } from '@antv/util';
|
|
5
5
|
import { format } from 'd3-format';
|
|
6
6
|
import { extent } from 'd3-array';
|
|
7
7
|
import {
|
|
@@ -18,12 +18,13 @@ import {
|
|
|
18
18
|
GuideComponentPosition,
|
|
19
19
|
Scale,
|
|
20
20
|
} from '../runtime';
|
|
21
|
-
import {
|
|
21
|
+
import { titleContent } from './utils';
|
|
22
22
|
|
|
23
23
|
export type AxisOptions = {
|
|
24
24
|
position?: GuideComponentPosition;
|
|
25
25
|
zIndex?: number;
|
|
26
26
|
title?: string | string[];
|
|
27
|
+
d;
|
|
27
28
|
direction?: 'left' | 'center' | 'right';
|
|
28
29
|
labelFormatter?: (d: any, index: number, array: any) => string;
|
|
29
30
|
tickFilter?: (datum: any, index: number, array: any) => boolean;
|
|
@@ -37,89 +38,6 @@ export type AxisOptions = {
|
|
|
37
38
|
[key: string]: any;
|
|
38
39
|
};
|
|
39
40
|
|
|
40
|
-
function inferPosition(
|
|
41
|
-
position: GuideComponentPosition,
|
|
42
|
-
direction: string,
|
|
43
|
-
bbox: BBox,
|
|
44
|
-
coordinate: Coordinate,
|
|
45
|
-
): {
|
|
46
|
-
startPos: [number, number];
|
|
47
|
-
endPos: [number, number];
|
|
48
|
-
labelOffset: number;
|
|
49
|
-
titlePosition: 'start' | 'end' | 'center';
|
|
50
|
-
titlePadding: number;
|
|
51
|
-
titleRotate: number;
|
|
52
|
-
verticalFactor: 1 | -1;
|
|
53
|
-
titleOffsetY?: number;
|
|
54
|
-
labelAlign?: 'start' | 'end' | 'center' | 'left' | 'right';
|
|
55
|
-
label?: boolean;
|
|
56
|
-
axisLine?: boolean;
|
|
57
|
-
tickLine?: boolean;
|
|
58
|
-
} {
|
|
59
|
-
const { x, y, width, height } = bbox;
|
|
60
|
-
if (position === 'bottom') {
|
|
61
|
-
return {
|
|
62
|
-
startPos: [x, y],
|
|
63
|
-
endPos: [x + width, y],
|
|
64
|
-
labelOffset: 8,
|
|
65
|
-
titlePosition: 'end',
|
|
66
|
-
titlePadding: 2,
|
|
67
|
-
titleRotate: 0,
|
|
68
|
-
verticalFactor: 1,
|
|
69
|
-
};
|
|
70
|
-
} else if (position === 'left' || position === 'centerHorizontal') {
|
|
71
|
-
return {
|
|
72
|
-
startPos: [x + width, y],
|
|
73
|
-
endPos: [x + width, y + height],
|
|
74
|
-
titlePosition: 'center',
|
|
75
|
-
titlePadding: 6,
|
|
76
|
-
titleRotate: -90,
|
|
77
|
-
labelAlign: 'end',
|
|
78
|
-
labelOffset: 4,
|
|
79
|
-
verticalFactor: -1,
|
|
80
|
-
};
|
|
81
|
-
} else if (position === 'right') {
|
|
82
|
-
return {
|
|
83
|
-
startPos: [x, y],
|
|
84
|
-
endPos: [x, y + height],
|
|
85
|
-
titlePosition: 'center',
|
|
86
|
-
titlePadding: 16,
|
|
87
|
-
titleRotate: -90,
|
|
88
|
-
labelAlign: 'start',
|
|
89
|
-
labelOffset: 4,
|
|
90
|
-
verticalFactor: 1,
|
|
91
|
-
};
|
|
92
|
-
} else if (position === 'arcY') {
|
|
93
|
-
return {
|
|
94
|
-
startPos: [x, y],
|
|
95
|
-
endPos: [x + width, y + height],
|
|
96
|
-
titlePosition: 'start',
|
|
97
|
-
titlePadding: 4,
|
|
98
|
-
titleOffsetY: -5,
|
|
99
|
-
titleRotate: 0,
|
|
100
|
-
labelOffset: direction === 'left' ? 4 : direction === 'right' ? -4 : 0,
|
|
101
|
-
verticalFactor: -1,
|
|
102
|
-
labelAlign:
|
|
103
|
-
direction === 'center'
|
|
104
|
-
? 'center'
|
|
105
|
-
: direction === 'right'
|
|
106
|
-
? 'start'
|
|
107
|
-
: undefined,
|
|
108
|
-
axisLine: false,
|
|
109
|
-
};
|
|
110
|
-
}
|
|
111
|
-
// position === 'centerVertical'
|
|
112
|
-
return {
|
|
113
|
-
startPos: [x, y + height],
|
|
114
|
-
endPos: [x + width, y + height],
|
|
115
|
-
titlePosition: 'end',
|
|
116
|
-
titlePadding: 2,
|
|
117
|
-
titleRotate: 0,
|
|
118
|
-
labelOffset: 4,
|
|
119
|
-
verticalFactor: -1,
|
|
120
|
-
};
|
|
121
|
-
}
|
|
122
|
-
|
|
123
41
|
function angleOf(coordinate: Coordinate): [number, number] {
|
|
124
42
|
const { transformations } = coordinate.getOptions();
|
|
125
43
|
const [, startAngle, endAngle] = transformations.find(
|
|
@@ -143,12 +61,9 @@ function sizeOf(coordinate: Coordinate): [number, number] {
|
|
|
143
61
|
}
|
|
144
62
|
|
|
145
63
|
function reverseTicks(ticks) {
|
|
146
|
-
return ticks.map(({ value,
|
|
64
|
+
return ticks.map(({ value, ...rest }) => ({ value: 1 - value, ...rest }));
|
|
147
65
|
}
|
|
148
66
|
|
|
149
|
-
/**
|
|
150
|
-
* @todo More position besides bottom and left.
|
|
151
|
-
*/
|
|
152
67
|
function createFisheye(position, coordinate) {
|
|
153
68
|
const { width, height } = coordinate.getOptions();
|
|
154
69
|
return (tick) => {
|
|
@@ -215,8 +130,6 @@ function createInset(position, coordinate) {
|
|
|
215
130
|
|
|
216
131
|
/**
|
|
217
132
|
* Calc ticks based on scale and coordinate.
|
|
218
|
-
* @todo Parallel coordinate.
|
|
219
|
-
* @todo More position besides bottom and left.
|
|
220
133
|
*/
|
|
221
134
|
function getTicks(
|
|
222
135
|
scale: Scale,
|
|
@@ -247,7 +160,8 @@ function getTicks(
|
|
|
247
160
|
const tick = applyInset(scale.map(d) + offset);
|
|
248
161
|
return {
|
|
249
162
|
value: isTranspose(coordinate) && scale.getTicks?.() ? 1 - tick : tick,
|
|
250
|
-
|
|
163
|
+
label: labelFormatter(d, i, array),
|
|
164
|
+
id: String(i),
|
|
251
165
|
};
|
|
252
166
|
});
|
|
253
167
|
// @todo GUI should consider the overlap problem for the first
|
|
@@ -262,99 +176,205 @@ function getTicks(
|
|
|
262
176
|
const tick = applyFisheye(applyInset(scale.map(d) + offset));
|
|
263
177
|
return {
|
|
264
178
|
value: tick,
|
|
265
|
-
|
|
179
|
+
label: `${labelFormatter(prettyNumber(d), i, array)}`,
|
|
180
|
+
id: String(i),
|
|
266
181
|
};
|
|
267
182
|
});
|
|
268
183
|
}
|
|
269
184
|
|
|
270
|
-
function
|
|
271
|
-
tick: number,
|
|
272
|
-
position: GuideComponentPosition,
|
|
273
|
-
coordinate: Coordinate,
|
|
274
|
-
startPos: Vector2,
|
|
275
|
-
endPos: Vector2,
|
|
276
|
-
) {
|
|
277
|
-
const [sx, sy] = startPos;
|
|
278
|
-
const [ex, ey] = endPos;
|
|
185
|
+
function getGridLength(position: GuideComponentPosition, coordinate) {
|
|
279
186
|
const [width, height] = sizeOf(coordinate);
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
x1 = x2 = sx + (ex - sx) * tick;
|
|
283
|
-
y1 = sy;
|
|
284
|
-
y2 = position === 'bottom' ? sy - height : sy + height;
|
|
285
|
-
} else {
|
|
286
|
-
y1 = y2 = sy + (ey - sy) * tick;
|
|
287
|
-
x1 = sx;
|
|
288
|
-
x2 = position === 'left' ? sx + width : sx - width;
|
|
289
|
-
}
|
|
290
|
-
return [
|
|
291
|
-
[x1, y1],
|
|
292
|
-
[x2, y2],
|
|
293
|
-
];
|
|
187
|
+
if (position === 'bottom' || position === 'top') return height;
|
|
188
|
+
return width;
|
|
294
189
|
}
|
|
295
190
|
|
|
296
|
-
function
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
191
|
+
function labelTransforms(autoHide?: boolean, autoRotate?: boolean) {
|
|
192
|
+
const transforms = [];
|
|
193
|
+
if (autoHide) transforms.push({ type: 'hide' });
|
|
194
|
+
if (autoRotate)
|
|
195
|
+
transforms.push({ type: 'rotate', optionalAngles: [0, 30, 45, 60, 90] });
|
|
196
|
+
return transforms;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
function inferArcStyle(
|
|
200
|
+
position: GuideComponentPosition,
|
|
301
201
|
innerRadius: number,
|
|
302
202
|
outerRadius: number,
|
|
303
203
|
coordinate: Coordinate,
|
|
304
204
|
) {
|
|
305
|
-
const [cx, cy] = center;
|
|
306
205
|
const [w, h] = sizeOf(coordinate);
|
|
307
206
|
const r = Math.min(w, h) / 2;
|
|
308
|
-
|
|
309
|
-
const
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
207
|
+
|
|
208
|
+
const common = {
|
|
209
|
+
titleFillOpacity: 0,
|
|
210
|
+
titlePosition: 'inner',
|
|
211
|
+
showLine: false,
|
|
212
|
+
showTick: true,
|
|
213
|
+
gridLength: (outerRadius - innerRadius) * r,
|
|
214
|
+
};
|
|
215
|
+
|
|
216
|
+
if (position === 'arcInner') {
|
|
217
|
+
const [w, h] = sizeOf(coordinate);
|
|
218
|
+
const r = Math.min(w, h) / 2;
|
|
314
219
|
return {
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
220
|
+
...common,
|
|
221
|
+
labelAlign: 'perpendicular',
|
|
222
|
+
labelDirection: 'positive',
|
|
223
|
+
labelSpacing: 4,
|
|
224
|
+
tickDirection: 'positive',
|
|
225
|
+
gridDirection: 'negative',
|
|
319
226
|
};
|
|
320
|
-
}
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
return {
|
|
230
|
+
...common,
|
|
231
|
+
labelAlign: 'parallel',
|
|
232
|
+
labelDirection: 'negative',
|
|
233
|
+
labelSpacing: 8,
|
|
234
|
+
tickDirection: 'negative',
|
|
235
|
+
gridDirection: 'positive',
|
|
236
|
+
};
|
|
321
237
|
}
|
|
322
238
|
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
ticks: any[],
|
|
328
|
-
position: GuideComponentPosition,
|
|
329
|
-
coordinate: any,
|
|
330
|
-
startPos: Vector2,
|
|
331
|
-
endPos: Vector2,
|
|
332
|
-
) {
|
|
333
|
-
if (isTheta(coordinate) || isParallel(coordinate)) return [];
|
|
334
|
-
return ticks.map((tick) => {
|
|
335
|
-
const points = getTickGridItem(
|
|
336
|
-
tick.value,
|
|
337
|
-
position,
|
|
338
|
-
coordinate,
|
|
339
|
-
startPos,
|
|
340
|
-
endPos,
|
|
341
|
-
);
|
|
342
|
-
const finalPoints = isPolar(coordinate) ? [points[0]] : points;
|
|
343
|
-
return { points: finalPoints };
|
|
344
|
-
});
|
|
239
|
+
function inferGrid(value: boolean, coordinate: Coordinate, scale: Scale) {
|
|
240
|
+
if (isTheta(coordinate) || isParallel(coordinate)) return false;
|
|
241
|
+
// Display axis grid for non-discrete values.
|
|
242
|
+
return value === undefined ? !!scale.getTicks : value;
|
|
345
243
|
}
|
|
346
244
|
|
|
347
|
-
function
|
|
348
|
-
|
|
245
|
+
function inferStyle(
|
|
246
|
+
position: GuideComponentPosition,
|
|
247
|
+
direction: string,
|
|
248
|
+
bbox: BBox,
|
|
249
|
+
coordinate: Coordinate,
|
|
250
|
+
scale: Scale,
|
|
251
|
+
): {
|
|
252
|
+
type: 'linear';
|
|
253
|
+
startPos: [number, number];
|
|
254
|
+
endPos: [number, number];
|
|
255
|
+
labelSpacing: number;
|
|
256
|
+
titlePosition: AxisStyleProps['titlePosition'];
|
|
257
|
+
titleTextBaseline: 'top' | 'bottom' | 'middle';
|
|
258
|
+
titleSpacing?: number;
|
|
259
|
+
titleTransform: string;
|
|
260
|
+
titleTransformOrigin: string;
|
|
261
|
+
labelDirection: 'negative' | 'positive';
|
|
262
|
+
labelTransform?: string;
|
|
263
|
+
tickDirection: 'negative' | 'positive';
|
|
264
|
+
showLabel?: boolean;
|
|
265
|
+
showTick?: boolean;
|
|
266
|
+
showLine?: boolean;
|
|
267
|
+
gridLength: number;
|
|
268
|
+
gridDirection: 'negative' | 'positive';
|
|
269
|
+
gridConnect?: string;
|
|
270
|
+
gridType?: string;
|
|
271
|
+
gridCenter?: Vector2;
|
|
272
|
+
gridControlAngles?: number[];
|
|
273
|
+
girdClosed?: true;
|
|
274
|
+
} {
|
|
275
|
+
const gridLength = getGridLength(position, coordinate);
|
|
276
|
+
const [, cy] = coordinate.getCenter();
|
|
277
|
+
const { x, y, width, height } = bbox;
|
|
278
|
+
|
|
279
|
+
const common = {
|
|
280
|
+
type: 'linear' as const,
|
|
281
|
+
lineArrow: null,
|
|
282
|
+
titleTransform: undefined,
|
|
283
|
+
titleTransformOrigin: 'center',
|
|
284
|
+
labelAlign: 'horizontal',
|
|
285
|
+
gridLength,
|
|
286
|
+
};
|
|
287
|
+
|
|
288
|
+
if (position === 'bottom') {
|
|
289
|
+
return {
|
|
290
|
+
...common,
|
|
291
|
+
startPos: [x, y],
|
|
292
|
+
endPos: [x + width, y],
|
|
293
|
+
titlePosition: scale.getTicks ? 'right-bottom' : 'bottom',
|
|
294
|
+
titleTransform: scale.getTicks ? 'translate(-100%, 0)' : undefined,
|
|
295
|
+
titleSpacing: 10,
|
|
296
|
+
titleTextBaseline: 'bottom',
|
|
297
|
+
labelSpacing: 12,
|
|
298
|
+
labelDirection: 'positive',
|
|
299
|
+
tickDirection: 'positive',
|
|
300
|
+
gridDirection: 'negative',
|
|
301
|
+
};
|
|
302
|
+
} else if (position === 'left' || position === 'centerHorizontal') {
|
|
303
|
+
return {
|
|
304
|
+
...common,
|
|
305
|
+
startPos: [x + width, y],
|
|
306
|
+
endPos: [x + width, y + height],
|
|
307
|
+
titleSpacing: 10,
|
|
308
|
+
titleTextBaseline: 'middle',
|
|
309
|
+
titlePosition: 'left',
|
|
310
|
+
titleTransform: `translate(50%, 0) rotate(-90)`,
|
|
311
|
+
labelSpacing: 4,
|
|
312
|
+
labelDirection: 'positive',
|
|
313
|
+
tickDirection: 'positive',
|
|
314
|
+
gridDirection: 'negative',
|
|
315
|
+
showLine: position === 'centerHorizontal' ? true : undefined,
|
|
316
|
+
};
|
|
317
|
+
} else if (position === 'right') {
|
|
318
|
+
return {
|
|
319
|
+
...common,
|
|
320
|
+
endPos: [x, y + height],
|
|
321
|
+
startPos: [x, y],
|
|
322
|
+
titlePosition: 'right',
|
|
323
|
+
titleSpacing: 0,
|
|
324
|
+
titleTextBaseline: 'top',
|
|
325
|
+
titleTransform: `translate(-50%, 0) rotate(-90)`,
|
|
326
|
+
labelSpacing: 4,
|
|
327
|
+
labelDirection: 'negative',
|
|
328
|
+
tickDirection: 'negative',
|
|
329
|
+
gridDirection: 'positive',
|
|
330
|
+
};
|
|
331
|
+
} else if (position === 'arcY') {
|
|
332
|
+
return {
|
|
333
|
+
...common,
|
|
334
|
+
startPos: [x, y],
|
|
335
|
+
endPos: [x + width, y + height],
|
|
336
|
+
titlePosition: 'top',
|
|
337
|
+
titleSpacing: 0,
|
|
338
|
+
titleTextBaseline: 'bottom',
|
|
339
|
+
labelDirection: direction === 'right' ? 'negative' : 'positive',
|
|
340
|
+
labelTransform: direction === 'center' ? 'translate(50%, 0)' : '',
|
|
341
|
+
tickDirection: direction === 'right' ? 'negative' : 'positive',
|
|
342
|
+
labelSpacing: direction === 'center' ? 0 : 4,
|
|
343
|
+
gridDirection: 'negative',
|
|
344
|
+
gridConnect: 'arc',
|
|
345
|
+
gridType: 'surround',
|
|
346
|
+
gridCenter: [bbox.x, cy + bbox.y],
|
|
347
|
+
gridControlAngles: [90, 180, 360],
|
|
348
|
+
girdClosed: true,
|
|
349
|
+
};
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
return {
|
|
353
|
+
...common,
|
|
354
|
+
startPos: [x, y + height],
|
|
355
|
+
endPos: [x + width, y + height],
|
|
356
|
+
titlePosition: 'top',
|
|
357
|
+
titleSpacing: 0,
|
|
358
|
+
titleTextBaseline: 'middle',
|
|
359
|
+
labelSpacing: 8,
|
|
360
|
+
labelDirection: 'negative',
|
|
361
|
+
tickDirection: 'negative',
|
|
362
|
+
gridDirection: 'positive',
|
|
363
|
+
showLine: position === 'centerVertical' ? true : undefined,
|
|
364
|
+
};
|
|
349
365
|
}
|
|
350
366
|
|
|
351
367
|
const ArcAxis = (options) => {
|
|
352
368
|
const {
|
|
369
|
+
order,
|
|
370
|
+
size,
|
|
353
371
|
position,
|
|
354
372
|
labelFormatter = (d) => `${d}`,
|
|
355
373
|
tickFilter,
|
|
356
374
|
tickCount,
|
|
357
375
|
tickMethod,
|
|
376
|
+
title,
|
|
377
|
+
grid: showGrid = false,
|
|
358
378
|
...rest
|
|
359
379
|
} = options;
|
|
360
380
|
return (scale, value, coordinate, theme) => {
|
|
@@ -375,74 +395,34 @@ const ArcAxis = (options) => {
|
|
|
375
395
|
const radius = Math.min(width, height) / 2;
|
|
376
396
|
const [startAngle, endAngle] = angleOf(coordinate);
|
|
377
397
|
const [innerRadius, outerRadius] = radiusOf(coordinate);
|
|
378
|
-
|
|
379
|
-
const
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
endAngle,
|
|
398
|
-
ticks,
|
|
399
|
-
verticalFactor: position === 'arc' ? 1 : -1,
|
|
400
|
-
axisLine: {
|
|
401
|
-
style: {
|
|
402
|
-
lineWidth: 0,
|
|
403
|
-
strokeOpacity: 0,
|
|
404
|
-
...subObject(rest, 'line'),
|
|
405
|
-
},
|
|
406
|
-
},
|
|
407
|
-
grid: {
|
|
408
|
-
items: gridItems,
|
|
409
|
-
lineStyle: {
|
|
410
|
-
stroke: '#1b1e23',
|
|
411
|
-
strokeOpacity: 0.1,
|
|
412
|
-
lineDash: [0, 0],
|
|
413
|
-
...subObject(rest, 'grid'),
|
|
414
|
-
},
|
|
415
|
-
},
|
|
416
|
-
tickLine: {
|
|
417
|
-
len: 4,
|
|
418
|
-
style: {
|
|
419
|
-
lineWidth: 1,
|
|
420
|
-
stroke: '#BFBFBF',
|
|
421
|
-
...subObject(rest, 'tick'),
|
|
422
|
-
},
|
|
423
|
-
},
|
|
424
|
-
label: {
|
|
425
|
-
// @todo fix bug in @antv/gui related to tangential.
|
|
426
|
-
align: position === 'arcInner' ? 'radial' : 'tangential',
|
|
427
|
-
tickPadding: 2,
|
|
428
|
-
style: subObject(rest, 'label'),
|
|
429
|
-
},
|
|
430
|
-
},
|
|
431
|
-
),
|
|
398
|
+
|
|
399
|
+
const defaultStyle = inferArcStyle(
|
|
400
|
+
position,
|
|
401
|
+
innerRadius,
|
|
402
|
+
outerRadius,
|
|
403
|
+
coordinate,
|
|
404
|
+
);
|
|
405
|
+
const { axis: axisTheme } = theme;
|
|
406
|
+
return new AxisComponent({
|
|
407
|
+
style: deepMix({}, axisTheme, defaultStyle, {
|
|
408
|
+
type: 'arc',
|
|
409
|
+
center,
|
|
410
|
+
radius,
|
|
411
|
+
angleRange: [startAngle, endAngle],
|
|
412
|
+
data: ticks,
|
|
413
|
+
title: titleContent(title),
|
|
414
|
+
showGrid,
|
|
415
|
+
...rest,
|
|
416
|
+
}),
|
|
432
417
|
});
|
|
433
418
|
};
|
|
434
419
|
};
|
|
435
420
|
|
|
436
|
-
/***
|
|
437
|
-
* Four parts:
|
|
438
|
-
* - line
|
|
439
|
-
* - tick
|
|
440
|
-
* - label
|
|
441
|
-
* - grid
|
|
442
|
-
* - title
|
|
443
|
-
*/
|
|
444
421
|
const LinearAxis: GCC<AxisOptions> = (options) => {
|
|
445
422
|
const {
|
|
423
|
+
order,
|
|
424
|
+
size,
|
|
425
|
+
transform,
|
|
446
426
|
position,
|
|
447
427
|
title,
|
|
448
428
|
labelFormatter = (d) => `${d}`,
|
|
@@ -450,25 +430,16 @@ const LinearAxis: GCC<AxisOptions> = (options) => {
|
|
|
450
430
|
tickCount,
|
|
451
431
|
tickFilter,
|
|
452
432
|
tickMethod,
|
|
453
|
-
|
|
454
|
-
|
|
433
|
+
labelAutoHide = false,
|
|
434
|
+
labelAutoRotate = true,
|
|
435
|
+
grid,
|
|
436
|
+
...userDefinitions
|
|
455
437
|
} = options;
|
|
438
|
+
|
|
456
439
|
return (scale, value, coordinate, theme) => {
|
|
457
440
|
const { domain, bbox } = value;
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
endPos,
|
|
461
|
-
labelOffset,
|
|
462
|
-
titlePosition,
|
|
463
|
-
titlePadding,
|
|
464
|
-
titleRotate,
|
|
465
|
-
verticalFactor,
|
|
466
|
-
titleOffsetY,
|
|
467
|
-
labelAlign,
|
|
468
|
-
axisLine,
|
|
469
|
-
label = options.label === undefined ? true : options.label,
|
|
470
|
-
tickLine = options.tickLine === undefined ? true : options.tickLine,
|
|
471
|
-
} = inferPosition(position, direction, bbox, coordinate);
|
|
441
|
+
|
|
442
|
+
const { axis: axisTheme } = theme;
|
|
472
443
|
const ticks = getTicks(
|
|
473
444
|
scale,
|
|
474
445
|
domain,
|
|
@@ -479,86 +450,38 @@ const LinearAxis: GCC<AxisOptions> = (options) => {
|
|
|
479
450
|
position,
|
|
480
451
|
coordinate,
|
|
481
452
|
);
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
?
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
: null,
|
|
509
|
-
axisLine:
|
|
510
|
-
axisLine || Object.keys(axisLineStyle).length
|
|
511
|
-
? { stroke: '#BFBFBF', style: axisLineStyle }
|
|
512
|
-
: null,
|
|
513
|
-
grid: {
|
|
514
|
-
items: gridItems,
|
|
515
|
-
lineStyle: {
|
|
516
|
-
stroke: '#1b1e23',
|
|
517
|
-
strokeOpacity: 0.05,
|
|
518
|
-
lineDash: [0, 0],
|
|
519
|
-
...subObject(rest, 'grid'),
|
|
520
|
-
},
|
|
521
|
-
...(position === 'arcY' && {
|
|
522
|
-
type: 'circle',
|
|
523
|
-
center: [bbox.x, cy + bbox.y],
|
|
524
|
-
closed: true,
|
|
525
|
-
}),
|
|
526
|
-
},
|
|
527
|
-
tickLine: tickLine
|
|
528
|
-
? {
|
|
529
|
-
len: 4,
|
|
530
|
-
style: {
|
|
531
|
-
lineWidth: 1,
|
|
532
|
-
stroke: '#BFBFBF',
|
|
533
|
-
...subObject(rest, 'tick'),
|
|
534
|
-
},
|
|
535
|
-
}
|
|
536
|
-
: null,
|
|
537
|
-
...(title && {
|
|
538
|
-
title: {
|
|
539
|
-
content: titleContent(title),
|
|
540
|
-
// content: 'a',
|
|
541
|
-
titleAnchor: titleAnchor || anchor,
|
|
542
|
-
style: {
|
|
543
|
-
fontWeight: 'bold',
|
|
544
|
-
fillOpacity: 1,
|
|
545
|
-
dy: titleOffsetY,
|
|
546
|
-
textAnchor: anchor,
|
|
547
|
-
...subObject(rest, 'title'),
|
|
548
|
-
},
|
|
549
|
-
titlePadding,
|
|
550
|
-
rotate: titleRotate,
|
|
551
|
-
},
|
|
552
|
-
}),
|
|
553
|
-
}),
|
|
453
|
+
|
|
454
|
+
const showGrid = inferGrid(grid, coordinate, scale);
|
|
455
|
+
|
|
456
|
+
const {
|
|
457
|
+
showLabel = options.label === undefined ? true : options.label,
|
|
458
|
+
showTick = options.tick === undefined ? true : options.tick,
|
|
459
|
+
showLine = options.line === undefined ? false : options.line,
|
|
460
|
+
...defaultStyle
|
|
461
|
+
} = inferStyle(position, direction, bbox, coordinate, scale);
|
|
462
|
+
|
|
463
|
+
const axisStyle = {
|
|
464
|
+
...defaultStyle,
|
|
465
|
+
data: ticks,
|
|
466
|
+
title: titleContent(title),
|
|
467
|
+
showLabel,
|
|
468
|
+
labelTransforms: labelTransforms(labelAutoHide, labelAutoRotate),
|
|
469
|
+
showGrid,
|
|
470
|
+
showTick,
|
|
471
|
+
...userDefinitions,
|
|
472
|
+
// Always showLine, make title could align the end of axis.
|
|
473
|
+
showLine: true,
|
|
474
|
+
...(!showLine ? { lineOpacity: 0 } : null),
|
|
475
|
+
} as AxisStyleProps;
|
|
476
|
+
|
|
477
|
+
return new AxisComponent({
|
|
478
|
+
style: Object.assign({}, axisTheme, axisStyle),
|
|
554
479
|
});
|
|
555
480
|
};
|
|
556
481
|
};
|
|
557
482
|
|
|
558
483
|
/**
|
|
559
484
|
* Guide Component for position channel(e.g. x, y).
|
|
560
|
-
* @todo Render Circular in polar coordinate.
|
|
561
|
-
* @todo Custom style.
|
|
562
485
|
*/
|
|
563
486
|
export const Axis: GCC<AxisOptions> = (options) => {
|
|
564
487
|
const { position, labelFormatter: f = (d) => `${d}` } = options;
|