@antv/g2 5.0.0-alpha.4 → 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.
Files changed (181) hide show
  1. package/README.md +29 -27
  2. package/dist/g2-lite.min.js +2 -2
  3. package/dist/g2.min.js +2 -2
  4. package/esm/animation/morphing.js +10 -8
  5. package/esm/animation/morphing.js.map +1 -1
  6. package/esm/api/chart.js +2 -5
  7. package/esm/api/chart.js.map +1 -1
  8. package/esm/component/axis.d.ts +1 -2
  9. package/esm/component/axis.js +81 -198
  10. package/esm/component/axis.js.map +1 -1
  11. package/esm/component/legendCategory.d.ts +0 -1
  12. package/esm/component/legendCategory.js +36 -49
  13. package/esm/component/legendCategory.js.map +1 -1
  14. package/esm/component/legendContinuous.js +29 -19
  15. package/esm/component/legendContinuous.js.map +1 -1
  16. package/esm/component/utils.d.ts +1 -0
  17. package/esm/component/utils.js +3 -0
  18. package/esm/component/utils.js.map +1 -1
  19. package/esm/composition/facetRect.js +2 -4
  20. package/esm/composition/facetRect.js.map +1 -1
  21. package/esm/composition/repeatMatrix.js +2 -2
  22. package/esm/composition/repeatMatrix.js.map +1 -1
  23. package/esm/interaction/action/service/legendItemSelection.js.map +1 -1
  24. package/esm/interaction/action/transformer/setItemState.js.map +1 -1
  25. package/esm/mark/cell.js +1 -1
  26. package/esm/mark/pack.js +2 -2
  27. package/esm/mark/pack.js.map +1 -1
  28. package/esm/mark/sankey.js +1 -0
  29. package/esm/mark/sankey.js.map +1 -1
  30. package/esm/mark/treemap.js +2 -2
  31. package/esm/mark/treemap.js.map +1 -1
  32. package/esm/mark/wordCloud.js +2 -2
  33. package/esm/mark/wordCloud.js.map +1 -1
  34. package/esm/shape/area/curve.js +2 -9
  35. package/esm/shape/area/curve.js.map +1 -1
  36. package/esm/shape/interval/color.js +2 -2
  37. package/esm/shape/interval/color.js.map +1 -1
  38. package/esm/shape/line/curve.js +23 -12
  39. package/esm/shape/line/curve.js.map +1 -1
  40. package/esm/shape/line/line.js +6 -2
  41. package/esm/shape/line/line.js.map +1 -1
  42. package/esm/shape/line/smooth.js +6 -2
  43. package/esm/shape/line/smooth.js.map +1 -1
  44. package/esm/shape/text/advance.js +2 -2
  45. package/esm/shape/text/advance.js.map +1 -1
  46. package/esm/shape/utils.d.ts +1 -0
  47. package/esm/shape/utils.js +8 -1
  48. package/esm/shape/utils.js.map +1 -1
  49. package/esm/spec/geometry.d.ts +2 -2
  50. package/esm/spec/transform.d.ts +10 -2
  51. package/esm/stdlib/index.js +2 -2
  52. package/esm/stdlib/index.js.map +1 -1
  53. package/esm/theme/dark.js +78 -65
  54. package/esm/theme/dark.js.map +1 -1
  55. package/esm/theme/light.js +84 -74
  56. package/esm/theme/light.js.map +1 -1
  57. package/esm/transform/groupN.js +2 -0
  58. package/esm/transform/groupN.js.map +1 -1
  59. package/esm/transform/index.d.ts +8 -6
  60. package/esm/transform/index.js +4 -3
  61. package/esm/transform/index.js.map +1 -1
  62. package/esm/transform/sample.d.ts +8 -0
  63. package/esm/transform/sample.js +48 -0
  64. package/esm/transform/sample.js.map +1 -0
  65. package/esm/transform/{Select.d.ts → select.d.ts} +0 -0
  66. package/esm/transform/{Select.js → select.js} +1 -1
  67. package/esm/transform/{Select.js.map → select.js.map} +1 -1
  68. package/esm/transform/{SelectX.d.ts → selectX.d.ts} +0 -0
  69. package/esm/transform/{SelectX.js → selectX.js} +1 -1
  70. package/esm/transform/{SelectX.js.map → selectX.js.map} +1 -1
  71. package/esm/transform/{SelectY.d.ts → selectY.d.ts} +0 -0
  72. package/esm/transform/{SelectY.js → selectY.js} +1 -1
  73. package/esm/transform/{SelectY.js.map → selectY.js.map} +1 -1
  74. package/esm/transform/sort.d.ts +1 -1
  75. package/esm/transform/sort.js +39 -21
  76. package/esm/transform/sort.js.map +1 -1
  77. package/lib/animation/morphing.js +10 -8
  78. package/lib/animation/morphing.js.map +1 -1
  79. package/lib/api/chart.js +2 -5
  80. package/lib/api/chart.js.map +1 -1
  81. package/lib/component/axis.d.ts +1 -2
  82. package/lib/component/axis.js +80 -197
  83. package/lib/component/axis.js.map +1 -1
  84. package/lib/component/legendCategory.d.ts +0 -1
  85. package/lib/component/legendCategory.js +36 -49
  86. package/lib/component/legendCategory.js.map +1 -1
  87. package/lib/component/legendContinuous.js +29 -19
  88. package/lib/component/legendContinuous.js.map +1 -1
  89. package/lib/component/utils.d.ts +1 -0
  90. package/lib/component/utils.js +5 -1
  91. package/lib/component/utils.js.map +1 -1
  92. package/lib/composition/facetRect.js +2 -4
  93. package/lib/composition/facetRect.js.map +1 -1
  94. package/lib/composition/repeatMatrix.js +2 -2
  95. package/lib/composition/repeatMatrix.js.map +1 -1
  96. package/lib/interaction/action/service/legendItemSelection.js.map +1 -1
  97. package/lib/interaction/action/transformer/setItemState.js.map +1 -1
  98. package/lib/mark/cell.js +1 -1
  99. package/lib/mark/pack.js +2 -2
  100. package/lib/mark/pack.js.map +1 -1
  101. package/lib/mark/sankey.js +1 -0
  102. package/lib/mark/sankey.js.map +1 -1
  103. package/lib/mark/treemap.js +2 -2
  104. package/lib/mark/treemap.js.map +1 -1
  105. package/lib/mark/wordCloud.js +2 -2
  106. package/lib/mark/wordCloud.js.map +1 -1
  107. package/lib/shape/area/curve.js +2 -9
  108. package/lib/shape/area/curve.js.map +1 -1
  109. package/lib/shape/interval/color.js +2 -2
  110. package/lib/shape/interval/color.js.map +1 -1
  111. package/lib/shape/line/curve.js +21 -10
  112. package/lib/shape/line/curve.js.map +1 -1
  113. package/lib/shape/line/line.js +5 -1
  114. package/lib/shape/line/line.js.map +1 -1
  115. package/lib/shape/line/smooth.js +5 -1
  116. package/lib/shape/line/smooth.js.map +1 -1
  117. package/lib/shape/text/advance.js +2 -2
  118. package/lib/shape/text/advance.js.map +1 -1
  119. package/lib/shape/utils.d.ts +1 -0
  120. package/lib/shape/utils.js +9 -1
  121. package/lib/shape/utils.js.map +1 -1
  122. package/lib/spec/geometry.d.ts +2 -2
  123. package/lib/spec/transform.d.ts +10 -2
  124. package/lib/stdlib/index.js +1 -1
  125. package/lib/stdlib/index.js.map +1 -1
  126. package/lib/theme/dark.js +78 -65
  127. package/lib/theme/dark.js.map +1 -1
  128. package/lib/theme/light.js +84 -74
  129. package/lib/theme/light.js.map +1 -1
  130. package/lib/transform/groupN.js +2 -0
  131. package/lib/transform/groupN.js.map +1 -1
  132. package/lib/transform/index.d.ts +8 -6
  133. package/lib/transform/index.js +9 -7
  134. package/lib/transform/index.js.map +1 -1
  135. package/lib/transform/sample.d.ts +8 -0
  136. package/lib/transform/sample.js +52 -0
  137. package/lib/transform/sample.js.map +1 -0
  138. package/lib/transform/{Select.d.ts → select.d.ts} +0 -0
  139. package/lib/transform/{Select.js → select.js} +1 -1
  140. package/lib/transform/{Select.js.map → select.js.map} +1 -1
  141. package/lib/transform/{SelectX.d.ts → selectX.d.ts} +0 -0
  142. package/lib/transform/{SelectX.js → selectX.js} +1 -1
  143. package/lib/transform/{SelectX.js.map → selectX.js.map} +1 -1
  144. package/lib/transform/{SelectY.d.ts → selectY.d.ts} +0 -0
  145. package/lib/transform/{SelectY.js → selectY.js} +1 -1
  146. package/lib/transform/{SelectY.js.map → selectY.js.map} +1 -1
  147. package/lib/transform/sort.d.ts +1 -1
  148. package/lib/transform/sort.js +38 -20
  149. package/lib/transform/sort.js.map +1 -1
  150. package/package.json +3 -3
  151. package/src/animation/morphing.ts +12 -8
  152. package/src/api/chart.ts +2 -5
  153. package/src/component/axis.ts +233 -310
  154. package/src/component/legendCategory.ts +52 -68
  155. package/src/component/legendContinuous.ts +24 -25
  156. package/src/component/utils.ts +4 -0
  157. package/src/composition/facetRect.ts +2 -4
  158. package/src/composition/repeatMatrix.ts +2 -2
  159. package/src/interaction/action/service/legendItemSelection.ts +1 -2
  160. package/src/interaction/action/transformer/setItemState.ts +2 -3
  161. package/src/mark/cell.ts +1 -1
  162. package/src/mark/pack.ts +1 -0
  163. package/src/mark/sankey.ts +1 -0
  164. package/src/mark/treemap.ts +1 -0
  165. package/src/mark/wordCloud.ts +1 -0
  166. package/src/shape/area/curve.ts +7 -9
  167. package/src/shape/interval/color.ts +7 -7
  168. package/src/shape/line/curve.ts +27 -12
  169. package/src/shape/line/line.ts +6 -2
  170. package/src/shape/line/smooth.ts +11 -2
  171. package/src/shape/text/advance.ts +2 -2
  172. package/src/shape/utils.ts +8 -1
  173. package/src/spec/geometry.ts +2 -1
  174. package/src/spec/transform.ts +10 -1
  175. package/src/stdlib/index.ts +2 -0
  176. package/src/theme/dark.ts +78 -66
  177. package/src/theme/light.ts +84 -75
  178. package/src/transform/groupN.ts +2 -0
  179. package/src/transform/index.ts +8 -6
  180. package/src/transform/sample.ts +45 -0
  181. package/src/transform/sort.ts +53 -21
@@ -1,7 +1,7 @@
1
1
  import { Coordinate, Vector2 } from '@antv/coord';
2
- import { Arc, Linear } from '@antv/gui';
2
+ import { Axis as AxisComponent, AxisStyleProps } from '@antv/gui';
3
3
  import { Linear as LinearScale } from '@antv/scale';
4
- import { deepMix, size } from '@antv/util';
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 { subObject } from '../utils/helper';
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, text }) => ({ value: 1 - value, text }));
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
- text: labelFormatter(d, i, array),
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
- text: `${labelFormatter(prettyNumber(d), i, array)}`,
179
+ label: `${labelFormatter(prettyNumber(d), i, array)}`,
180
+ id: String(i),
266
181
  };
267
182
  });
268
183
  }
269
184
 
270
- function getTickGridItem(
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
- let x1, x2, y1, y2;
281
- if (position === 'bottom' || position === 'top') {
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 getArcGridItems(
297
- ticks: any[],
298
- center: [number, number],
299
- startAngle: number,
300
- endAngle: number,
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
- const ir = innerRadius * r;
309
- const or = outerRadius * r;
310
- return ticks.map(({ value }) => {
311
- const angle = (endAngle - startAngle) * value + startAngle;
312
- const dx = Math.cos((angle * Math.PI) / 180);
313
- const dy = Math.sin((angle * Math.PI) / 180);
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
- points: [
316
- [cx + ir * dx, cy + ir * dy],
317
- [cx + or * dx, cy + or * dy],
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
- * @todo render grid in arcY positioned axis.
325
- */
326
- function getGridItems(
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 titleContent(field: string | string[]): string {
348
- return Array.isArray(field) ? field.join(', ') : `${field}`;
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
- const { grid: showGrid = false } = rest;
379
- const gridItems = showGrid
380
- ? getArcGridItems(
381
- ticks,
382
- center,
383
- startAngle,
384
- endAngle,
385
- innerRadius,
386
- outerRadius,
387
- coordinate,
388
- )
389
- : [];
390
- return new Arc({
391
- style: deepMix(
392
- {},
393
- {
394
- center,
395
- radius,
396
- startAngle,
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
- titleAnchor,
454
- ...rest
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
- const {
459
- startPos,
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
- const anchor =
483
- position === 'arcY' || scale.getTicks ? titlePosition : 'center';
484
- const [, cy] = coordinate.getCenter();
485
- // Display axis grid for non-discrete values.
486
- const { grid: showGrid = !!scale.getTicks } = rest;
487
- const gridItems = showGrid
488
- ? getGridItems(ticks, position, coordinate, startPos, endPos)
489
- : [];
490
- const axisLineStyle = subObject(rest, 'line');
491
- return new Linear({
492
- style: deepMix({
493
- startPos,
494
- endPos,
495
- verticalFactor,
496
- ticks,
497
- label: label
498
- ? {
499
- tickPadding: labelOffset,
500
- autoHide: false,
501
- autoRotate: true,
502
- ...subObject(rest, 'label'),
503
- style: {
504
- ...(labelAlign && { textAlign: labelAlign }),
505
- ...subObject(rest, 'label'),
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;