@antv/g2 5.3.3-beta.0 → 5.3.4-alpha.0

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 (161) hide show
  1. package/README.md +9 -0
  2. package/README.zh-CN.md +8 -0
  3. package/dist/g2.lite.min.js +30 -22
  4. package/dist/g2.min.js +30 -22
  5. package/esm/api/runtime.d.ts +12 -1
  6. package/esm/api/runtime.js +89 -6
  7. package/esm/api/runtime.js.map +1 -1
  8. package/esm/data/fetch.d.ts +2 -2
  9. package/esm/data/fetch.js +2 -2
  10. package/esm/data/fetch.js.map +1 -1
  11. package/esm/data/utils/venn/fmin/bisect.d.ts +3 -0
  12. package/esm/data/utils/venn/fmin/bisect.js +30 -0
  13. package/esm/data/utils/venn/fmin/bisect.js.map +1 -0
  14. package/esm/data/utils/venn/fmin/blas1.d.ts +7 -0
  15. package/esm/data/utils/venn/fmin/blas1.js +38 -0
  16. package/esm/data/utils/venn/fmin/blas1.js.map +1 -0
  17. package/esm/data/utils/venn/fmin/conjugateGradient.d.ts +6 -0
  18. package/esm/data/utils/venn/fmin/conjugateGradient.js +91 -0
  19. package/esm/data/utils/venn/fmin/conjugateGradient.js.map +1 -0
  20. package/esm/data/utils/venn/fmin/gradientDescent.d.ts +10 -0
  21. package/esm/data/utils/venn/fmin/gradientDescent.js +66 -0
  22. package/esm/data/utils/venn/fmin/gradientDescent.js.map +1 -0
  23. package/esm/data/utils/venn/fmin/index.d.ts +34 -0
  24. package/esm/data/utils/venn/fmin/index.js +35 -0
  25. package/esm/data/utils/venn/fmin/index.js.map +1 -0
  26. package/esm/data/utils/venn/fmin/linesearch.d.ts +1 -0
  27. package/esm/data/utils/venn/fmin/linesearch.js +60 -0
  28. package/esm/data/utils/venn/fmin/linesearch.js.map +1 -0
  29. package/esm/data/utils/venn/fmin/nelderMead.d.ts +5 -0
  30. package/esm/data/utils/venn/fmin/nelderMead.js +133 -0
  31. package/esm/data/utils/venn/fmin/nelderMead.js.map +1 -0
  32. package/esm/data/utils/venn/layout.d.ts +2 -2
  33. package/esm/data/utils/venn/layout.js +1 -1
  34. package/esm/data/utils/venn/layout.js.map +1 -1
  35. package/esm/index.d.ts +2 -2
  36. package/esm/index.js +2 -2
  37. package/esm/index.js.map +1 -1
  38. package/esm/interaction/elementSelect.js +32 -2
  39. package/esm/interaction/elementSelect.js.map +1 -1
  40. package/esm/interaction/tooltip.d.ts +57 -0
  41. package/esm/interaction/tooltip.js +147 -85
  42. package/esm/interaction/tooltip.js.map +1 -1
  43. package/esm/interaction/utils.d.ts +2 -2
  44. package/esm/interaction/utils.js +10 -2
  45. package/esm/interaction/utils.js.map +1 -1
  46. package/esm/mark/line.js +4 -1
  47. package/esm/mark/line.js.map +1 -1
  48. package/esm/runtime/component.js +5 -2
  49. package/esm/runtime/component.js.map +1 -1
  50. package/esm/runtime/plot.js +8 -3
  51. package/esm/runtime/plot.js.map +1 -1
  52. package/esm/runtime/render.d.ts +1 -1
  53. package/esm/runtime/render.js +4 -2
  54. package/esm/runtime/render.js.map +1 -1
  55. package/esm/runtime/types/common.d.ts +1 -0
  56. package/esm/shape/connector/connector.js +19 -15
  57. package/esm/shape/connector/connector.js.map +1 -1
  58. package/esm/spec/transform.d.ts +1 -0
  59. package/esm/theme/create.d.ts +0 -1
  60. package/esm/theme/create.js +0 -1
  61. package/esm/theme/create.js.map +1 -1
  62. package/esm/transform/group.d.ts +0 -1
  63. package/esm/transform/group.js.map +1 -1
  64. package/esm/transform/groupN.d.ts +1 -1
  65. package/esm/utils/style.js +11 -2
  66. package/esm/utils/style.js.map +1 -1
  67. package/esm/utils/traverse-elements.d.ts +2 -0
  68. package/esm/utils/traverse-elements.js +13 -0
  69. package/esm/utils/traverse-elements.js.map +1 -0
  70. package/lib/api/runtime.d.ts +12 -1
  71. package/lib/api/runtime.js +96 -13
  72. package/lib/api/runtime.js.map +1 -1
  73. package/lib/data/fetch.d.ts +2 -2
  74. package/lib/data/fetch.js +1 -1
  75. package/lib/data/fetch.js.map +1 -1
  76. package/lib/data/utils/venn/fmin/bisect.d.ts +3 -0
  77. package/lib/data/utils/venn/fmin/bisect.js +34 -0
  78. package/lib/data/utils/venn/fmin/bisect.js.map +1 -0
  79. package/lib/data/utils/venn/fmin/blas1.d.ts +7 -0
  80. package/lib/data/utils/venn/fmin/blas1.js +48 -0
  81. package/lib/data/utils/venn/fmin/blas1.js.map +1 -0
  82. package/lib/data/utils/venn/fmin/conjugateGradient.d.ts +6 -0
  83. package/lib/data/utils/venn/fmin/conjugateGradient.js +96 -0
  84. package/lib/data/utils/venn/fmin/conjugateGradient.js.map +1 -0
  85. package/lib/data/utils/venn/fmin/gradientDescent.d.ts +10 -0
  86. package/lib/data/utils/venn/fmin/gradientDescent.js +71 -0
  87. package/lib/data/utils/venn/fmin/gradientDescent.js.map +1 -0
  88. package/lib/data/utils/venn/fmin/index.d.ts +34 -0
  89. package/lib/data/utils/venn/fmin/index.js +49 -0
  90. package/lib/data/utils/venn/fmin/index.js.map +1 -0
  91. package/lib/data/utils/venn/fmin/linesearch.d.ts +1 -0
  92. package/lib/data/utils/venn/fmin/linesearch.js +64 -0
  93. package/lib/data/utils/venn/fmin/linesearch.js.map +1 -0
  94. package/lib/data/utils/venn/fmin/nelderMead.d.ts +5 -0
  95. package/lib/data/utils/venn/fmin/nelderMead.js +137 -0
  96. package/lib/data/utils/venn/fmin/nelderMead.js.map +1 -0
  97. package/lib/data/utils/venn/layout.d.ts +2 -2
  98. package/lib/data/utils/venn/layout.js +1 -1
  99. package/lib/data/utils/venn/layout.js.map +1 -1
  100. package/lib/index.d.ts +2 -2
  101. package/lib/index.js +2 -1
  102. package/lib/index.js.map +1 -1
  103. package/lib/interaction/elementSelect.js +32 -2
  104. package/lib/interaction/elementSelect.js.map +1 -1
  105. package/lib/interaction/tooltip.d.ts +57 -0
  106. package/lib/interaction/tooltip.js +150 -85
  107. package/lib/interaction/tooltip.js.map +1 -1
  108. package/lib/interaction/utils.d.ts +2 -2
  109. package/lib/interaction/utils.js +10 -2
  110. package/lib/interaction/utils.js.map +1 -1
  111. package/lib/mark/line.js +3 -0
  112. package/lib/mark/line.js.map +1 -1
  113. package/lib/runtime/component.js +5 -2
  114. package/lib/runtime/component.js.map +1 -1
  115. package/lib/runtime/plot.js +8 -3
  116. package/lib/runtime/plot.js.map +1 -1
  117. package/lib/runtime/render.d.ts +1 -1
  118. package/lib/runtime/render.js +4 -2
  119. package/lib/runtime/render.js.map +1 -1
  120. package/lib/runtime/types/common.d.ts +1 -0
  121. package/lib/shape/connector/connector.js +19 -15
  122. package/lib/shape/connector/connector.js.map +1 -1
  123. package/lib/spec/transform.d.ts +1 -0
  124. package/lib/theme/create.d.ts +0 -1
  125. package/lib/theme/create.js +0 -1
  126. package/lib/theme/create.js.map +1 -1
  127. package/lib/transform/group.d.ts +0 -1
  128. package/lib/transform/group.js.map +1 -1
  129. package/lib/transform/groupN.d.ts +1 -1
  130. package/lib/utils/style.js +11 -2
  131. package/lib/utils/style.js.map +1 -1
  132. package/lib/utils/traverse-elements.d.ts +2 -0
  133. package/lib/utils/traverse-elements.js +17 -0
  134. package/lib/utils/traverse-elements.js.map +1 -0
  135. package/package.json +21 -21
  136. package/src/api/runtime.ts +136 -6
  137. package/src/data/fetch.ts +5 -4
  138. package/src/data/utils/venn/fmin/bisect.ts +32 -0
  139. package/src/data/utils/venn/fmin/blas1.ts +42 -0
  140. package/src/data/utils/venn/fmin/conjugateGradient.ts +106 -0
  141. package/src/data/utils/venn/fmin/gradientDescent.ts +75 -0
  142. package/src/data/utils/venn/fmin/index.ts +35 -0
  143. package/src/data/utils/venn/fmin/linesearch.ts +70 -0
  144. package/src/data/utils/venn/fmin/nelderMead.ts +147 -0
  145. package/src/data/utils/venn/layout.ts +1 -1
  146. package/src/index.ts +2 -2
  147. package/src/interaction/elementSelect.ts +32 -3
  148. package/src/interaction/tooltip.ts +216 -135
  149. package/src/interaction/utils.ts +12 -5
  150. package/src/mark/line.ts +3 -1
  151. package/src/runtime/component.ts +5 -3
  152. package/src/runtime/plot.ts +7 -1
  153. package/src/runtime/render.ts +5 -1
  154. package/src/runtime/types/common.ts +1 -0
  155. package/src/shape/connector/connector.ts +30 -19
  156. package/src/spec/transform.ts +1 -0
  157. package/src/theme/create.ts +0 -1
  158. package/src/transform/group.ts +0 -1
  159. package/src/transform/groupN.ts +1 -1
  160. package/src/utils/style.ts +11 -1
  161. package/src/utils/traverse-elements.ts +16 -0
@@ -439,12 +439,14 @@ function inferAxisPositionAndOrientation(
439
439
  scale.name.startsWith('position'),
440
440
  );
441
441
  const index = matchPosition(name);
442
- if (name === positions.slice(-1)[0].name || index === null)
443
- return [null, null];
442
+ if (index === null) return [null, null];
444
443
  // infer radar axis orientation
445
444
  const [startAngle, endAngle] = angleOf(coordinates);
445
+ const positionLength = isRadar(coordinates)
446
+ ? positions.length
447
+ : positions.length - 1;
446
448
  const angle =
447
- ((endAngle - startAngle) / (positions.length - 1)) * index + startAngle;
449
+ ((endAngle - startAngle) / positionLength) * index + startAngle;
448
450
  return ['center', angle];
449
451
  }
450
452
 
@@ -789,6 +789,7 @@ function initializeState(
789
789
  // the same style with JS standard and lodash APIs.
790
790
  // @todo More proper way to index scale for different marks.
791
791
  const children = [];
792
+ const dataMap = new Map();
792
793
  for (const [mark, state] of markState.entries()) {
793
794
  const {
794
795
  // scale,
@@ -799,7 +800,9 @@ function initializeState(
799
800
  dataDomain,
800
801
  modifier,
801
802
  key: markKey,
803
+ data,
802
804
  } = mark;
805
+ dataMap.set(markKey, data);
803
806
  const { index, channels, tooltip } = state;
804
807
  const scale = Object.fromEntries(
805
808
  channels.map(({ name, scale }) => [name, scale]),
@@ -828,6 +831,7 @@ function initializeState(
828
831
  index: d,
829
832
  markKey,
830
833
  viewKey: key,
834
+ data: data[d],
831
835
  ...(tooltip && {
832
836
  title: titleOf(d),
833
837
  items: itemsOf(d),
@@ -867,6 +871,7 @@ function initializeState(
867
871
  scale: scaleInstance,
868
872
  style: framedStyle,
869
873
  components,
874
+ data: dataMap,
870
875
  labelTransform: compose(labelTransform.map(useLabelTransform)),
871
876
  };
872
877
 
@@ -1318,7 +1323,7 @@ function normalizeLabelSelector(
1318
1323
  * transitions together.
1319
1324
  */
1320
1325
  function getLocalBounds(element: DisplayObject) {
1321
- const cloneElement = element.cloneNode();
1326
+ const cloneElement = element.cloneNode(true);
1322
1327
  const animations = element.getAnimations();
1323
1328
  cloneElement.style.visibility = 'hidden';
1324
1329
  animations.forEach((animation) => {
@@ -1472,6 +1477,7 @@ function selectFacetElements(
1472
1477
  elementClassName: string,
1473
1478
  ): DisplayObject[] {
1474
1479
  const group = selection.node().parentElement;
1480
+ if (!group || typeof group.findAll !== 'function') return [];
1475
1481
  return group
1476
1482
  .findAll(
1477
1483
  (node) =>
@@ -171,13 +171,17 @@ export function destroy<T extends G2ViewTree = G2ViewTree>(
171
171
  options: T,
172
172
  context: G2Context = {},
173
173
  isDestroyCanvas = false,
174
+ isClearEvents = true,
174
175
  ) {
175
176
  const { canvas, emitter } = context;
176
177
  if (canvas) {
177
178
  destroyAllInteractions(canvas);
178
179
  isDestroyCanvas ? canvas.destroy() : canvas.destroyChildren();
179
180
  }
180
- emitter.off();
181
+
182
+ if (isClearEvents) {
183
+ emitter.off();
184
+ }
181
185
  }
182
186
 
183
187
  /**
@@ -47,6 +47,7 @@ export type G2ViewDescriptor = {
47
47
  labelTransform: LabelTransform;
48
48
  // @todo More accurate type.
49
49
  style: Record<string, any>;
50
+ data?: Map<string, any>;
50
51
  };
51
52
 
52
53
  export type G2ViewInstance = {
@@ -35,40 +35,49 @@ function inferConnectorPath(points: Vector2[]) {
35
35
  function getPoints(
36
36
  coordinate: Coordinate,
37
37
  points: Vector2[],
38
- offset1: number,
39
- offset2: number,
38
+ sourceOffsetY: number,
39
+ targetOffsetY: number,
40
+ sourceOffsetX: number,
41
+ targetOffsetX: number,
40
42
  length1 = 0,
41
43
  ): Vector2[] {
42
44
  const [[x0, y0], [x1, y1]] = points;
43
45
 
44
46
  if (isTranspose(coordinate)) {
45
- const X0 = x0 + offset1;
46
- const X1 = x1 + offset2;
47
+ const X0 = x0 + sourceOffsetY;
48
+ const X1 = x1 + targetOffsetY;
47
49
  const X = X0 + length1;
50
+ const Y0 = y0 + sourceOffsetX;
51
+ const Y1 = y1 + targetOffsetX;
48
52
  return [
49
- [X0, y0],
50
- [X, y0],
51
- [X, y1],
52
- [X1, y1],
53
+ [X0, Y0],
54
+ [X, Y0],
55
+ [X, Y1],
56
+ [X1, Y1],
53
57
  ];
54
58
  }
55
59
 
56
- const Y0 = y0 - offset1;
57
- const Y1 = y1 - offset2;
60
+ const Y0 = y0 - sourceOffsetY;
61
+ const Y1 = y1 - targetOffsetY;
58
62
  const Y = Y0 - length1;
63
+ const X0 = x0 - sourceOffsetX;
64
+ const X1 = x1 - targetOffsetX;
59
65
  return [
60
- [x0, Y0],
61
- [x0, Y],
62
- [x1, Y],
63
- [x1, Y1],
66
+ [X0, Y0],
67
+ [X0, Y],
68
+ [X1, Y],
69
+ [X1, Y1],
64
70
  ];
65
71
  }
66
72
 
67
73
  export const Connector: SC<ConnectorOptions> = (options, context) => {
68
74
  const {
69
- offset = 0,
70
- offset1 = offset,
71
- offset2 = offset,
75
+ offsetX = 0,
76
+ sourceOffsetX = offsetX,
77
+ targetOffsetX = offsetX,
78
+ offsetY = 0,
79
+ sourceOffsetY = offsetY,
80
+ targetOffsetY = offsetY,
72
81
  connectLength1: length1,
73
82
  endMarker = true,
74
83
  ...style
@@ -81,8 +90,10 @@ export const Connector: SC<ConnectorOptions> = (options, context) => {
81
90
  const P = getPoints(
82
91
  coordinate,
83
92
  points,
84
- offset1,
85
- offset2,
93
+ sourceOffsetY,
94
+ targetOffsetY,
95
+ sourceOffsetX,
96
+ targetOffsetX,
86
97
  length1 ?? connectLength1,
87
98
  );
88
99
  const makerStyle = subObject({ ...style, ...defaults }, 'endMarker');
@@ -251,6 +251,7 @@ export type GroupColorTransform = {
251
251
 
252
252
  export type GroupTransform = {
253
253
  type?: 'group';
254
+ channels?: string | string[];
254
255
  } & { [key in ChannelTypes]?: Reducer };
255
256
 
256
257
  export type BinXTransform = {
@@ -293,7 +293,6 @@ export function create({
293
293
  girdClosed: true,
294
294
  gridStrokeOpacity: 0.3,
295
295
  gridType: 'surround',
296
- label: false,
297
296
  tick: false,
298
297
  titlePosition: 'start',
299
298
  },
@@ -5,7 +5,6 @@ import { GroupN } from './groupN';
5
5
 
6
6
  export type GroupOptions = Omit<
7
7
  GroupTransform & {
8
- channels?: string | string[];
9
8
  groupBy?: (
10
9
  I: number[],
11
10
  mark: G2Mark,
@@ -19,7 +19,7 @@ export type GroupNOptions = Omit<
19
19
  options?: Record<string, any>,
20
20
  ) => number[][];
21
21
  },
22
- 'type'
22
+ 'type' | 'channels'
23
23
  >;
24
24
 
25
25
  type ReducerFunction = (I: number[], V: Primitive[]) => Primitive;
@@ -1,4 +1,5 @@
1
1
  import type { DisplayObject, BaseStyleProps } from '@antv/g';
2
+ import { traverseElements } from './traverse-elements';
2
3
 
3
4
  const defaultStyle: BaseStyleProps = {
4
5
  visibility: 'visible',
@@ -8,7 +9,16 @@ const defaultStyle: BaseStyleProps = {
8
9
  };
9
10
 
10
11
  export function getStyle(element: DisplayObject, key: string) {
11
- return element.style[key] ?? defaultStyle[key];
12
+ let value: any;
13
+ traverseElements(element, (el) => {
14
+ if (el.tagName !== 'g' && el.style?.[key] !== undefined) {
15
+ value = el.style[key];
16
+ return true;
17
+ }
18
+ return false;
19
+ });
20
+
21
+ return value ?? defaultStyle[key];
12
22
  }
13
23
 
14
24
  export function setStyle(
@@ -0,0 +1,16 @@
1
+ import { DisplayObject } from '@antv/g';
2
+
3
+ export function traverseElements(
4
+ element: DisplayObject,
5
+ visitor: (el: DisplayObject) => boolean | void,
6
+ ): boolean {
7
+ if (visitor(element)) return true;
8
+ if (element.tagName === 'g') {
9
+ const { childNodes = [] } = element;
10
+ for (const child of childNodes) {
11
+ if (traverseElements(child as DisplayObject, visitor)) return true;
12
+ }
13
+ }
14
+
15
+ return false;
16
+ }