@antv/g2 5.0.20 → 5.0.21

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 +10 -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
@@ -12,6 +12,7 @@ import {
12
12
  Section,
13
13
  SectionArea,
14
14
  G2Theme,
15
+ GuideComponentPlane,
15
16
  } from './types/common';
16
17
  import {
17
18
  computeComponentSize,
@@ -24,6 +25,45 @@ import {
24
25
  import { G2GuideComponentOptions, G2Library, G2View } from './types/options';
25
26
  import { isPolar as isPolarOptions } from './coordinate';
26
27
 
28
+ export function processAxisZ(components: G2GuideComponentOptions[]) {
29
+ const axisZ = components.find(({ type }) => type === 'axisZ');
30
+ if (axisZ) {
31
+ const axisX = components.find(({ type }) => type === 'axisX');
32
+ axisX.plane = 'xy';
33
+ const axisY = components.find(({ type }) => type === 'axisY');
34
+ axisY.plane = 'xy';
35
+ axisZ.plane = 'yz';
36
+ axisZ.origin = [axisX.bbox.x, axisX.bbox.y, 0];
37
+ axisZ.eulerAngles = [0, -90, 0];
38
+ axisZ.bbox.x = axisX.bbox.x;
39
+ axisZ.bbox.y = axisX.bbox.y;
40
+ components.push({
41
+ ...axisX,
42
+ plane: 'xz',
43
+ showLabel: false,
44
+ showTitle: false,
45
+ origin: [axisX.bbox.x, axisX.bbox.y, 0],
46
+ eulerAngles: [-90, 0, 0],
47
+ });
48
+ components.push({
49
+ ...axisY,
50
+ plane: 'yz',
51
+ showLabel: false,
52
+ showTitle: false,
53
+ origin: [axisY.bbox.x + axisY.bbox.width, axisY.bbox.y, 0],
54
+ eulerAngles: [0, -90, 0],
55
+ });
56
+ components.push({
57
+ ...axisZ,
58
+ plane: 'xz',
59
+ actualPosition: 'left',
60
+ showLabel: false,
61
+ showTitle: false,
62
+ eulerAngles: [90, -90, 0],
63
+ });
64
+ }
65
+ }
66
+
27
67
  export function computeLayout(
28
68
  components: G2GuideComponentOptions[],
29
69
  options: G2View,
@@ -33,8 +73,10 @@ export function computeLayout(
33
73
  const {
34
74
  width,
35
75
  height,
76
+ depth,
36
77
  x = 0,
37
78
  y = 0,
79
+ z = 0,
38
80
  inset = 0,
39
81
  insetLeft = inset,
40
82
  insetTop = inset,
@@ -109,6 +151,7 @@ export function computeLayout(
109
151
  return {
110
152
  width,
111
153
  height,
154
+ depth,
112
155
  insetLeft,
113
156
  insetTop,
114
157
  insetBottom,
@@ -125,6 +168,7 @@ export function computeLayout(
125
168
  marginRight,
126
169
  x,
127
170
  y,
171
+ z,
128
172
  };
129
173
  }
130
174
 
@@ -314,7 +358,11 @@ export function placeComponents(
314
358
  coordinate: Coordinate,
315
359
  layout: Layout,
316
360
  ): void {
317
- const positionComponents = group(components, (d) => d.position);
361
+ // Group components by plane & position.
362
+ const positionComponents = group<G2GuideComponentOptions, string>(
363
+ components,
364
+ (d) => `${d.plane || 'xy'}-${d.position}`,
365
+ );
318
366
  const {
319
367
  paddingLeft,
320
368
  paddingRight,
@@ -332,8 +380,135 @@ export function placeComponents(
332
380
  insetTop,
333
381
  height,
334
382
  width,
383
+ depth,
335
384
  } = layout;
336
385
 
386
+ const planes = {
387
+ xy: createSection({
388
+ width,
389
+ height,
390
+ paddingLeft,
391
+ paddingRight,
392
+ paddingTop,
393
+ paddingBottom,
394
+ marginLeft,
395
+ marginTop,
396
+ marginBottom,
397
+ marginRight,
398
+ innerHeight,
399
+ innerWidth,
400
+ insetBottom,
401
+ insetLeft,
402
+ insetRight,
403
+ insetTop,
404
+ }),
405
+ yz: createSection({
406
+ width: depth,
407
+ height: height,
408
+ paddingLeft: 0,
409
+ paddingRight: 0,
410
+ paddingTop: 0,
411
+ paddingBottom: 0,
412
+ marginLeft: 0,
413
+ marginTop: 0,
414
+ marginBottom: 0,
415
+ marginRight: 0,
416
+ innerWidth: depth,
417
+ innerHeight: height,
418
+ insetBottom: 0,
419
+ insetLeft: 0,
420
+ insetRight: 0,
421
+ insetTop: 0,
422
+ }),
423
+ xz: createSection({
424
+ width,
425
+ height: depth,
426
+ paddingLeft: 0,
427
+ paddingRight: 0,
428
+ paddingTop: 0,
429
+ paddingBottom: 0,
430
+ marginLeft: 0,
431
+ marginTop: 0,
432
+ marginBottom: 0,
433
+ marginRight: 0,
434
+ innerWidth: width,
435
+ innerHeight: depth,
436
+ insetBottom: 0,
437
+ insetLeft: 0,
438
+ insetRight: 0,
439
+ insetTop: 0,
440
+ }),
441
+ };
442
+
443
+ for (const [key, components] of positionComponents.entries()) {
444
+ const [plane, position] = key.split('-') as [GuideComponentPlane, GCP];
445
+ const area = planes[plane][position];
446
+
447
+ /**
448
+ * @description non-entity components: axis in the center, inner, outer, component in the center
449
+ * @description entity components: other components
450
+ * @description no volume components take up no extra space
451
+ */
452
+
453
+ const [nonEntityComponents, entityComponents] = divide(
454
+ components,
455
+ (component) => {
456
+ if (typeof component.type !== 'string') return false;
457
+ if (position === 'center') return true;
458
+ if (
459
+ component.type.startsWith('axis') &&
460
+ ['inner', 'outer'].includes(position)
461
+ ) {
462
+ return true;
463
+ }
464
+ return false;
465
+ },
466
+ );
467
+
468
+ if (nonEntityComponents.length) {
469
+ placeNonEntityComponents(nonEntityComponents, coordinate, area, position);
470
+ }
471
+ if (entityComponents.length) {
472
+ placePaddingArea(components, coordinate, area);
473
+ }
474
+ }
475
+ }
476
+
477
+ function createSection({
478
+ width,
479
+ height,
480
+ paddingLeft,
481
+ paddingRight,
482
+ paddingTop,
483
+ paddingBottom,
484
+ marginLeft,
485
+ marginTop,
486
+ marginBottom,
487
+ marginRight,
488
+ innerHeight,
489
+ innerWidth,
490
+ insetBottom,
491
+ insetLeft,
492
+ insetRight,
493
+ insetTop,
494
+ }: {
495
+ width: number;
496
+ height: number;
497
+ paddingLeft: number;
498
+ paddingRight: number;
499
+ paddingTop: number;
500
+ paddingBottom: number;
501
+ marginLeft: number;
502
+ marginTop: number;
503
+ marginBottom: number;
504
+ marginRight: number;
505
+ innerHeight: number;
506
+ innerWidth: number;
507
+ insetBottom: number;
508
+ insetLeft: number;
509
+ insetRight: number;
510
+ insetTop: number;
511
+ }): Section {
337
512
  const pl = paddingLeft + marginLeft;
338
513
  const pt = paddingTop + marginTop;
339
514
  const pr = paddingRight + marginRight;
@@ -349,7 +524,7 @@ export function placeComponents(
349
524
  null,
350
525
  ];
351
526
 
352
- const section: Section = {
527
+ const xySection: Section = {
353
528
  top: [pl, 0, innerWidth, pt, 'vertical', true, ascending],
354
529
  right: [width - pr, pt, pr, innerHeight, 'horizontal', false, ascending],
355
530
  bottom: [pl, height - pb, innerWidth, pb, 'vertical', false, ascending],
@@ -379,37 +554,7 @@ export function placeComponents(
379
554
  outer: centerSection,
380
555
  };
381
556
 
382
- for (const [position, components] of positionComponents.entries()) {
383
- const area = section[position];
384
-
385
- /**
386
- * @description non-entity components: axis in the center, inner, outer, component in the center
387
- * @description entity components: other components
388
- * @description no volume components take up no extra space
389
- */
390
-
391
- const [nonEntityComponents, entityComponents] = divide(
392
- components,
393
- (component) => {
394
- if (typeof component.type !== 'string') return false;
395
- if (position === 'center') return true;
396
- if (
397
- component.type.startsWith('axis') &&
398
- ['inner', 'outer'].includes(position)
399
- ) {
400
- return true;
401
- }
402
- return false;
403
- },
404
- );
405
-
406
- if (nonEntityComponents.length) {
407
- placeNonEntityComponents(nonEntityComponents, coordinate, area, position);
408
- }
409
- if (entityComponents.length) {
410
- placePaddingArea(components, coordinate, area);
411
- }
412
- }
557
+ return xySection;
413
558
  }
414
559
 
415
560
  function placeNonEntityComponents(
@@ -33,7 +33,12 @@ import {
33
33
  VIEW_CLASS_NAME,
34
34
  } from './constant';
35
35
  import { coordinate2Transform, createCoordinate } from './coordinate';
36
- import { computeLayout, computeRoughPlotSize, placeComponents } from './layout';
36
+ import {
37
+ computeLayout,
38
+ computeRoughPlotSize,
39
+ placeComponents,
40
+ processAxisZ,
41
+ } from './layout';
37
42
  import { documentOf, useLibrary } from './library';
38
43
  import { initializeMark } from './mark';
39
44
  import {
@@ -626,6 +631,9 @@ function initializeState(
626
631
  // Place components and mutate their bbox.
627
632
  placeComponents(groupComponents(components), coordinate, layout);
628
633
 
634
+ // AxisZ need a copy of axisX and axisY to show grids in X-Z & Y-Z planes.
635
+ processAxisZ(components);
636
+
629
637
  // Scale from marks and components.
630
638
  const scaleInstance = {};
631
639
 
@@ -1552,8 +1560,8 @@ async function applyTransform<T extends G2ViewTree>(
1552
1560
 
1553
1561
  function updateBBox(selection: Selection) {
1554
1562
  selection
1555
- .style('x', (d) => d.paddingLeft)
1556
- .style('y', (d) => d.paddingTop)
1563
+ .style('x', (d) => d.paddingLeft + d.marginLeft)
1564
+ .style('y', (d) => d.paddingTop + d.marginTop)
1557
1565
  .style('width', (d) => d.innerWidth)
1558
1566
  .style('height', (d) => d.innerHeight);
1559
1567
  }
@@ -70,7 +70,7 @@ export function render<T extends G2ViewTree = G2ViewTree>(
70
70
  },
71
71
  ): HTMLElement {
72
72
  // Initialize the context if it is not provided.
73
- const { width = 640, height = 480, theme } = options;
73
+ const { width = 640, height = 480, depth = 0, theme } = options;
74
74
  if (!theme) {
75
75
  error(
76
76
  'ChartOptions.theme is required, such as `const chart = new Chart({ theme: "classic"})`.',
@@ -84,7 +84,11 @@ export function render<T extends G2ViewTree = G2ViewTree>(
84
84
  } = context;
85
85
  context.canvas = canvas;
86
86
  context.emitter = emitter;
87
- canvas.resize(width, height);
87
+
88
+ const { width: prevWidth, height: prevHeight } = canvas.getConfig();
89
+ if (prevWidth !== width || prevHeight !== height) {
90
+ canvas.resize(width, height);
91
+ }
88
92
 
89
93
  emitter.emit(ChartEvent.BEFORE_RENDER);
90
94
 
@@ -93,9 +97,16 @@ export function render<T extends G2ViewTree = G2ViewTree>(
93
97
  const selection = select(canvas.document.documentElement);
94
98
  canvas.ready
95
99
  .then(() =>
96
- plot<T>({ ...keyed, width, height }, selection, library, context),
100
+ plot<T>({ ...keyed, width, height, depth }, selection, library, context),
97
101
  )
98
102
  .then(() => {
103
+ // Place the center of whole scene at z axis' origin.
104
+ if (depth) {
105
+ const [x, y] = canvas!.document.documentElement.getPosition();
106
+ // Since `render` method can be called for multiple times, use setPosition instead of translate here.
107
+ canvas!.document.documentElement.setPosition(x, y, -depth / 2);
108
+ }
109
+
99
110
  // Wait for the next tick.
100
111
  canvas.requestAnimationFrame(() => {
101
112
  emitter.emit(ChartEvent.AFTER_RENDER);
@@ -126,6 +126,7 @@ export type Channel = {
126
126
  };
127
127
 
128
128
  export type Vector2 = [number, number];
129
+ export type Vector3 = [number, number, number];
129
130
 
130
131
  export type BBox = {
131
132
  x?: number;
@@ -152,6 +153,7 @@ export type GuideComponentPosition =
152
153
  | GuideCompositePosition;
153
154
 
154
155
  export type GuideComponentOrientation = 'horizontal' | 'vertical' | number;
156
+ export type GuideComponentPlane = 'xy' | 'xz' | 'yz';
155
157
 
156
158
  export type Layout = {
157
159
  paddingLeft?: number;
@@ -173,6 +175,8 @@ export type Layout = {
173
175
  marginRight?: number;
174
176
  x?: number;
175
177
  y?: number;
178
+ z?: number;
179
+ depth?: number;
176
180
  };
177
181
 
178
182
  export type Direction = 'horizontal' | 'vertical' | 'center';
@@ -1,4 +1,4 @@
1
- import { Coordinate, Transformation } from '@antv/coord';
1
+ import { Coordinate, Transformation, Transformation3D } from '@antv/coord';
2
2
  import EventEmitter from '@antv/event-emitter';
3
3
  import { DisplayObject, IAnimation as GAnimation, IDocument } from '@antv/g';
4
4
  import {
@@ -9,6 +9,7 @@ import {
9
9
  IndexedValue,
10
10
  Vector2,
11
11
  G2MarkState,
12
+ GuideComponentPlane,
12
13
  } from './common';
13
14
  import { DataComponent } from './data';
14
15
  import { Encode, EncodeComponent } from './encode';
@@ -115,6 +116,13 @@ export type CoordinateComponent<O = Record<string, unknown>> = G2BaseComponent<
115
116
  CoordinateProps
116
117
  >;
117
118
 
119
+ export type Coordinate3DTransform = Transformation3D[];
120
+ export type Coordinate3DProps = {
121
+ transform?: boolean;
122
+ };
123
+ export type Coordinate3DComponent<O = Record<string, unknown>> =
124
+ G2BaseComponent<Coordinate3DTransform, O, Coordinate3DProps>;
125
+
118
126
  export type Palette = string[];
119
127
  export type PaletteComponent<O = Record<string, unknown>> = G2BaseComponent<
120
128
  Palette,
@@ -169,6 +177,7 @@ export type GuideComponent = (context: GuideComponentContext) => DisplayObject;
169
177
 
170
178
  export type GuideComponentProps = {
171
179
  defaultPosition?: GuideComponentPosition;
180
+ defaultPlane?: GuideComponentPlane;
172
181
  defaultOrientation?: GuideComponentOrientation;
173
182
  defaultSize?: number;
174
183
  defaultOrder?: number;
@@ -4,6 +4,7 @@ import { Canvas, IAnimation as GAnimation } from '@antv/g';
4
4
  import {
5
5
  G2Title,
6
6
  G2ViewDescriptor,
7
+ GuideComponentPlane,
7
8
  GuideComponentPosition,
8
9
  Layout,
9
10
  Primitive,
@@ -32,6 +33,7 @@ import { TransformComponent } from './transform';
32
33
  export type G2ViewTree = {
33
34
  width?: number;
34
35
  height?: number;
36
+ depth?: number;
35
37
  } & Node;
36
38
 
37
39
  export type Node = {
@@ -68,8 +70,10 @@ export type G2View = {
68
70
  key?: string;
69
71
  x?: number;
70
72
  y?: number;
73
+ z?: number;
71
74
  width?: number;
72
75
  height?: number;
76
+ depth?: number;
73
77
  padding?: number;
74
78
  paddingLeft?: number;
75
79
  paddingRight?: number;
@@ -186,6 +190,7 @@ export type G2GuideComponentOptions = G2BaseComponentOptions<
186
190
  {
187
191
  scale?: G2ScaleOptions;
188
192
  position?: GuideComponentPosition;
193
+ plane?: GuideComponentPlane;
189
194
  size?: number;
190
195
  order?: number;
191
196
  zIndex?: number;
@@ -29,6 +29,8 @@ export { Square as PointSquare } from './point/square';
29
29
  export { Tick as PointTick } from './point/tick';
30
30
  export { Triangle as PointTriangle } from './point/triangle';
31
31
  export { TriangleDown as PointTriangleDown } from './point/triangleDown';
32
+ export { Sphere } from './point3D/sphere';
33
+ export { Cube } from './point3D/cube';
32
34
  export { Vector as VectorShape } from './vector/vector';
33
35
  export { Text as TextShape } from './text/text';
34
36
  export { Badge as TextBadge } from './text/badge';
@@ -0,0 +1,68 @@
1
+ import { MeshPhongMaterial, CubeGeometry, Mesh } from '@antv/g-plugin-3d';
2
+ import { applyStyle, getOrigin, toOpacityKey } from '../utils';
3
+ import { ShapeComponent as SC } from '../../runtime';
4
+ import { select } from '../../utils/selection';
5
+
6
+ const GEOMETRY_SIZE = 5;
7
+
8
+ export type CubeOptions = Record<string, any>;
9
+
10
+ /**
11
+ * @see https://g.antv.antgroup.com/api/3d/geometry#cubegeometry
12
+ */
13
+ export const Cube: SC<CubeOptions> = (options, context) => {
14
+ // Render border only when colorAttribute is stroke.
15
+ const { ...style } = options;
16
+
17
+ // @ts-ignore
18
+ if (!context.cubeGeometry) {
19
+ const renderer = context.canvas.getConfig().renderer;
20
+ const plugin = renderer.getPlugin('device-renderer');
21
+ const device = plugin.getDevice();
22
+ // create a sphere geometry
23
+ // @ts-ignore
24
+ context.cubeGeometry = new CubeGeometry(device, {
25
+ width: GEOMETRY_SIZE * 2,
26
+ height: GEOMETRY_SIZE * 2,
27
+ depth: GEOMETRY_SIZE * 2,
28
+ });
29
+ // create a material with Phong lighting model
30
+ // @ts-ignore
31
+ context.cubeMaterial = new MeshPhongMaterial(device);
32
+ }
33
+
34
+ return (points, value, defaults) => {
35
+ const { color: defaultColor } = defaults;
36
+ const { color = defaultColor, transform, opacity } = value;
37
+ const [cx, cy, cz] = getOrigin(points);
38
+ const r = value.size;
39
+ const finalRadius = r || style.r || defaults.r;
40
+
41
+ const cube = new Mesh({
42
+ style: {
43
+ x: cx,
44
+ y: cy,
45
+ z: cz,
46
+ // @ts-ignore
47
+ geometry: context.cubeGeometry,
48
+ // @ts-ignore
49
+ material: context.cubeMaterial,
50
+ },
51
+ });
52
+ cube.setOrigin(0, 0, 0);
53
+ const scaling = finalRadius / GEOMETRY_SIZE;
54
+ cube.scale(scaling);
55
+
56
+ return select(cube)
57
+ .call(applyStyle, defaults)
58
+ .style('fill', color)
59
+ .style('transform', transform)
60
+ .style(toOpacityKey(options), opacity)
61
+ .call(applyStyle, style)
62
+ .node();
63
+ };
64
+ };
65
+
66
+ Cube.props = {
67
+ defaultMarker: 'cube',
68
+ };
@@ -0,0 +1,68 @@
1
+ import { MeshPhongMaterial, SphereGeometry, Mesh } from '@antv/g-plugin-3d';
2
+ import { applyStyle, getOrigin, toOpacityKey } from '../utils';
3
+ import { ShapeComponent as SC } from '../../runtime';
4
+ import { select } from '../../utils/selection';
5
+
6
+ export type SphereOptions = Record<string, any>;
7
+
8
+ const GEOMETRY_SIZE = 5;
9
+
10
+ /**
11
+ * @see https://g.antv.antgroup.com/api/3d/geometry#spheregeometry
12
+ */
13
+ export const Sphere: SC<SphereOptions> = (options, context) => {
14
+ // Render border only when colorAttribute is stroke.
15
+ const { ...style } = options;
16
+
17
+ // @ts-ignore
18
+ if (!context.sphereGeometry) {
19
+ const renderer = context.canvas.getConfig().renderer;
20
+ const plugin = renderer.getPlugin('device-renderer');
21
+ const device = plugin.getDevice();
22
+ // create a sphere geometry
23
+ // @ts-ignore
24
+ context.sphereGeometry = new SphereGeometry(device, {
25
+ radius: GEOMETRY_SIZE,
26
+ latitudeBands: 32,
27
+ longitudeBands: 32,
28
+ });
29
+ // create a material with Phong lighting model
30
+ // @ts-ignore
31
+ context.sphereMaterial = new MeshPhongMaterial(device);
32
+ }
33
+
34
+ return (points, value, defaults) => {
35
+ const { color: defaultColor } = defaults;
36
+ const { color = defaultColor, transform, opacity } = value;
37
+ const [cx, cy, cz] = getOrigin(points);
38
+ const r = value.size;
39
+ const finalRadius = r || style.r || defaults.r;
40
+
41
+ const sphere = new Mesh({
42
+ style: {
43
+ x: cx,
44
+ y: cy,
45
+ z: cz,
46
+ // @ts-ignore
47
+ geometry: context.sphereGeometry,
48
+ // @ts-ignore
49
+ material: context.sphereMaterial,
50
+ },
51
+ });
52
+ sphere.setOrigin(0, 0, 0);
53
+ const scaling = finalRadius / GEOMETRY_SIZE;
54
+ sphere.scale(scaling);
55
+
56
+ return select(sphere)
57
+ .call(applyStyle, defaults)
58
+ .style('fill', color)
59
+ .style('transform', transform)
60
+ .style(toOpacityKey(options), opacity)
61
+ .call(applyStyle, style)
62
+ .node();
63
+ };
64
+ };
65
+
66
+ Sphere.props = {
67
+ defaultMarker: 'sphere',
68
+ };
@@ -6,15 +6,18 @@ export type ShapeOptions = Record<string, any>;
6
6
  /**
7
7
  * Draw a custom shape.
8
8
  */
9
- export const Shape: SC<ShapeOptions> = (options) => {
9
+ export const Shape: SC<ShapeOptions> = (options, context) => {
10
10
  const { render, ...rest } = options;
11
11
  return (points) => {
12
12
  const [[x0, y0]] = points;
13
- return render({
14
- ...rest,
15
- x: x0,
16
- y: y0,
17
- });
13
+ return render(
14
+ {
15
+ ...rest,
16
+ x: x0,
17
+ y: y0,
18
+ },
19
+ context,
20
+ );
18
21
  };
19
22
  };
20
23
 
@@ -3,7 +3,7 @@ import { Linear } from '@antv/scale';
3
3
  import { lowerFirst } from '@antv/util';
4
4
  import { extent } from 'd3-array';
5
5
  import { Path as D3Path } from 'd3-path';
6
- import { G2Theme, Primitive, Vector2 } from '../runtime';
6
+ import { G2Theme, Primitive, Vector2, Vector3 } from '../runtime';
7
7
  import { indexOf } from '../utils/array';
8
8
  import { isPolar, isTranspose } from '../utils/coordinate';
9
9
  import { Selection } from '../utils/selection';
@@ -212,8 +212,8 @@ export function getTransform(coordinate, value) {
212
212
  return `translate(${center[0]}, ${center[1]}) ${suffix || ''}`;
213
213
  }
214
214
 
215
- export function getOrigin(points: Vector2[]) {
215
+ export function getOrigin(points: (Vector2 | Vector3)[]) {
216
216
  if (points.length === 1) return points[0];
217
- const [[x0, y0], [x2, y2]] = points;
218
- return [(x0 + x2) / 2, (y0 + y2) / 2];
217
+ const [[x0, y0, z0 = 0], [x2, y2, z2 = 0]] = points;
218
+ return [(x0 + x2) / 2, (y0 + y2) / 2, (z0 + z2) / 2];
219
219
  }
@@ -33,7 +33,7 @@ export type TitleComponent = {
33
33
  } & UsePrefix<'title' | 'subtitle', Record<string, any>>;
34
34
 
35
35
  export type AxisComponent = {
36
- type?: 'axisX' | 'axisY';
36
+ type?: 'axisX' | 'axisY' | 'axisZ';
37
37
  tickCount?: number;
38
38
  labelFormatter?: any;
39
39
  tickFilter?: any;
@@ -42,8 +42,10 @@ export type ViewComposition = {
42
42
  type?: 'view';
43
43
  x?: number;
44
44
  y?: number;
45
+ z?: number;
45
46
  width?: number;
46
47
  height?: number;
48
+ depth?: number;
47
49
  data?: Data;
48
50
  key?: string;
49
51
  class?: string;
@@ -7,6 +7,7 @@ export type Coordinate =
7
7
  | ThetaCoordinate
8
8
  | CustomCoordinate
9
9
  | CartesianCoordinate
10
+ | Cartesian3DCoordinate
10
11
  | ParallelCoordinate
11
12
  | RadialCoordinate
12
13
  | RadarCoordinate
@@ -18,6 +19,7 @@ export type CoordinateTypes =
18
19
  | 'transpose'
19
20
  | 'theta'
20
21
  | 'cartesian'
22
+ | 'cartesian3D'
21
23
  | 'parallel'
22
24
  | 'fisheye'
23
25
  | 'radial'
@@ -70,6 +72,10 @@ export type CartesianCoordinate = BaseCoordinate<{
70
72
  type?: 'cartesian';
71
73
  }>;
72
74
 
75
+ export type Cartesian3DCoordinate = BaseCoordinate<{
76
+ type?: 'cartesian3D';
77
+ }>;
78
+
73
79
  export type ParallelCoordinate = BaseCoordinate<{
74
80
  type?: 'parallel';
75
81
  }>;
package/src/spec/index.ts CHANGED
@@ -5,6 +5,7 @@ import { Mark } from './mark';
5
5
  export type G2Spec = (Mark | Composition | AxisComponent | LegendComponent) & {
6
6
  width?: number;
7
7
  height?: number;
8
+ depth?: number;
8
9
  autoFit?: boolean;
9
10
  };
10
11