@antv/g2 5.0.22 → 5.0.24

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 (236) hide show
  1. package/CHANGELOG.md +325 -0
  2. package/dist/g2-lite.min.js +3 -3
  3. package/dist/g2.min.js +3 -3
  4. package/esm/api/chart.d.ts +9 -17
  5. package/esm/api/chart.js.map +1 -1
  6. package/esm/api/extend.d.ts +5 -1
  7. package/esm/api/extend.js.map +1 -1
  8. package/esm/api/index.d.ts +1 -1
  9. package/esm/api/index.js.map +1 -1
  10. package/esm/api/library.d.ts +6 -16
  11. package/esm/api/runtime.js +4 -1
  12. package/esm/api/runtime.js.map +1 -1
  13. package/esm/component/axis.js +15 -10
  14. package/esm/component/axis.js.map +1 -1
  15. package/esm/component/legendCategory.js +2 -2
  16. package/esm/component/legendCategory.js.map +1 -1
  17. package/esm/component/legendContinuous.js +4 -5
  18. package/esm/component/legendContinuous.js.map +1 -1
  19. package/esm/component/scrollbar.js +2 -0
  20. package/esm/component/scrollbar.js.map +1 -1
  21. package/esm/component/slider.js +2 -0
  22. package/esm/component/slider.js.map +1 -1
  23. package/esm/component/title.js +4 -2
  24. package/esm/component/title.js.map +1 -1
  25. package/esm/component/utils.d.ts +1 -1
  26. package/esm/component/utils.js +2 -3
  27. package/esm/component/utils.js.map +1 -1
  28. package/esm/composition/facetRect.js +2 -2
  29. package/esm/composition/facetRect.js.map +1 -1
  30. package/esm/composition/repeatMatrix.js +3 -3
  31. package/esm/composition/repeatMatrix.js.map +1 -1
  32. package/esm/index.d.ts +2 -2
  33. package/esm/index.js +1 -1
  34. package/esm/index.js.map +1 -1
  35. package/esm/interaction/brushHighlight.js.map +1 -1
  36. package/esm/interaction/tooltip.js +4 -3
  37. package/esm/interaction/tooltip.js.map +1 -1
  38. package/esm/lib/builtinlib.d.ts +13 -0
  39. package/esm/lib/builtinlib.js +21 -0
  40. package/esm/lib/builtinlib.js.map +1 -0
  41. package/esm/lib/core.d.ts +2 -12
  42. package/esm/lib/core.js +8 -19
  43. package/esm/lib/core.js.map +1 -1
  44. package/esm/lib/graph.d.ts +5 -0
  45. package/esm/lib/graph.js +7 -1
  46. package/esm/lib/graph.js.map +1 -1
  47. package/esm/lib/plot.d.ts +0 -5
  48. package/esm/lib/plot.js +2 -7
  49. package/esm/lib/plot.js.map +1 -1
  50. package/esm/lib/std.d.ts +6 -16
  51. package/esm/lib/threed.d.ts +1 -0
  52. package/esm/lib/threed.js +2 -1
  53. package/esm/lib/threed.js.map +1 -1
  54. package/esm/mark/index.d.ts +1 -0
  55. package/esm/mark/index.js +1 -0
  56. package/esm/mark/index.js.map +1 -1
  57. package/esm/mark/line3D.d.ts +7 -0
  58. package/esm/mark/line3D.js +65 -0
  59. package/esm/mark/line3D.js.map +1 -0
  60. package/esm/runtime/component.js +33 -30
  61. package/esm/runtime/component.js.map +1 -1
  62. package/esm/runtime/layout.js +79 -28
  63. package/esm/runtime/layout.js.map +1 -1
  64. package/esm/runtime/library.d.ts +1 -1
  65. package/esm/runtime/library.js +3 -1
  66. package/esm/runtime/library.js.map +1 -1
  67. package/esm/runtime/plot.js +42 -42
  68. package/esm/runtime/plot.js.map +1 -1
  69. package/esm/runtime/render.js +1 -4
  70. package/esm/runtime/render.js.map +1 -1
  71. package/esm/runtime/scale.js +2 -0
  72. package/esm/runtime/scale.js.map +1 -1
  73. package/esm/runtime/types/common.d.ts +3 -1
  74. package/esm/runtime/types/theme.d.ts +8 -2
  75. package/esm/shape/connector/connector.js +19 -30
  76. package/esm/shape/connector/connector.js.map +1 -1
  77. package/esm/shape/index.d.ts +1 -0
  78. package/esm/shape/index.js +1 -0
  79. package/esm/shape/index.js.map +1 -1
  80. package/esm/shape/line3D/line.d.ts +3 -0
  81. package/esm/shape/line3D/line.js +30 -0
  82. package/esm/shape/line3D/line.js.map +1 -0
  83. package/esm/shape/point3D/cube.js +2 -2
  84. package/esm/shape/point3D/cube.js.map +1 -1
  85. package/esm/shape/point3D/sphere.js +2 -2
  86. package/esm/shape/point3D/sphere.js.map +1 -1
  87. package/esm/theme/classic.js +54 -37
  88. package/esm/theme/classic.js.map +1 -1
  89. package/esm/theme/index.d.ts +1 -0
  90. package/esm/theme/index.js +1 -0
  91. package/esm/theme/index.js.map +1 -1
  92. package/esm/theme/light.d.ts +6 -0
  93. package/esm/theme/light.js +476 -0
  94. package/esm/theme/light.js.map +1 -0
  95. package/esm/utils/selection.d.ts +1 -1
  96. package/esm/utils/selection.js +10 -10
  97. package/esm/utils/selection.js.map +1 -1
  98. package/esm/utils/size.js +1 -1
  99. package/lib/api/chart.d.ts +9 -17
  100. package/lib/api/chart.js.map +1 -1
  101. package/lib/api/extend.d.ts +5 -1
  102. package/lib/api/extend.js.map +1 -1
  103. package/lib/api/index.d.ts +1 -1
  104. package/lib/api/index.js.map +1 -1
  105. package/lib/api/library.d.ts +6 -16
  106. package/lib/api/runtime.js +4 -1
  107. package/lib/api/runtime.js.map +1 -1
  108. package/lib/component/axis.js +14 -9
  109. package/lib/component/axis.js.map +1 -1
  110. package/lib/component/legendCategory.js +2 -2
  111. package/lib/component/legendCategory.js.map +1 -1
  112. package/lib/component/legendContinuous.js +4 -5
  113. package/lib/component/legendContinuous.js.map +1 -1
  114. package/lib/component/scrollbar.js +2 -0
  115. package/lib/component/scrollbar.js.map +1 -1
  116. package/lib/component/slider.js +2 -0
  117. package/lib/component/slider.js.map +1 -1
  118. package/lib/component/title.js +4 -2
  119. package/lib/component/title.js.map +1 -1
  120. package/lib/component/utils.d.ts +1 -1
  121. package/lib/component/utils.js +2 -3
  122. package/lib/component/utils.js.map +1 -1
  123. package/lib/composition/facetRect.js +2 -2
  124. package/lib/composition/facetRect.js.map +1 -1
  125. package/lib/composition/repeatMatrix.js +3 -3
  126. package/lib/composition/repeatMatrix.js.map +1 -1
  127. package/lib/index.d.ts +2 -2
  128. package/lib/index.js +4 -1
  129. package/lib/index.js.map +1 -1
  130. package/lib/interaction/brushHighlight.js.map +1 -1
  131. package/lib/interaction/tooltip.js +4 -3
  132. package/lib/interaction/tooltip.js.map +1 -1
  133. package/lib/lib/builtinlib.d.ts +13 -0
  134. package/lib/lib/builtinlib.js +25 -0
  135. package/lib/lib/builtinlib.js.map +1 -0
  136. package/lib/lib/core.d.ts +2 -12
  137. package/lib/lib/core.js +1 -12
  138. package/lib/lib/core.js.map +1 -1
  139. package/lib/lib/graph.d.ts +5 -0
  140. package/lib/lib/graph.js +6 -0
  141. package/lib/lib/graph.js.map +1 -1
  142. package/lib/lib/plot.d.ts +0 -5
  143. package/lib/lib/plot.js +0 -5
  144. package/lib/lib/plot.js.map +1 -1
  145. package/lib/lib/std.d.ts +6 -16
  146. package/lib/lib/threed.d.ts +1 -0
  147. package/lib/lib/threed.js +1 -0
  148. package/lib/lib/threed.js.map +1 -1
  149. package/lib/mark/index.d.ts +1 -0
  150. package/lib/mark/index.js +3 -1
  151. package/lib/mark/index.js.map +1 -1
  152. package/lib/mark/line3D.d.ts +7 -0
  153. package/lib/mark/line3D.js +69 -0
  154. package/lib/mark/line3D.js.map +1 -0
  155. package/lib/runtime/component.js +33 -30
  156. package/lib/runtime/component.js.map +1 -1
  157. package/lib/runtime/layout.js +77 -26
  158. package/lib/runtime/layout.js.map +1 -1
  159. package/lib/runtime/library.d.ts +1 -1
  160. package/lib/runtime/library.js +3 -1
  161. package/lib/runtime/library.js.map +1 -1
  162. package/lib/runtime/plot.js +42 -42
  163. package/lib/runtime/plot.js.map +1 -1
  164. package/lib/runtime/render.js +1 -4
  165. package/lib/runtime/render.js.map +1 -1
  166. package/lib/runtime/scale.js +2 -0
  167. package/lib/runtime/scale.js.map +1 -1
  168. package/lib/runtime/types/common.d.ts +3 -1
  169. package/lib/runtime/types/theme.d.ts +8 -2
  170. package/lib/shape/connector/connector.js +19 -30
  171. package/lib/shape/connector/connector.js.map +1 -1
  172. package/lib/shape/index.d.ts +1 -0
  173. package/lib/shape/index.js +8 -6
  174. package/lib/shape/index.js.map +1 -1
  175. package/lib/shape/line3D/line.d.ts +3 -0
  176. package/lib/shape/line3D/line.js +34 -0
  177. package/lib/shape/line3D/line.js.map +1 -0
  178. package/lib/shape/point3D/cube.js +1 -1
  179. package/lib/shape/point3D/cube.js.map +1 -1
  180. package/lib/shape/point3D/sphere.js +1 -1
  181. package/lib/shape/point3D/sphere.js.map +1 -1
  182. package/lib/theme/classic.js +54 -37
  183. package/lib/theme/classic.js.map +1 -1
  184. package/lib/theme/index.d.ts +1 -0
  185. package/lib/theme/index.js +3 -1
  186. package/lib/theme/index.js.map +1 -1
  187. package/lib/theme/light.d.ts +6 -0
  188. package/lib/theme/light.js +480 -0
  189. package/lib/theme/light.js.map +1 -0
  190. package/lib/utils/selection.d.ts +1 -1
  191. package/lib/utils/selection.js +10 -10
  192. package/lib/utils/selection.js.map +1 -1
  193. package/lib/utils/size.js +1 -1
  194. package/package.json +4 -4
  195. package/src/api/chart.ts +3 -0
  196. package/src/api/extend.ts +6 -1
  197. package/src/api/index.ts +1 -1
  198. package/src/api/runtime.ts +6 -3
  199. package/src/component/axis.ts +17 -13
  200. package/src/component/legendCategory.ts +3 -5
  201. package/src/component/legendContinuous.ts +4 -5
  202. package/src/component/scrollbar.ts +4 -1
  203. package/src/component/slider.ts +4 -1
  204. package/src/component/title.ts +3 -3
  205. package/src/component/utils.ts +1 -3
  206. package/src/composition/facetRect.ts +4 -3
  207. package/src/composition/repeatMatrix.ts +4 -3
  208. package/src/index.ts +10 -1
  209. package/src/interaction/brushHighlight.ts +1 -1
  210. package/src/interaction/tooltip.ts +5 -3
  211. package/src/lib/builtinlib.ts +28 -0
  212. package/src/lib/core.ts +4 -25
  213. package/src/lib/graph.ts +7 -1
  214. package/src/lib/plot.ts +2 -7
  215. package/src/lib/threed.ts +2 -1
  216. package/src/mark/index.ts +1 -0
  217. package/src/mark/line3D.ts +81 -0
  218. package/src/runtime/component.ts +57 -30
  219. package/src/runtime/layout.ts +91 -31
  220. package/src/runtime/library.ts +4 -1
  221. package/src/runtime/plot.ts +62 -40
  222. package/src/runtime/render.ts +1 -6
  223. package/src/runtime/scale.ts +1 -0
  224. package/src/runtime/types/common.ts +2 -0
  225. package/src/runtime/types/theme.ts +8 -2
  226. package/src/shape/connector/connector.ts +41 -47
  227. package/src/shape/index.ts +1 -0
  228. package/src/shape/line3D/line.ts +29 -0
  229. package/src/shape/point3D/cube.ts +2 -2
  230. package/src/shape/point3D/sphere.ts +2 -2
  231. package/src/shape/utils.ts +2 -2
  232. package/src/theme/classic.ts +54 -37
  233. package/src/theme/index.ts +1 -0
  234. package/src/theme/light.ts +483 -0
  235. package/src/utils/selection.ts +11 -11
  236. package/src/utils/size.ts +1 -1
@@ -217,20 +217,20 @@ export async function plot<T extends G2ViewTree>(
217
217
  .attr('className', VIEW_CLASS_NAME)
218
218
  .attr('id', (view) => view.key)
219
219
  .call(applyTranslate)
220
- .each(function (view) {
221
- plotView(view, select(this), transitions, library, context);
222
- enterContainer.set(view, this);
220
+ .each(function (view, i, element) {
221
+ plotView(view, select(element), transitions, library, context);
222
+ enterContainer.set(view, element);
223
223
  }),
224
224
  (update) =>
225
- update.call(applyTranslate).each(function (view) {
226
- plotView(view, select(this), transitions, library, context);
227
- updateContainer.set(view, this);
225
+ update.call(applyTranslate).each(function (view, i, element) {
226
+ plotView(view, select(element), transitions, library, context);
227
+ updateContainer.set(view, element);
228
228
  }),
229
229
  (exit) =>
230
230
  exit
231
- .each(function () {
231
+ .each(function (d, i, element) {
232
232
  // Remove existed interactions.
233
- const interactions = this['nameInteraction'].values();
233
+ const interactions = element['nameInteraction'].values();
234
234
  for (const interaction of interactions) {
235
235
  interaction.destroy();
236
236
  }
@@ -775,8 +775,8 @@ async function plotView(
775
775
  .style('y', (i) => areaLayouts[i].y)
776
776
  .style('width', (i) => areaLayouts[i].width)
777
777
  .style('height', (i) => areaLayouts[i].height)
778
- .each(function (i) {
779
- applyStyle(select(this), areaStyles[i]);
778
+ .each(function (i, d, element) {
779
+ applyStyle(select(element), areaStyles[i]);
780
780
  });
781
781
  let px = 0;
782
782
  let py = 0;
@@ -847,7 +847,11 @@ async function plotView(
847
847
  ),
848
848
  ),
849
849
  (update) =>
850
- update.transition(function (options: G2GuideComponentOptions) {
850
+ update.transition(function (
851
+ options: G2GuideComponentOptions,
852
+ i,
853
+ element,
854
+ ) {
851
855
  const { preserve = false } = options;
852
856
  if (preserve) return;
853
857
  const newComponent = renderComponent(
@@ -858,7 +862,7 @@ async function plotView(
858
862
  markState,
859
863
  );
860
864
  const { attributes } = newComponent;
861
- const [node] = this.childNodes;
865
+ const [node] = element.childNodes;
862
866
  return node.update(attributes);
863
867
  }),
864
868
  )
@@ -933,8 +937,8 @@ async function plotView(
933
937
  // Using attribute as alternative for other classNames.
934
938
  .attr('className', ELEMENT_CLASS_NAME)
935
939
  .attr('markType', type)
936
- .transition(function (data) {
937
- return enterFunction(data, [this]);
940
+ .transition(function (data, i, element) {
941
+ return enterFunction(data, [element]);
938
942
  }),
939
943
  (update) =>
940
944
  update.call((selection) => {
@@ -944,14 +948,15 @@ async function plotView(
944
948
  return [x, y];
945
949
  });
946
950
  selection
947
- .transition(function (data, index) {
948
- maybeFacetElement(this, parent, origin);
951
+ .transition(function (data, index, element) {
952
+ maybeFacetElement(element, parent, origin);
949
953
  const node = shapeFunction(data, index);
950
- const animation = updateFunction(data, [this], [node]);
954
+ const animation = updateFunction(data, [element], [node]);
951
955
  if (animation !== null) return animation;
952
- if (this.nodeName === node.nodeName) copyAttributes(this, node);
956
+ if (element.nodeName === node.nodeName)
957
+ copyAttributes(element, node);
953
958
  else {
954
- this.parentNode.replaceChild(node, this);
959
+ element.parentNode.replaceChild(node, element);
955
960
  node.className = ELEMENT_CLASS_NAME;
956
961
  // @ts-ignore
957
962
  node.markType = type;
@@ -963,11 +968,11 @@ async function plotView(
963
968
  }),
964
969
  (exit) => {
965
970
  return exit
966
- .each(function () {
967
- this.__removed__ = true;
971
+ .each(function (d, i, element) {
972
+ element.__removed__ = true;
968
973
  })
969
- .transition(function (data) {
970
- return exitFunction(data, [this]);
974
+ .transition(function (data, i, element) {
975
+ return exitFunction(data, [element]);
971
976
  })
972
977
  .remove();
973
978
  },
@@ -977,25 +982,33 @@ async function plotView(
977
982
  .append(shapeFunction)
978
983
  .attr('className', ELEMENT_CLASS_NAME)
979
984
  .attr('markType', type)
980
- .transition(function (data) {
985
+ .transition(function (data, i, element) {
981
986
  // Remove merged elements after animation finishing.
982
- const { __fromElements__: fromElements } = this;
983
- const transition = updateFunction(data, fromElements, [this]);
984
- const exit = new Selection(fromElements, null, this.parentNode);
987
+ const { __fromElements__: fromElements } = element;
988
+ const transition = updateFunction(data, fromElements, [element]);
989
+ const exit = new Selection(
990
+ fromElements,
991
+ null,
992
+ element.parentNode,
993
+ );
985
994
  exit.transition(transition).remove();
986
995
  return transition;
987
996
  }),
988
997
  (split) =>
989
998
  split
990
- .transition(function (data) {
999
+ .transition(function (data, i, element) {
991
1000
  // Append splitted shapes.
992
- const enter = new Selection([], this.__toData__, this.parentNode);
1001
+ const enter = new Selection(
1002
+ [],
1003
+ element.__toData__,
1004
+ element.parentNode,
1005
+ );
993
1006
  const toElements = enter
994
1007
  .append(shapeFunction)
995
1008
  .attr('className', ELEMENT_CLASS_NAME)
996
1009
  .attr('markType', type)
997
1010
  .nodes();
998
- return updateFunction(data, [this], toElements);
1011
+ return updateFunction(data, [element], toElements);
999
1012
  })
1000
1013
  // Remove elements to be splitted after animation finishing.
1001
1014
  .remove(),
@@ -1071,11 +1084,11 @@ function plotLabel(
1071
1084
  .append((d) => labelShapeFunction.get(d)(d))
1072
1085
  .attr('className', LABEL_CLASS_NAME),
1073
1086
  (update) =>
1074
- update.each(function (d) {
1087
+ update.each(function (d, i, element) {
1075
1088
  // @todo Handle Label with different type.
1076
1089
  const shapeFunction = labelShapeFunction.get(d);
1077
1090
  const node = shapeFunction(d);
1078
- copyAttributes(this, node);
1091
+ copyAttributes(element, node);
1079
1092
  }),
1080
1093
  (exit) => exit.remove(),
1081
1094
  )
@@ -1525,7 +1538,7 @@ function createExitFunction(
1525
1538
 
1526
1539
  function inferTheme(theme: G2ThemeOptions = {}): G2ThemeOptions {
1527
1540
  if (typeof theme === 'string') return { type: theme };
1528
- const { type = 'classic', ...rest } = theme;
1541
+ const { type = 'light', ...rest } = theme;
1529
1542
  return { ...rest, type };
1530
1543
  }
1531
1544
 
@@ -1568,9 +1581,16 @@ function updateBBox(selection: Selection) {
1568
1581
 
1569
1582
  function animateBBox(selection: Selection, extent: [number, number]) {
1570
1583
  const [delay, duration] = extent;
1571
- selection.transition(function (data) {
1572
- const { x, y, width, height } = this.style;
1573
- const { paddingLeft, paddingTop, innerWidth, innerHeight } = data;
1584
+ selection.transition(function (data, i, element) {
1585
+ const { x, y, width, height } = element.style;
1586
+ const {
1587
+ paddingLeft,
1588
+ paddingTop,
1589
+ innerWidth,
1590
+ innerHeight,
1591
+ marginLeft,
1592
+ marginTop,
1593
+ } = data;
1574
1594
  const keyframes = [
1575
1595
  {
1576
1596
  x,
@@ -1579,13 +1599,13 @@ function animateBBox(selection: Selection, extent: [number, number]) {
1579
1599
  height,
1580
1600
  },
1581
1601
  {
1582
- x: paddingLeft,
1583
- y: paddingTop,
1602
+ x: paddingLeft + marginLeft,
1603
+ y: paddingTop + marginTop,
1584
1604
  width: innerWidth,
1585
1605
  height: innerHeight,
1586
1606
  },
1587
1607
  ];
1588
- return this.animate(keyframes, { delay, duration, fill: 'both' });
1608
+ return element.animate(keyframes, { delay, duration, fill: 'both' });
1589
1609
  });
1590
1610
  }
1591
1611
 
@@ -1645,10 +1665,12 @@ function applyClip(selection, clip?: boolean) {
1645
1665
  const {
1646
1666
  paddingTop: y,
1647
1667
  paddingLeft: x,
1668
+ marginLeft: x1,
1669
+ marginTop: y1,
1648
1670
  innerWidth: width,
1649
1671
  innerHeight: height,
1650
1672
  } = data;
1651
- return new Rect({ style: { x, y, width, height } });
1673
+ return new Rect({ style: { x: x + x1, y: y + y1, width, height } });
1652
1674
  });
1653
1675
  }
1654
1676
 
@@ -70,12 +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, depth = 0, theme } = options;
74
- if (!theme) {
75
- error(
76
- 'ChartOptions.theme is required, such as `const chart = new Chart({ theme: "classic"})`.',
77
- );
78
- }
73
+ const { width = 640, height = 480, depth = 0 } = options;
79
74
  const keyed = inferKeys(options);
80
75
  const {
81
76
  canvas = Canvas(width, height),
@@ -423,6 +423,7 @@ function categoricalColors(
423
423
  const { category10: c10, category20: c20 } = theme;
424
424
  const defaultPalette = unique(values.flat()).length <= c10.length ? c10 : c20;
425
425
  const { palette = defaultPalette, offset } = options;
426
+ if (Array.isArray(palette)) return palette;
426
427
  // Built-in palettes have higher priority.
427
428
  try {
428
429
  return usePalette({ type: palette });
@@ -195,6 +195,8 @@ export type SectionArea = [
195
195
  direction: Direction,
196
196
  reverse: boolean,
197
197
  comparator: (a: Primitive, b: Primitive) => number,
198
+ minX?: number,
199
+ totalWidth?: number,
198
200
  ];
199
201
 
200
202
  export type Section = Record<GuideComponentPosition, SectionArea>;
@@ -68,6 +68,8 @@ type InteractionTheme = {
68
68
 
69
69
  type ComponentTheme = {
70
70
  axis?: any;
71
+ axisX?: any;
72
+ axisY?: any;
71
73
  axisLinear?: any;
72
74
  axisTop?: any;
73
75
  axisBottom?: any;
@@ -75,6 +77,7 @@ type ComponentTheme = {
75
77
  axisRight?: any;
76
78
  axisRadar?: any;
77
79
  axisArc?: any;
80
+ legend?: any;
78
81
  legendCategory?: any;
79
82
  legendContinuous?: any;
80
83
  label?: LabelStyleProps;
@@ -112,9 +115,12 @@ type AreaTheme = {
112
115
  };
113
116
 
114
117
  export type G2Theme = {
118
+ padding?: 'auto' | number;
119
+ inset?: 'auto' | number;
120
+ margin?: number;
115
121
  color?: string;
116
- category10?: string;
117
- category20?: string;
122
+ category10?: string | string[];
123
+ category20?: string | string[];
118
124
  size?: number;
119
125
  view?: WithPrefix<AreaTheme, 'view'> &
120
126
  WithPrefix<AreaTheme, 'plot'> &
@@ -1,10 +1,9 @@
1
1
  import { Coordinate } from '@antv/coord';
2
2
  import type { PathArray } from '@antv/util';
3
- import { PathStyleProps } from '@antv/g';
3
+ import { PathStyleProps, Path } from '@antv/g';
4
4
  import { Marker } from '@antv/gui';
5
5
  import { line as d3line } from 'd3-shape';
6
6
  import { ShapeComponent as SC, Vector2, WithPrefix } from '../../runtime';
7
- import { createElement } from '../../utils/createElement';
8
7
  import { isTranspose } from '../../utils/coordinate';
9
8
  import { subObject } from '../../utils/helper';
10
9
  import { select } from '../../utils/selection';
@@ -33,51 +32,19 @@ function inferConnectorPath(points: Vector2[]) {
33
32
  .y((d) => d[1])(points);
34
33
  }
35
34
 
36
- const ConnectorPath = createElement((g) => {
37
- // Do not copy className to path.
38
- const {
39
- points,
40
- class: className,
41
- endMarker = true,
42
- direction,
43
- ...rest
44
- } = g.attributes;
45
-
46
- const markerStyle = subObject(rest, 'endMarker');
47
- const path = inferConnectorPath(points);
48
-
49
- select(g)
50
- .maybeAppend('connector', 'path')
51
- .style('path', path)
52
- .style(
53
- 'markerEnd',
54
- endMarker
55
- ? new Marker({
56
- className: 'marker',
57
- style: {
58
- ...markerStyle,
59
- symbol: inferSymbol,
60
- },
61
- })
62
- : null,
63
- )
64
- .call(applyStyle, rest);
65
- });
66
-
67
35
  function getPoints(
68
36
  coordinate: Coordinate,
69
37
  points: Vector2[],
70
- offset: number,
38
+ offset1: number,
39
+ offset2: number,
71
40
  length1 = 0,
72
41
  ): Vector2[] {
73
42
  const [[x0, y0], [x1, y1]] = points;
74
43
 
75
44
  if (isTranspose(coordinate)) {
76
- const OFFSET = offset;
77
- const X0 = x0 + OFFSET;
78
- const X1 = x1 + OFFSET;
45
+ const X0 = x0 + offset1;
46
+ const X1 = x1 + offset2;
79
47
  const X = X0 + length1;
80
-
81
48
  return [
82
49
  [X0, y0],
83
50
  [X, y0],
@@ -86,10 +53,9 @@ function getPoints(
86
53
  ];
87
54
  }
88
55
 
89
- const OFFSET = -offset;
90
- const Y0 = y0 + OFFSET;
91
- const Y1 = y1 + OFFSET;
92
- const Y = Y0 + -length1;
56
+ const Y0 = y0 - offset1;
57
+ const Y1 = y1 - offset2;
58
+ const Y = Y0 - length1;
93
59
  return [
94
60
  [x0, Y0],
95
61
  [x0, Y],
@@ -99,17 +65,45 @@ function getPoints(
99
65
  }
100
66
 
101
67
  export const Connector: SC<ConnectorOptions> = (options, context) => {
102
- const { offset = 0, connectLength1: length1, ...style } = options;
68
+ const {
69
+ offset = 0,
70
+ offset1 = offset,
71
+ offset2 = offset,
72
+ connectLength1: length1,
73
+ endMarker = true,
74
+ ...style
75
+ } = options;
103
76
  const { coordinate } = context;
77
+
104
78
  return (points, value, defaults) => {
105
- const { color: defaultColor, connectLength1 = length1, ...rest } = defaults;
79
+ const { color: defaultColor, connectLength1, ...rest } = defaults;
106
80
  const { color, transform } = value;
107
- const P = getPoints(coordinate, points, offset, connectLength1);
108
- return select(new ConnectorPath())
81
+ const P = getPoints(
82
+ coordinate,
83
+ points,
84
+ offset1,
85
+ offset2,
86
+ length1 || connectLength1,
87
+ );
88
+ const makerStyle = subObject({ ...style, ...defaults }, 'endMarker');
89
+
90
+ return select(new Path())
109
91
  .call(applyStyle, rest)
110
- .style('points', P)
92
+ .style('path', inferConnectorPath(P))
111
93
  .style('stroke', color || defaultColor)
112
94
  .style('transform', transform)
95
+ .style(
96
+ 'markerEnd',
97
+ endMarker
98
+ ? new Marker({
99
+ className: 'marker',
100
+ style: {
101
+ ...makerStyle,
102
+ symbol: inferSymbol,
103
+ },
104
+ })
105
+ : null,
106
+ )
113
107
  .call(applyStyle, style)
114
108
  .node();
115
109
  };
@@ -10,6 +10,7 @@ export { HV as LineHV } from './line/hv';
10
10
  export { VH as LineVH } from './line/vh';
11
11
  export { HVH as LineHVH } from './line/hvh';
12
12
  export { Trail as LineTrail } from './line/trail';
13
+ export { Line as Line3DShape } from './line3D/line';
13
14
  export { HollowBowtie as PointHollowBowtie } from './point/hollowBowtie';
14
15
  export { HollowDiamond as PointHollowDiamond } from './point/hollowDiamond';
15
16
  export { HollowHexagon as PointHollowHexagon } from './point/hollowHexagon';
@@ -0,0 +1,29 @@
1
+ import { Polyline } from '@antv/g';
2
+ import { applyStyle } from '../utils';
3
+ import { ShapeComponent as SC } from '../../runtime';
4
+ import { select } from '../../utils/selection';
5
+
6
+ export type LineOptions = Record<string, any>;
7
+
8
+ export const Line: SC<LineOptions> = (options, context) => {
9
+ return (P, value, defaults) => {
10
+ const { color: defaultColor, lineWidth: defaultSize, ...rest } = defaults;
11
+ const { color = defaultColor, size = defaultSize } = value;
12
+ const stroke = color;
13
+ const finalStyle = {
14
+ isBillboard: true,
15
+ ...rest,
16
+ ...(stroke && { stroke }),
17
+ ...(size && { lineWidth: size }),
18
+ };
19
+
20
+ return select(new Polyline())
21
+ .style('points', P)
22
+ .call(applyStyle, finalStyle)
23
+ .node();
24
+ };
25
+ };
26
+
27
+ Line.props = {
28
+ defaultMarker: 'line',
29
+ };
@@ -1,4 +1,4 @@
1
- import { MeshPhongMaterial, CubeGeometry, Mesh } from '@antv/g-plugin-3d';
1
+ import { MeshLambertMaterial, CubeGeometry, Mesh } from '@antv/g-plugin-3d';
2
2
  import { applyStyle, getOrigin, toOpacityKey } from '../utils';
3
3
  import { ShapeComponent as SC } from '../../runtime';
4
4
  import { select } from '../../utils/selection';
@@ -28,7 +28,7 @@ export const Cube: SC<CubeOptions> = (options, context) => {
28
28
  });
29
29
  // create a material with Phong lighting model
30
30
  // @ts-ignore
31
- context.cubeMaterial = new MeshPhongMaterial(device);
31
+ context.cubeMaterial = new MeshLambertMaterial(device);
32
32
  }
33
33
 
34
34
  return (points, value, defaults) => {
@@ -1,4 +1,4 @@
1
- import { MeshPhongMaterial, SphereGeometry, Mesh } from '@antv/g-plugin-3d';
1
+ import { MeshLambertMaterial, SphereGeometry, Mesh } from '@antv/g-plugin-3d';
2
2
  import { applyStyle, getOrigin, toOpacityKey } from '../utils';
3
3
  import { ShapeComponent as SC } from '../../runtime';
4
4
  import { select } from '../../utils/selection';
@@ -28,7 +28,7 @@ export const Sphere: SC<SphereOptions> = (options, context) => {
28
28
  });
29
29
  // create a material with Phong lighting model
30
30
  // @ts-ignore
31
- context.sphereMaterial = new MeshPhongMaterial(device);
31
+ context.sphereMaterial = new MeshLambertMaterial(device);
32
32
  }
33
33
 
34
34
  return (points, value, defaults) => {
@@ -3,10 +3,10 @@ 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, Vector3 } from '../runtime';
6
+ import { Primitive, Vector2, Vector3 } from '../runtime';
7
7
  import { indexOf } from '../utils/array';
8
8
  import { isPolar, isTranspose } from '../utils/coordinate';
9
- import { Selection } from '../utils/selection';
9
+ import { G2Element, Selection } from '../utils/selection';
10
10
  import { angle, angleWithQuadrant, dist, sub } from '../utils/vector';
11
11
 
12
12
  export function applyStyle(