@antv/g2 5.0.20 → 5.0.22

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 (229) hide show
  1. package/README.md +32 -34
  2. package/README.zh-CN.md +99 -0
  3. package/dist/g2-lite.min.js +4 -4
  4. package/dist/g2.min.js +4 -4
  5. package/esm/api/runtime.js +2 -2
  6. package/esm/api/runtime.js.map +1 -1
  7. package/esm/api/utils.d.ts +5 -0
  8. package/esm/api/utils.js +3 -2
  9. package/esm/api/utils.js.map +1 -1
  10. package/esm/component/axis.d.ts +11 -1
  11. package/esm/component/axis.js +46 -11
  12. package/esm/component/axis.js.map +1 -1
  13. package/esm/component/axisX.js +7 -4
  14. package/esm/component/axisX.js.map +1 -1
  15. package/esm/component/axisY.js +6 -2
  16. package/esm/component/axisY.js.map +1 -1
  17. package/esm/component/axisZ.d.ts +8 -0
  18. package/esm/component/axisZ.js +14 -0
  19. package/esm/component/axisZ.js.map +1 -0
  20. package/esm/component/index.d.ts +1 -0
  21. package/esm/component/index.js +1 -0
  22. package/esm/component/index.js.map +1 -1
  23. package/esm/component/scrollbar.d.ts +2 -1
  24. package/esm/component/scrollbar.js +1 -1
  25. package/esm/component/scrollbar.js.map +1 -1
  26. package/esm/composition/mark.js +3 -1
  27. package/esm/composition/mark.js.map +1 -1
  28. package/esm/coordinate/cartesian3D.d.ts +7 -0
  29. package/esm/coordinate/cartesian3D.js +6 -0
  30. package/esm/coordinate/cartesian3D.js.map +1 -0
  31. package/esm/coordinate/index.d.ts +2 -0
  32. package/esm/coordinate/index.js +1 -0
  33. package/esm/coordinate/index.js.map +1 -1
  34. package/esm/index.d.ts +1 -1
  35. package/esm/index.js +1 -1
  36. package/esm/index.js.map +1 -1
  37. package/esm/interaction/event.js +20 -9
  38. package/esm/interaction/event.js.map +1 -1
  39. package/esm/lib/index.d.ts +1 -0
  40. package/esm/lib/index.js +1 -0
  41. package/esm/lib/index.js.map +1 -1
  42. package/esm/lib/threed.d.ts +5 -0
  43. package/esm/lib/threed.js +11 -0
  44. package/esm/lib/threed.js.map +1 -0
  45. package/esm/mark/index.d.ts +1 -0
  46. package/esm/mark/index.js +1 -0
  47. package/esm/mark/index.js.map +1 -1
  48. package/esm/mark/point3D.d.ts +9 -0
  49. package/esm/mark/point3D.js +76 -0
  50. package/esm/mark/point3D.js.map +1 -0
  51. package/esm/mark/utils.d.ts +7 -0
  52. package/esm/mark/utils.js +6 -0
  53. package/esm/mark/utils.js.map +1 -1
  54. package/esm/runtime/component.js +6 -3
  55. package/esm/runtime/component.js.map +1 -1
  56. package/esm/runtime/coordinate.js +9 -4
  57. package/esm/runtime/coordinate.js.map +1 -1
  58. package/esm/runtime/layout.d.ts +1 -0
  59. package/esm/runtime/layout.js +109 -29
  60. package/esm/runtime/layout.js.map +1 -1
  61. package/esm/runtime/plot.js +5 -3
  62. package/esm/runtime/plot.js.map +1 -1
  63. package/esm/runtime/render.js +12 -3
  64. package/esm/runtime/render.js.map +1 -1
  65. package/esm/runtime/types/common.d.ts +4 -0
  66. package/esm/runtime/types/component.d.ts +8 -2
  67. package/esm/runtime/types/options.d.ts +5 -1
  68. package/esm/shape/index.d.ts +2 -0
  69. package/esm/shape/index.js +2 -0
  70. package/esm/shape/index.js.map +1 -1
  71. package/esm/shape/point3D/cube.d.ts +6 -0
  72. package/esm/shape/point3D/cube.js +70 -0
  73. package/esm/shape/point3D/cube.js.map +1 -0
  74. package/esm/shape/point3D/sphere.d.ts +6 -0
  75. package/esm/shape/point3D/sphere.js +70 -0
  76. package/esm/shape/point3D/sphere.js.map +1 -0
  77. package/esm/shape/shape/shape.js +2 -2
  78. package/esm/shape/shape/shape.js.map +1 -1
  79. package/esm/shape/utils.d.ts +2 -2
  80. package/esm/shape/utils.js +2 -2
  81. package/esm/shape/utils.js.map +1 -1
  82. package/esm/spec/component.d.ts +1 -1
  83. package/esm/spec/composition.d.ts +2 -0
  84. package/esm/spec/coordinate.d.ts +5 -2
  85. package/esm/spec/index.d.ts +1 -0
  86. package/esm/spec/index.js.map +1 -1
  87. package/esm/spec/mark.d.ts +2 -2
  88. package/esm/transform/index.d.ts +1 -0
  89. package/esm/transform/index.js +1 -0
  90. package/esm/transform/index.js.map +1 -1
  91. package/esm/transform/maybeZeroZ.d.ts +6 -0
  92. package/esm/transform/maybeZeroZ.js +22 -0
  93. package/esm/transform/maybeZeroZ.js.map +1 -0
  94. package/esm/utils/size.d.ts +1 -0
  95. package/esm/utils/size.js +1 -0
  96. package/esm/utils/size.js.map +1 -1
  97. package/lib/api/runtime.js +2 -2
  98. package/lib/api/runtime.js.map +1 -1
  99. package/lib/api/utils.d.ts +5 -0
  100. package/lib/api/utils.js +3 -2
  101. package/lib/api/utils.js.map +1 -1
  102. package/lib/component/axis.d.ts +11 -1
  103. package/lib/component/axis.js +48 -12
  104. package/lib/component/axis.js.map +1 -1
  105. package/lib/component/axisX.js +6 -3
  106. package/lib/component/axisX.js.map +1 -1
  107. package/lib/component/axisY.js +5 -1
  108. package/lib/component/axisY.js.map +1 -1
  109. package/lib/component/axisZ.d.ts +8 -0
  110. package/lib/component/axisZ.js +19 -0
  111. package/lib/component/axisZ.js.map +1 -0
  112. package/lib/component/index.d.ts +1 -0
  113. package/lib/component/index.js +3 -1
  114. package/lib/component/index.js.map +1 -1
  115. package/lib/component/scrollbar.d.ts +2 -1
  116. package/lib/component/scrollbar.js +1 -1
  117. package/lib/component/scrollbar.js.map +1 -1
  118. package/lib/composition/mark.js +3 -1
  119. package/lib/composition/mark.js.map +1 -1
  120. package/lib/coordinate/cartesian3D.d.ts +7 -0
  121. package/lib/coordinate/cartesian3D.js +10 -0
  122. package/lib/coordinate/cartesian3D.js.map +1 -0
  123. package/lib/coordinate/index.d.ts +2 -0
  124. package/lib/coordinate/index.js +3 -1
  125. package/lib/coordinate/index.js.map +1 -1
  126. package/lib/index.d.ts +1 -1
  127. package/lib/index.js +2 -1
  128. package/lib/index.js.map +1 -1
  129. package/lib/interaction/event.js +20 -9
  130. package/lib/interaction/event.js.map +1 -1
  131. package/lib/lib/index.d.ts +1 -0
  132. package/lib/lib/index.js +3 -1
  133. package/lib/lib/index.js.map +1 -1
  134. package/lib/lib/threed.d.ts +5 -0
  135. package/lib/lib/threed.js +15 -0
  136. package/lib/lib/threed.js.map +1 -0
  137. package/lib/mark/index.d.ts +1 -0
  138. package/lib/mark/index.js +3 -1
  139. package/lib/mark/index.js.map +1 -1
  140. package/lib/mark/point3D.d.ts +9 -0
  141. package/lib/mark/point3D.js +80 -0
  142. package/lib/mark/point3D.js.map +1 -0
  143. package/lib/mark/utils.d.ts +7 -0
  144. package/lib/mark/utils.js +8 -1
  145. package/lib/mark/utils.js.map +1 -1
  146. package/lib/runtime/component.js +6 -3
  147. package/lib/runtime/component.js.map +1 -1
  148. package/lib/runtime/coordinate.js +8 -3
  149. package/lib/runtime/coordinate.js.map +1 -1
  150. package/lib/runtime/layout.d.ts +1 -0
  151. package/lib/runtime/layout.js +112 -31
  152. package/lib/runtime/layout.js.map +1 -1
  153. package/lib/runtime/plot.js +4 -2
  154. package/lib/runtime/plot.js.map +1 -1
  155. package/lib/runtime/render.js +12 -3
  156. package/lib/runtime/render.js.map +1 -1
  157. package/lib/runtime/types/common.d.ts +4 -0
  158. package/lib/runtime/types/component.d.ts +8 -2
  159. package/lib/runtime/types/options.d.ts +5 -1
  160. package/lib/shape/index.d.ts +2 -0
  161. package/lib/shape/index.js +6 -2
  162. package/lib/shape/index.js.map +1 -1
  163. package/lib/shape/point3D/cube.d.ts +6 -0
  164. package/lib/shape/point3D/cube.js +74 -0
  165. package/lib/shape/point3D/cube.js.map +1 -0
  166. package/lib/shape/point3D/sphere.d.ts +6 -0
  167. package/lib/shape/point3D/sphere.js +74 -0
  168. package/lib/shape/point3D/sphere.js.map +1 -0
  169. package/lib/shape/shape/shape.js +2 -2
  170. package/lib/shape/shape/shape.js.map +1 -1
  171. package/lib/shape/utils.d.ts +2 -2
  172. package/lib/shape/utils.js +2 -2
  173. package/lib/shape/utils.js.map +1 -1
  174. package/lib/spec/component.d.ts +1 -1
  175. package/lib/spec/composition.d.ts +2 -0
  176. package/lib/spec/coordinate.d.ts +5 -2
  177. package/lib/spec/index.d.ts +1 -0
  178. package/lib/spec/index.js.map +1 -1
  179. package/lib/spec/mark.d.ts +2 -2
  180. package/lib/transform/index.d.ts +1 -0
  181. package/lib/transform/index.js +3 -1
  182. package/lib/transform/index.js.map +1 -1
  183. package/lib/transform/maybeZeroZ.d.ts +6 -0
  184. package/lib/transform/maybeZeroZ.js +26 -0
  185. package/lib/transform/maybeZeroZ.js.map +1 -0
  186. package/lib/utils/size.d.ts +1 -0
  187. package/lib/utils/size.js +1 -0
  188. package/lib/utils/size.js.map +1 -1
  189. package/package.json +11 -3
  190. package/src/api/runtime.ts +2 -2
  191. package/src/api/utils.ts +3 -2
  192. package/src/component/axis.ts +65 -9
  193. package/src/component/axisX.ts +8 -3
  194. package/src/component/axisY.ts +8 -3
  195. package/src/component/axisZ.ts +25 -0
  196. package/src/component/index.ts +1 -0
  197. package/src/component/scrollbar.ts +3 -2
  198. package/src/composition/mark.ts +4 -0
  199. package/src/coordinate/cartesian3D.ts +11 -0
  200. package/src/coordinate/index.ts +2 -0
  201. package/src/index.ts +1 -1
  202. package/src/interaction/event.ts +22 -9
  203. package/src/lib/index.ts +1 -0
  204. package/src/lib/threed.ts +11 -0
  205. package/src/mark/index.ts +1 -0
  206. package/src/mark/point3D.ts +90 -0
  207. package/src/mark/utils.ts +7 -0
  208. package/src/runtime/component.ts +6 -0
  209. package/src/runtime/coordinate.ts +18 -10
  210. package/src/runtime/layout.ts +178 -33
  211. package/src/runtime/plot.ts +11 -3
  212. package/src/runtime/render.ts +14 -3
  213. package/src/runtime/types/common.ts +4 -0
  214. package/src/runtime/types/component.ts +10 -1
  215. package/src/runtime/types/options.ts +5 -0
  216. package/src/shape/index.ts +2 -0
  217. package/src/shape/point3D/cube.ts +68 -0
  218. package/src/shape/point3D/sphere.ts +68 -0
  219. package/src/shape/shape/shape.ts +9 -6
  220. package/src/shape/utils.ts +4 -4
  221. package/src/spec/component.ts +1 -1
  222. package/src/spec/composition.ts +2 -0
  223. package/src/spec/coordinate.ts +6 -0
  224. package/src/spec/index.ts +1 -0
  225. package/src/spec/mark.ts +7 -1
  226. package/src/transform/index.ts +1 -0
  227. package/src/transform/maybeZeroZ.ts +25 -0
  228. package/src/utils/size.ts +2 -0
  229. package/README.en-US.md +0 -99
package/src/api/utils.ts CHANGED
@@ -8,6 +8,7 @@ import { Node } from './node';
8
8
  export const VIEW_KEYS = [
9
9
  'width',
10
10
  'height',
11
+ 'depth',
11
12
  'padding',
12
13
  'paddingLeft',
13
14
  'paddingRight',
@@ -63,8 +64,8 @@ export function valueOf(node: Node): Record<string, any> {
63
64
  export function sizeOf(options, container) {
64
65
  const { autoFit } = options;
65
66
  if (autoFit) return getContainerSize(container);
66
- const { width = 640, height = 480 } = options;
67
- return { width, height };
67
+ const { width = 640, height = 480, depth = 0 } = options;
68
+ return { width, height, depth };
68
69
  }
69
70
 
70
71
  export function optionsOf(node: Node): Record<string, any> {
@@ -11,7 +11,9 @@ import {
11
11
  GuideComponentComponent as GCC,
12
12
  GuideComponentOrientation as GCO,
13
13
  GuideComponentPosition as GCP,
14
+ GuideComponentPlane,
14
15
  Scale,
16
+ Vector3,
15
17
  } from '../runtime';
16
18
  import {
17
19
  angleOf,
@@ -24,11 +26,11 @@ import {
24
26
  radiusOf,
25
27
  } from '../utils/coordinate';
26
28
  import { capitalizeFirst } from '../utils/helper';
27
- import { isOrdinalScale } from '../utils/scale';
28
29
  import { adaptor, isVertical, titleContent } from './utils';
29
30
 
30
31
  export type AxisOptions = {
31
32
  position?: GCP;
33
+ plane?: GuideComponentPlane;
32
34
  zIndex?: number;
33
35
  title?: string | string[];
34
36
  direction?: 'left' | 'center' | 'right';
@@ -50,13 +52,31 @@ export type AxisOptions = {
50
52
  grid: any;
51
53
  // options won't be overridden
52
54
  important: Record<string, any>;
55
+ /**
56
+ * Rotation origin.
57
+ */
58
+ origin?: Vector3;
59
+ /**
60
+ * EulerAngles of rotation.
61
+ */
62
+ eulerAngles?: Vector3;
53
63
  [key: string]: any;
54
64
  };
55
65
 
56
- function sizeOf(coordinate: Coordinate): [number, number] {
66
+ export function rotateAxis(axis: DisplayObject, options: AxisOptions) {
67
+ const { eulerAngles, origin } = options;
68
+ if (origin) {
69
+ axis.setOrigin(origin);
70
+ }
71
+ if (eulerAngles) {
72
+ axis.rotate(eulerAngles[0], eulerAngles[1], eulerAngles[2]);
73
+ }
74
+ }
75
+
76
+ function sizeOf(coordinate: Coordinate): [number, number, number] {
57
77
  // @ts-ignore
58
- const { innerWidth, innerHeight } = coordinate.getOptions();
59
- return [innerWidth, innerHeight];
78
+ const { innerWidth, innerHeight, depth } = coordinate.getOptions();
79
+ return [innerWidth, innerHeight, depth];
60
80
  }
61
81
 
62
82
  function createFisheye(position, coordinate) {
@@ -193,10 +213,23 @@ function getData(
193
213
  });
194
214
  }
195
215
 
196
- function inferGridLength(position: GCP, coordinate: Coordinate) {
197
- const [width, height] = sizeOf(coordinate);
198
- if (position.includes('bottom') || position.includes('top')) return height;
199
- return width;
216
+ function inferGridLength(
217
+ position: GCP,
218
+ coordinate: Coordinate,
219
+ plane: GuideComponentPlane = 'xy',
220
+ ) {
221
+ const [width, height, depth] = sizeOf(coordinate);
222
+
223
+ if (plane === 'xy') {
224
+ if (position.includes('bottom') || position.includes('top')) return height;
225
+ return width;
226
+ } else if (plane === 'xz') {
227
+ if (position.includes('bottom') || position.includes('top')) return depth;
228
+ return width;
229
+ } else {
230
+ if (position.includes('bottom') || position.includes('top')) return height;
231
+ return depth;
232
+ }
200
233
  }
201
234
 
202
235
  function inferLabelOverlap(transform = [], style: Record<string, any>) {
@@ -280,6 +313,20 @@ function inferGrid(value: boolean, coordinate: Coordinate, scale: Scale) {
280
313
  return value === undefined ? !!scale.getTicks : value;
281
314
  }
282
315
 
316
+ function infer3DAxisLinearOverrideStyle(coordinate: Coordinate) {
317
+ // @ts-ignore
318
+ const { depth } = coordinate.getOptions();
319
+ return depth
320
+ ? {
321
+ tickIsBillboard: true,
322
+ lineIsBillboard: true,
323
+ labelIsBillboard: true,
324
+ titleIsBillboard: true,
325
+ gridIsBillboard: true,
326
+ }
327
+ : {};
328
+ }
329
+
283
330
  function inferAxisLinearOverrideStyle(
284
331
  position: GCP,
285
332
  orientation: GCO,
@@ -492,6 +539,7 @@ const LinearAxisComponent: GCC<AxisOptions> = (options) => {
492
539
  labelFormatter,
493
540
  order,
494
541
  orientation,
542
+ actualPosition,
495
543
  position,
496
544
  size,
497
545
  style = {},
@@ -523,7 +571,12 @@ const LinearAxisComponent: GCC<AxisOptions> = (options) => {
523
571
  ...userDefinitions,
524
572
  };
525
573
 
526
- const gridLength = inferGridLength(position, coordinate);
574
+ const gridLength = inferGridLength(
575
+ actualPosition || position,
576
+ coordinate,
577
+ options.plane,
578
+ );
579
+
527
580
  const overrideStyle = inferAxisLinearOverrideStyle(
528
581
  position,
529
582
  orientation,
@@ -531,6 +584,8 @@ const LinearAxisComponent: GCC<AxisOptions> = (options) => {
531
584
  coordinate,
532
585
  );
533
586
 
587
+ const threeDOverrideStyle = infer3DAxisLinearOverrideStyle(coordinate);
588
+
534
589
  const data = getData(
535
590
  scale,
536
591
  domain,
@@ -568,6 +623,7 @@ const LinearAxisComponent: GCC<AxisOptions> = (options) => {
568
623
  indexBBox,
569
624
  ...(!internalAxisStyle.line ? { lineOpacity: 0 } : null),
570
625
  ...overrideStyle,
626
+ ...threeDOverrideStyle,
571
627
  ...important,
572
628
  };
573
629
 
@@ -1,5 +1,5 @@
1
1
  import { GuideComponentComponent as GCC } from '../runtime';
2
- import { LinearAxis, AxisOptions } from './axis';
2
+ import { AxisOptions, LinearAxis, rotateAxis } from './axis';
3
3
 
4
4
  export type AxisXOptions = AxisOptions;
5
5
 
@@ -7,9 +7,14 @@ export type AxisXOptions = AxisOptions;
7
7
  * LinearAxis component bind to x scale.
8
8
  */
9
9
  export const AxisX: GCC<AxisXOptions> = (options) => {
10
- return (...args) =>
10
+ return (...args) => {
11
11
  // empirical value for crossPadding
12
- LinearAxis(Object.assign({}, { crossPadding: 50 }, options))(...args);
12
+ const axisX = LinearAxis(Object.assign({}, { crossPadding: 50 }, options))(
13
+ ...args,
14
+ );
15
+ rotateAxis(axisX, options);
16
+ return axisX;
17
+ };
13
18
  };
14
19
 
15
20
  AxisX.props = {
@@ -1,5 +1,5 @@
1
1
  import { GuideComponentComponent as GCC } from '../runtime';
2
- import { AxisOptions, LinearAxis } from './axis';
2
+ import { AxisOptions, LinearAxis, rotateAxis } from './axis';
3
3
 
4
4
  export type AxisYOptions = AxisOptions;
5
5
 
@@ -7,8 +7,13 @@ export type AxisYOptions = AxisOptions;
7
7
  * LinearAxis component bind to y scale.
8
8
  */
9
9
  export const AxisY: GCC<AxisYOptions> = (options) => {
10
- return (...args) =>
11
- LinearAxis(Object.assign({}, { crossPadding: 10 }, options))(...args);
10
+ return (...args) => {
11
+ const axisY = LinearAxis(Object.assign({}, { crossPadding: 10 }, options))(
12
+ ...args,
13
+ );
14
+ rotateAxis(axisY, options);
15
+ return axisY;
16
+ };
12
17
  };
13
18
 
14
19
  AxisY.props = {
@@ -0,0 +1,25 @@
1
+ import { GuideComponentComponent as GCC } from '../runtime';
2
+ import { LinearAxis, AxisOptions, rotateAxis } from './axis';
3
+
4
+ export type AxisXOptions = AxisOptions;
5
+
6
+ /**
7
+ * LinearAxis component bind to z scale.
8
+ */
9
+ export const AxisZ: GCC<AxisXOptions> = (options) => {
10
+ return (...args) => {
11
+ const axisZ = LinearAxis(Object.assign({}, { crossPadding: 10 }, options))(
12
+ ...args,
13
+ );
14
+ rotateAxis(axisZ, options);
15
+ return axisZ;
16
+ };
17
+ };
18
+
19
+ AxisZ.props = {
20
+ ...LinearAxis.props,
21
+ defaultPosition: 'bottom',
22
+ defaultPlane: 'yz',
23
+ };
24
+
25
+ export function axisZConfig() {}
@@ -1,6 +1,7 @@
1
1
  export { LinearAxis as AxisLinear, ArcAxis as AxisArc } from './axis';
2
2
  export { AxisX } from './axisX';
3
3
  export { AxisY } from './axisY';
4
+ export { AxisZ } from './axisZ';
4
5
  export { AxisRadar } from './axisRadar';
5
6
  export { LegendCategory } from './legendCategory';
6
7
  export { LegendContinuous } from './legendContinuous';
@@ -2,7 +2,8 @@ import { Scrollbar as ScrollbarComponent } from '@antv/gui';
2
2
  import { GuideComponentComponent as GCC } from '../runtime';
3
3
 
4
4
  export type ScrollbarOptions = {
5
- orientation: 'horizontal' | 'vertical';
5
+ orientation?: 'horizontal' | 'vertical';
6
+ ratio?: number;
6
7
  [key: string]: any;
7
8
  };
8
9
 
@@ -28,9 +29,9 @@ export const Scrollbar: GCC<ScrollbarOptions> = (options) => {
28
29
  x,
29
30
  y,
30
31
  trackLength: mainSize,
32
+ value: value1,
31
33
  ...rest,
32
34
  orientation,
33
- value: value1,
34
35
  contentLength: actualSize,
35
36
  viewportLength: mainSize,
36
37
  }),
@@ -11,6 +11,7 @@ export const Mark: CC<MarkOptions> = ({
11
11
  const {
12
12
  width,
13
13
  height,
14
+ depth,
14
15
  paddingLeft,
15
16
  paddingRight,
16
17
  paddingTop,
@@ -33,6 +34,7 @@ export const Mark: CC<MarkOptions> = ({
33
34
  interaction,
34
35
  x,
35
36
  y,
37
+ z,
36
38
  key,
37
39
  frame,
38
40
  labelTransform,
@@ -48,9 +50,11 @@ export const Mark: CC<MarkOptions> = ({
48
50
  type: 'standardView',
49
51
  x,
50
52
  y,
53
+ z,
51
54
  key,
52
55
  width,
53
56
  height,
57
+ depth,
54
58
  padding,
55
59
  paddingLeft,
56
60
  paddingRight,
@@ -0,0 +1,11 @@
1
+ import { Coordinate3DComponent as CC } from '../runtime';
2
+ import { Cartesian3DCoordinate } from '../spec';
3
+
4
+ export type Cartesian3DOptions = Cartesian3DCoordinate;
5
+
6
+ /**
7
+ * Default coordinate3D transformation for all charts.
8
+ */
9
+ export const Cartesian3D: CC<Cartesian3DCoordinate> = () => [['cartesian3D']];
10
+
11
+ Cartesian3D.props = {};
@@ -1,4 +1,5 @@
1
1
  export { Cartesian } from './cartesian';
2
+ export { Cartesian3D } from './cartesian3D';
2
3
  export { Polar, getPolarOptions } from './polar';
3
4
  export { Helix } from './helix';
4
5
  export { Transpose } from './transpose';
@@ -9,6 +10,7 @@ export { Fisheye } from './fisheye';
9
10
  export { Radar } from './radar';
10
11
 
11
12
  export type { CartesianOptions } from './cartesian';
13
+ export type { Cartesian3DOptions } from './cartesian3D';
12
14
  export type { PolarOptions } from './polar';
13
15
  export type { HelixOptions } from './helix';
14
16
  export type { TransposeOptions } from './transpose';
package/src/index.ts CHANGED
@@ -15,7 +15,7 @@ export {
15
15
  AREA_CLASS_NAME,
16
16
  } from './runtime';
17
17
 
18
- export { corelib, stdlib, litelib } from './lib';
18
+ export { corelib, stdlib, litelib, threedlib } from './lib';
19
19
 
20
20
  export * from './mark';
21
21
 
@@ -14,14 +14,23 @@ export function dataOf(element, view) {
14
14
  return selectedMark.data[index];
15
15
  }
16
16
 
17
- // For extended shape.
18
- function maybeElementRoot(node) {
19
- if (node.className === 'element') return node;
17
+ function maybeRoot(node, rootOf) {
18
+ if (rootOf(node)) return node;
20
19
  let root = node.parent;
21
- while (root && root.className !== 'element') root = root.parent;
20
+ while (root && !rootOf(root)) root = root.parent;
22
21
  return root;
23
22
  }
24
23
 
24
+ // For extended component
25
+ function maybeComponentRoot(node) {
26
+ return maybeRoot(node, (node) => node.className === 'component');
27
+ }
28
+
29
+ // For extended shape.
30
+ function maybeElementRoot(node) {
31
+ return maybeRoot(node, (node) => node.className === 'element');
32
+ }
33
+
25
34
  function bubblesEvent(eventType, view, emitter, predicate = (event) => true) {
26
35
  return (e) => {
27
36
  if (!predicate(e)) return;
@@ -41,19 +50,23 @@ function bubblesEvent(eventType, view, emitter, predicate = (event) => true) {
41
50
 
42
51
  // If target is element or child of element.
43
52
  const elementRoot = maybeElementRoot(target);
44
- if (!elementRoot) return;
45
- const { className: elementType, markType } = elementRoot;
53
+ // If target is component or child of component.
54
+ const componentRoot = maybeComponentRoot(target);
55
+ const root = elementRoot || componentRoot;
56
+ if (!root) return;
57
+ const { className: elementType, markType } = root;
46
58
  if (elementType === 'element') {
47
59
  const e1 = {
48
60
  ...e,
49
61
  nativeEvent: true,
50
- data: { data: dataOf(elementRoot, view) },
62
+ data: { data: dataOf(root, view) },
51
63
  };
52
64
  emitter.emit(`element:${eventType}`, e1);
53
65
  emitter.emit(`${markType}:${eventType}`, e1);
54
66
  } else {
55
- // @todo Handle click axis and legend.
56
- emitter.emit(`${elementType}:${eventType}`, e);
67
+ const e1 = { ...e, nativeEvent: true };
68
+ emitter.emit(`component:${eventType}`, e1);
69
+ emitter.emit(`${className}:${eventType}`, e1);
57
70
  }
58
71
  };
59
72
  }
package/src/lib/index.ts CHANGED
@@ -2,5 +2,6 @@ export { corelib } from './core';
2
2
  export { geolib } from './geo';
3
3
  export { graphlib } from './graph';
4
4
  export { plotlib } from './plot';
5
+ export { threedlib } from './threed';
5
6
  export { stdlib } from './std';
6
7
  export { litelib } from './lite';
@@ -0,0 +1,11 @@
1
+ import { Cartesian3D } from '../coordinate';
2
+ import { AxisZ } from '../component';
3
+ import { Point3D } from '../mark';
4
+
5
+ export function threedlib() {
6
+ return {
7
+ 'coordinate.cartesian3D': Cartesian3D,
8
+ 'component.axisZ': AxisZ,
9
+ 'mark.point3D': Point3D,
10
+ } as const;
11
+ }
package/src/mark/index.ts CHANGED
@@ -2,6 +2,7 @@ export { Interval } from './interval';
2
2
  export { Rect } from './rect';
3
3
  export { Line } from './line';
4
4
  export { Point } from './point';
5
+ export { Point3D } from './point3D';
5
6
  export { Text } from './text';
6
7
  export { Cell } from './cell';
7
8
  export { Area } from './area';
@@ -0,0 +1,90 @@
1
+ import { Coordinate3D } from '@antv/coord';
2
+ import { MarkComponent as MC, Vector3 } from '../runtime';
3
+ import { PointMark } from '../spec';
4
+ import { MaybeZeroX, MaybeZeroY, MaybeZeroZ, MaybeSize } from '../transform';
5
+ import { Sphere, Cube } from '../shape';
6
+ import {
7
+ baseGeometryChannels,
8
+ basePostInference,
9
+ basePreInference,
10
+ tooltip3d,
11
+ } from './utils';
12
+
13
+ export type PointOptions = Omit<PointMark, 'type'>;
14
+
15
+ /**
16
+ * Convert value for each channel to point shapes.
17
+ * Calc the bbox of each point based on x, y and r.
18
+ * This is for allowing their radius can be affected by coordinate(e.g. fisheye).
19
+ */
20
+ export const Point3D: MC<PointOptions> = (options) => {
21
+ return (index, _, value, coordinate) => {
22
+ const { x: X, y: Y, z: Z, size: S, dx: DX, dy: DY, dz: DZ } = value;
23
+ const [width, height, depth] = (
24
+ coordinate as unknown as Coordinate3D
25
+ ).getSize();
26
+ const xyz: (i: number) => Vector3 = (i) => {
27
+ const dx = +(DX?.[i] || 0);
28
+ const dy = +(DY?.[i] || 0);
29
+ const dz = +(DZ?.[i] || 0);
30
+ const x = +X[i];
31
+ const y = +Y[i];
32
+ const z = +Z[i];
33
+ const cx = x + dx;
34
+ const cy = y + dy;
35
+ const cz = z + dz;
36
+ return [cx, cy, cz];
37
+ };
38
+ const P = S
39
+ ? Array.from(index, (i) => {
40
+ const [cx, cy, cz] = xyz(i);
41
+ const r = +S[i];
42
+ const a = r / width;
43
+ const b = r / height;
44
+ const c = r / depth;
45
+ const p1: Vector3 = [cx - a, cy - b, cz - c];
46
+ const p2: Vector3 = [cx + a, cy + b, cz + c];
47
+ return [
48
+ (coordinate as unknown as Coordinate3D).map([...p1, cz]),
49
+ (coordinate as unknown as Coordinate3D).map([...p2, cz]),
50
+ ] as Vector3[];
51
+ })
52
+ : Array.from(index, (i) => {
53
+ const [cx, cy, cz] = xyz(i);
54
+ return [
55
+ (coordinate as unknown as Coordinate3D).map([cx, cy, cz]),
56
+ ] as Vector3[];
57
+ });
58
+ return [index, P];
59
+ };
60
+ };
61
+
62
+ const shape = {
63
+ sphere: Sphere,
64
+ cube: Cube,
65
+ };
66
+
67
+ Point3D.props = {
68
+ defaultShape: 'cube',
69
+ defaultLabelShape: 'label',
70
+ composite: false,
71
+ shape,
72
+ channels: [
73
+ ...baseGeometryChannels({ shapes: Object.keys(shape) }),
74
+ { name: 'x', required: true },
75
+ { name: 'y', required: true },
76
+ { name: 'z', required: true },
77
+ { name: 'series', scale: 'band' },
78
+ { name: 'size', quantitative: 'sqrt' },
79
+ { name: 'dx', scale: 'identity' },
80
+ { name: 'dy', scale: 'identity' },
81
+ { name: 'dz', scale: 'identity' },
82
+ ],
83
+ preInference: [
84
+ ...basePreInference(),
85
+ { type: MaybeZeroX },
86
+ { type: MaybeZeroY },
87
+ { type: MaybeZeroZ },
88
+ ],
89
+ postInference: [...basePostInference(), { type: MaybeSize }, ...tooltip3d()],
90
+ };
package/src/mark/utils.ts CHANGED
@@ -30,6 +30,13 @@ export function baseGeometryChannels(options: ChannelOptions = {}): Channel[] {
30
30
  return [...baseChannels(options), { name: 'title', scale: 'identity' }];
31
31
  }
32
32
 
33
+ export function tooltip3d() {
34
+ return [
35
+ { type: MaybeTitle, channel: 'color' },
36
+ { type: MaybeTooltip, channel: ['x', 'y', 'z'] },
37
+ ];
38
+ }
39
+
33
40
  export function tooltip2d() {
34
41
  return [
35
42
  { type: MaybeTitle, channel: 'color' },
@@ -102,6 +102,7 @@ export function inferComponent(
102
102
  const { props } = createGuideComponent(type);
103
103
  const {
104
104
  defaultPosition,
105
+ defaultPlane = 'xy',
105
106
  defaultOrientation,
106
107
  defaultSize,
107
108
  defaultOrder,
@@ -148,6 +149,7 @@ export function inferComponent(
148
149
  defaultSize,
149
150
  length,
150
151
  position,
152
+ plane: defaultPlane,
151
153
  orientation,
152
154
  padding,
153
155
  order,
@@ -363,6 +365,10 @@ function inferAxisComponentType(
363
365
  if (isRadial(coordinates)) return ['axisArc', [scale]];
364
366
  return [isTranspose(coordinates) ? 'axisX' : 'axisY', [scale]];
365
367
  }
368
+ // Only support linear axis for z.
369
+ if (name.startsWith('z')) {
370
+ return ['axisZ', [scale]];
371
+ }
366
372
  if (name.startsWith('position')) {
367
373
  if (isRadar(coordinates)) return ['axisRadar', [scale]];
368
374
  if (!isPolar(coordinates)) return ['axisY', [scale]];
@@ -1,4 +1,4 @@
1
- import { Coordinate } from '@antv/coord';
1
+ import { Coordinate, Coordinate3D } from '@antv/coord';
2
2
  import { G2View, G2CoordinateOptions, G2Library } from './types/options';
3
3
  import { CoordinateComponent, CoordinateTransform } from './types/component';
4
4
  import { useLibrary } from './library';
@@ -21,22 +21,27 @@ export function createCoordinate(
21
21
  insetTop,
22
22
  insetRight,
23
23
  insetBottom,
24
- marginLeft,
25
- marginTop,
26
24
  } = layout;
27
25
  const { coordinates: partialTransform = [] } = partialOptions;
28
26
  const transform = inferCoordinate(partialTransform);
29
- const coordinate = new Coordinate({
27
+
28
+ const isCartesian3D = transform[0].type === 'cartesian3D';
29
+ const options = {
30
30
  // @todo Find a better solution.
31
31
  // Store more layout information for component.
32
32
  ...layout,
33
- x: insetLeft + marginLeft,
34
- y: insetTop + marginTop,
33
+ x: insetLeft,
34
+ y: insetTop,
35
35
  width: innerWidth - insetLeft - insetRight,
36
36
  height: innerHeight - insetBottom - insetTop,
37
- transformations: transform.map(useCoordinate).flat(),
38
- });
39
- return coordinate;
37
+ transformations: transform.flatMap(useCoordinate),
38
+ };
39
+
40
+ const coordinate = isCartesian3D
41
+ ? // @ts-ignore
42
+ new Coordinate3D(options)
43
+ : new Coordinate(options);
44
+ return coordinate as Coordinate;
40
45
  }
41
46
 
42
47
  export function coordinate2Transform(node: G2View, library: G2Library): G2View {
@@ -112,6 +117,9 @@ export function isReflectY(coordinates: G2CoordinateOptions[]) {
112
117
  function inferCoordinate(
113
118
  coordinates: G2CoordinateOptions[],
114
119
  ): G2CoordinateOptions[] {
115
- if (coordinates.find((d) => d.type === 'cartesian')) return coordinates;
120
+ if (
121
+ coordinates.find((d) => d.type === 'cartesian' || d.type === 'cartesian3D')
122
+ )
123
+ return coordinates;
116
124
  return [...coordinates, { type: 'cartesian' }];
117
125
  }