@antv/g2 5.1.9 → 5.1.11

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 (163) hide show
  1. package/dist/g2.lite.min.js +1 -1
  2. package/dist/g2.min.js +1 -1
  3. package/esm/animation/scaleInY.js +103 -33
  4. package/esm/animation/scaleInY.js.map +1 -1
  5. package/esm/component/slider.js +32 -2
  6. package/esm/component/slider.js.map +1 -1
  7. package/esm/composition/facetCircle.js +1 -1
  8. package/esm/index.d.ts +2 -0
  9. package/esm/interaction/chartIndex.d.ts +5 -0
  10. package/esm/interaction/chartIndex.js +4 -1
  11. package/esm/interaction/chartIndex.js.map +1 -1
  12. package/esm/interaction/elementHighlight.d.ts +5 -0
  13. package/esm/interaction/elementHighlight.js +3 -0
  14. package/esm/interaction/elementHighlight.js.map +1 -1
  15. package/esm/interaction/elementHighlightByColor.d.ts +5 -0
  16. package/esm/interaction/elementHighlightByColor.js +3 -0
  17. package/esm/interaction/elementHighlightByColor.js.map +1 -1
  18. package/esm/interaction/elementHighlightByX.d.ts +5 -0
  19. package/esm/interaction/elementHighlightByX.js +3 -0
  20. package/esm/interaction/elementHighlightByX.js.map +1 -1
  21. package/esm/interaction/elementSelect.d.ts +5 -0
  22. package/esm/interaction/elementSelect.js +3 -0
  23. package/esm/interaction/elementSelect.js.map +1 -1
  24. package/esm/interaction/elementSelectByColor.d.ts +5 -0
  25. package/esm/interaction/elementSelectByColor.js +3 -0
  26. package/esm/interaction/elementSelectByColor.js.map +1 -1
  27. package/esm/interaction/elementSelectByX.d.ts +5 -0
  28. package/esm/interaction/elementSelectByX.js +3 -0
  29. package/esm/interaction/elementSelectByX.js.map +1 -1
  30. package/esm/interaction/event.d.ts +5 -0
  31. package/esm/interaction/event.js +3 -0
  32. package/esm/interaction/event.js.map +1 -1
  33. package/esm/interaction/poptip.d.ts +5 -0
  34. package/esm/interaction/poptip.js +3 -0
  35. package/esm/interaction/poptip.js.map +1 -1
  36. package/esm/interaction/sliderFilter.js +2 -0
  37. package/esm/interaction/sliderFilter.js.map +1 -1
  38. package/esm/interaction/tooltip.d.ts +5 -0
  39. package/esm/interaction/tooltip.js +16 -9
  40. package/esm/interaction/tooltip.js.map +1 -1
  41. package/esm/lib/core.d.ts +1 -0
  42. package/esm/lib/core.js +2 -1
  43. package/esm/lib/core.js.map +1 -1
  44. package/esm/lib/std.d.ts +1 -0
  45. package/esm/mark/chord.js +2 -0
  46. package/esm/mark/chord.js.map +1 -1
  47. package/esm/runtime/library.js +7 -4
  48. package/esm/runtime/library.js.map +1 -1
  49. package/esm/runtime/plot.js +41 -19
  50. package/esm/runtime/plot.js.map +1 -1
  51. package/esm/runtime/render.js +5 -2
  52. package/esm/runtime/render.js.map +1 -1
  53. package/esm/runtime/types/common.d.ts +1 -1
  54. package/esm/shape/area/smooth.d.ts +1 -3
  55. package/esm/shape/area/smooth.js +9 -5
  56. package/esm/shape/area/smooth.js.map +1 -1
  57. package/esm/shape/line/smooth.d.ts +1 -3
  58. package/esm/shape/line/smooth.js +2 -2
  59. package/esm/shape/line/smooth.js.map +1 -1
  60. package/esm/spec/composition.d.ts +1 -1
  61. package/esm/spec/mark.d.ts +1 -1
  62. package/esm/spec/transform.d.ts +7 -2
  63. package/esm/transform/index.d.ts +2 -0
  64. package/esm/transform/index.js +1 -0
  65. package/esm/transform/index.js.map +1 -1
  66. package/esm/transform/jitterY.d.ts +8 -0
  67. package/esm/transform/jitterY.js +25 -0
  68. package/esm/transform/jitterY.js.map +1 -0
  69. package/lib/animation/scaleInY.js +102 -32
  70. package/lib/animation/scaleInY.js.map +1 -1
  71. package/lib/component/slider.js +32 -2
  72. package/lib/component/slider.js.map +1 -1
  73. package/lib/composition/facetCircle.js +1 -1
  74. package/lib/index.d.ts +2 -0
  75. package/lib/interaction/chartIndex.d.ts +5 -0
  76. package/lib/interaction/chartIndex.js +4 -1
  77. package/lib/interaction/chartIndex.js.map +1 -1
  78. package/lib/interaction/elementHighlight.d.ts +5 -0
  79. package/lib/interaction/elementHighlight.js +3 -0
  80. package/lib/interaction/elementHighlight.js.map +1 -1
  81. package/lib/interaction/elementHighlightByColor.d.ts +5 -0
  82. package/lib/interaction/elementHighlightByColor.js +3 -0
  83. package/lib/interaction/elementHighlightByColor.js.map +1 -1
  84. package/lib/interaction/elementHighlightByX.d.ts +5 -0
  85. package/lib/interaction/elementHighlightByX.js +3 -0
  86. package/lib/interaction/elementHighlightByX.js.map +1 -1
  87. package/lib/interaction/elementSelect.d.ts +5 -0
  88. package/lib/interaction/elementSelect.js +3 -0
  89. package/lib/interaction/elementSelect.js.map +1 -1
  90. package/lib/interaction/elementSelectByColor.d.ts +5 -0
  91. package/lib/interaction/elementSelectByColor.js +3 -0
  92. package/lib/interaction/elementSelectByColor.js.map +1 -1
  93. package/lib/interaction/elementSelectByX.d.ts +5 -0
  94. package/lib/interaction/elementSelectByX.js +3 -0
  95. package/lib/interaction/elementSelectByX.js.map +1 -1
  96. package/lib/interaction/event.d.ts +5 -0
  97. package/lib/interaction/event.js +3 -0
  98. package/lib/interaction/event.js.map +1 -1
  99. package/lib/interaction/poptip.d.ts +5 -0
  100. package/lib/interaction/poptip.js +3 -0
  101. package/lib/interaction/poptip.js.map +1 -1
  102. package/lib/interaction/sliderFilter.js +2 -0
  103. package/lib/interaction/sliderFilter.js.map +1 -1
  104. package/lib/interaction/tooltip.d.ts +5 -0
  105. package/lib/interaction/tooltip.js +16 -9
  106. package/lib/interaction/tooltip.js.map +1 -1
  107. package/lib/lib/core.d.ts +1 -0
  108. package/lib/lib/core.js +1 -0
  109. package/lib/lib/core.js.map +1 -1
  110. package/lib/lib/std.d.ts +1 -0
  111. package/lib/mark/chord.js +2 -0
  112. package/lib/mark/chord.js.map +1 -1
  113. package/lib/runtime/library.js +7 -4
  114. package/lib/runtime/library.js.map +1 -1
  115. package/lib/runtime/plot.js +41 -19
  116. package/lib/runtime/plot.js.map +1 -1
  117. package/lib/runtime/render.js +5 -2
  118. package/lib/runtime/render.js.map +1 -1
  119. package/lib/runtime/types/common.d.ts +1 -1
  120. package/lib/shape/area/smooth.d.ts +1 -3
  121. package/lib/shape/area/smooth.js +7 -3
  122. package/lib/shape/area/smooth.js.map +1 -1
  123. package/lib/shape/line/smooth.d.ts +1 -3
  124. package/lib/shape/line/smooth.js +2 -2
  125. package/lib/shape/line/smooth.js.map +1 -1
  126. package/lib/spec/composition.d.ts +1 -1
  127. package/lib/spec/mark.d.ts +1 -1
  128. package/lib/spec/transform.d.ts +7 -2
  129. package/lib/transform/index.d.ts +2 -0
  130. package/lib/transform/index.js +3 -1
  131. package/lib/transform/index.js.map +1 -1
  132. package/lib/transform/jitterY.d.ts +8 -0
  133. package/lib/transform/jitterY.js +29 -0
  134. package/lib/transform/jitterY.js.map +1 -0
  135. package/package.json +4 -2
  136. package/src/animation/scaleInY.ts +142 -43
  137. package/src/component/slider.ts +42 -2
  138. package/src/composition/facetCircle.ts +1 -1
  139. package/src/interaction/chartIndex.ts +5 -1
  140. package/src/interaction/elementHighlight.ts +4 -0
  141. package/src/interaction/elementHighlightByColor.ts +4 -0
  142. package/src/interaction/elementHighlightByX.ts +4 -0
  143. package/src/interaction/elementSelect.ts +4 -0
  144. package/src/interaction/elementSelectByColor.ts +4 -0
  145. package/src/interaction/elementSelectByX.ts +4 -0
  146. package/src/interaction/event.ts +4 -0
  147. package/src/interaction/poptip.ts +4 -0
  148. package/src/interaction/sliderFilter.ts +3 -0
  149. package/src/interaction/tooltip.ts +18 -12
  150. package/src/lib/core.ts +2 -0
  151. package/src/mark/chord.ts +2 -0
  152. package/src/runtime/library.ts +10 -3
  153. package/src/runtime/plot.ts +58 -21
  154. package/src/runtime/render.ts +3 -2
  155. package/src/runtime/types/common.ts +1 -1
  156. package/src/shape/area/smooth.ts +14 -8
  157. package/src/shape/line/smooth.ts +3 -5
  158. package/src/spec/composition.ts +1 -1
  159. package/src/spec/mark.ts +1 -1
  160. package/src/spec/transform.ts +8 -0
  161. package/src/transform/index.ts +2 -0
  162. package/src/transform/jitterY.ts +30 -0
  163. package/CHANGELOG.md +0 -471
@@ -1,5 +1,15 @@
1
- import { isTranspose } from '../utils/coordinate';
1
+ import { arc } from 'd3-shape';
2
+ import {
3
+ Path,
4
+ convertToPath,
5
+ CSS,
6
+ PropertySyntax,
7
+ DisplayObject,
8
+ } from '@antv/g';
9
+ import { G2Element } from 'utils/selection';
2
10
  import { AnimationComponent as AC } from '../runtime';
11
+ import { isTranspose, isPolar } from '../utils/coordinate';
12
+ import { getArcObject } from '../shape/utils';
3
13
  import { Animation } from './types';
4
14
 
5
15
  export type ScaleInYOptions = Animation;
@@ -14,49 +24,138 @@ export const ScaleInY: AC<ScaleInYOptions> = (options, context) => {
14
24
 
15
25
  const { coordinate } = context;
16
26
 
27
+ // the polar coordinate need
28
+ CSS.registerProperty({
29
+ name: 'scaleInYRadius',
30
+ inherits: false,
31
+ initialValue: '',
32
+ interpolable: true,
33
+ syntax: PropertySyntax.NUMBER,
34
+ });
35
+
17
36
  return (from, _, defaults) => {
18
37
  const [shape] = from;
19
- const {
20
- transform: prefix = '',
21
- fillOpacity = 1,
22
- strokeOpacity = 1,
23
- opacity = 1,
24
- } = shape.style;
25
- const [transformOrigin, transform]: [string, string] = isTranspose(
26
- coordinate,
27
- )
28
- ? [`left top`, `scale(${ZERO}, 1)`] // left-top corner
29
- : [`left bottom`, `scale(1, ${ZERO})`]; // left-bottom corner
30
-
31
- // Using a short fadeIn transition to hide element with scale(0.001)
32
- // which is still visible.
33
- const keyframes = [
34
- {
35
- transform: `${prefix} ${transform}`.trimStart(),
36
- transformOrigin,
37
- fillOpacity: 0,
38
- strokeOpacity: 0,
39
- opacity: 0,
40
- },
41
- {
42
- transform: `${prefix} ${transform}`.trimStart(),
43
- transformOrigin,
44
- fillOpacity,
45
- strokeOpacity,
46
- opacity,
47
- offset: 0.01,
48
- },
49
- {
50
- transform: `${prefix} scale(1, 1)`.trimStart(),
51
- transformOrigin,
52
- fillOpacity,
53
- strokeOpacity,
54
- opacity,
55
- },
56
- ];
57
-
58
- const animation = shape.animate(keyframes, { ...defaults, ...options });
59
-
60
- return animation;
38
+ const PolarScaleInY = (shape: DisplayObject) => {
39
+ const { __data__, style } = shape as G2Element;
40
+ const {
41
+ radius = 0,
42
+ inset = 0,
43
+ fillOpacity = 1,
44
+ strokeOpacity = 1,
45
+ opacity = 1,
46
+ } = style;
47
+ const { points, y, y1 } = __data__;
48
+ const arcObject = getArcObject(coordinate, points, [y, y1]);
49
+ const { innerRadius, outerRadius } = arcObject;
50
+ const path = arc()
51
+ .cornerRadius(radius as number)
52
+ .padAngle((inset * Math.PI) / 180);
53
+ const pathForConversion = new Path({});
54
+ const center = coordinate.getCenter();
55
+ const createArcPath = (arcParams: {
56
+ startAngle: number;
57
+ endAngle: number;
58
+ innerRadius: number;
59
+ outerRadius: number;
60
+ }) => {
61
+ pathForConversion.attr({
62
+ d: path(arcParams),
63
+ transform: `translate(${center[0]}, ${center[1]})`,
64
+ });
65
+ const convertedPathDefinition = convertToPath(pathForConversion);
66
+ pathForConversion.style.transform = '';
67
+ return convertedPathDefinition;
68
+ };
69
+
70
+ const keyframes = [
71
+ {
72
+ scaleInYRadius: innerRadius + ZERO,
73
+ fillOpacity: 0,
74
+ strokeOpacity: 0,
75
+ opacity: 0,
76
+ },
77
+ {
78
+ scaleInYRadius: innerRadius + ZERO,
79
+ fillOpacity,
80
+ strokeOpacity,
81
+ opacity,
82
+ offset: 0.01,
83
+ },
84
+ {
85
+ scaleInYRadius: outerRadius,
86
+ fillOpacity,
87
+ strokeOpacity,
88
+ opacity,
89
+ },
90
+ ];
91
+
92
+ const animation = shape.animate(keyframes, { ...defaults, ...options });
93
+ animation.onframe = function () {
94
+ shape.style.path = createArcPath({
95
+ ...arcObject,
96
+ outerRadius: Number(shape.style.scaleInYRadius),
97
+ });
98
+ };
99
+
100
+ animation.onfinish = function () {
101
+ shape.style.path = createArcPath({
102
+ ...arcObject,
103
+ outerRadius: outerRadius,
104
+ });
105
+ };
106
+
107
+ return animation;
108
+ };
109
+
110
+ const RectangularScaleInY = (shape: DisplayObject) => {
111
+ const { style } = shape as G2Element;
112
+ const {
113
+ transform: prefix = '',
114
+ fillOpacity = 1,
115
+ strokeOpacity = 1,
116
+ opacity = 1,
117
+ } = style;
118
+ const [transformOrigin, transform]: [string, string] = isTranspose(
119
+ coordinate,
120
+ )
121
+ ? [`left top`, `scale(${ZERO}, 1)`] // left-top corner
122
+ : [`left bottom`, `scale(1, ${ZERO})`]; // left-bottom corner
123
+
124
+ // Using a short fadeIn transition to hide element with scale(0.001)
125
+ // which is still visible.
126
+ const keyframes = [
127
+ {
128
+ transform: `${prefix} ${transform}`.trimStart(),
129
+ transformOrigin,
130
+ fillOpacity: 0,
131
+ strokeOpacity: 0,
132
+ opacity: 0,
133
+ },
134
+ {
135
+ transform: `${prefix} ${transform}`.trimStart(),
136
+ transformOrigin,
137
+ fillOpacity,
138
+ strokeOpacity,
139
+ opacity,
140
+ offset: 0.01,
141
+ },
142
+ {
143
+ transform: `${prefix} scale(1, 1)`.trimStart(),
144
+ transformOrigin,
145
+ fillOpacity,
146
+ strokeOpacity,
147
+ opacity,
148
+ },
149
+ ];
150
+
151
+ const animation = shape.animate(keyframes, { ...defaults, ...options });
152
+ return animation;
153
+ };
154
+
155
+ if (isPolar(coordinate)) {
156
+ return PolarScaleInY(shape);
157
+ } else {
158
+ return RectangularScaleInY(shape);
159
+ }
61
160
  };
62
161
  };
@@ -1,8 +1,12 @@
1
1
  import { Slider as SliderComponent } from '@antv/component';
2
2
  import { format } from 'd3-format';
3
3
  import { DisplayObject } from '@antv/g';
4
+ import { isArray } from '@antv/util';
4
5
  import { isTranspose } from '../utils/coordinate';
5
- import { GuideComponentComponent as GCC } from '../runtime';
6
+ import {
7
+ GuideComponentComponent as GCC,
8
+ GuideComponentContext,
9
+ } from '../runtime';
6
10
  import { invert } from '../utils/scale';
7
11
 
8
12
  export type SliderOptions = {
@@ -32,7 +36,13 @@ export const Slider: GCC<SliderOptions> = (options) => {
32
36
  ...rest
33
37
  } = options;
34
38
 
35
- return ({ scales: [scale], value, theme, coordinate }) => {
39
+ return (context) => {
40
+ const {
41
+ scales: [scale],
42
+ value,
43
+ theme,
44
+ coordinate,
45
+ } = context;
36
46
  const { bbox } = value;
37
47
 
38
48
  const { width, height } = bbox;
@@ -60,6 +70,7 @@ export const Slider: GCC<SliderOptions> = (options) => {
60
70
  const tick = invert(scale, v1, true);
61
71
  return f(tick);
62
72
  },
73
+ sparklineData: inferSparklineData(options, context),
63
74
  ...style,
64
75
  ...rest,
65
76
  }),
@@ -67,6 +78,35 @@ export const Slider: GCC<SliderOptions> = (options) => {
67
78
  };
68
79
  };
69
80
 
81
+ function markValue(markState, channels: string[]) {
82
+ const [value] = Array.from(markState.entries())
83
+ .filter(([mark]) => mark.type === 'line' || mark.type === 'area')
84
+ .map(([mark]) => {
85
+ const { encode, slider } = mark;
86
+ if (slider?.x && Object.keys(slider.x).length === 0) {
87
+ const channel = (name) => {
88
+ const channel = encode[name];
89
+ return [name, channel ? channel.value : undefined];
90
+ };
91
+ return Object.fromEntries(channels.map(channel));
92
+ }
93
+ });
94
+
95
+ if (!value?.series) return value?.y;
96
+ const result = value.series.reduce((acc, curr, index) => {
97
+ acc[curr] = acc[curr] || [];
98
+ acc[curr].push(value.y[index]);
99
+ return acc;
100
+ }, {});
101
+ return Object.values(result);
102
+ }
103
+
104
+ function inferSparklineData(options, context: GuideComponentContext) {
105
+ const { markState } = context;
106
+ if (isArray(options.sparklineData)) return options.sparklineData;
107
+ return markValue(markState, ['y', 'series']);
108
+ }
109
+
70
110
  Slider.props = {
71
111
  defaultPosition: 'bottom',
72
112
  defaultSize: 24,
@@ -71,7 +71,7 @@ function subLayoutFacetCircle(data) {
71
71
  const a3 = a0 + a01 / 2;
72
72
  const d = ir * t;
73
73
  const cx = x0 + d * Math.sin(a3); // center x of inscribed circle
74
- const cy = y0 + d * Math.cos(a3); // center y of inscribed circle
74
+ const cy = y0 - d * Math.cos(a3); // center y of inscribed circle
75
75
  return [cx - s / 2, cy - s / 2, s, s];
76
76
  }
77
77
 
@@ -154,7 +154,7 @@ export function ChartIndex({
154
154
  return clonedOptions;
155
155
  });
156
156
 
157
- const newState = await update();
157
+ const newState = await update('chartIndex');
158
158
  newView = newState.view;
159
159
  };
160
160
 
@@ -215,3 +215,7 @@ export function ChartIndex({
215
215
  };
216
216
  };
217
217
  }
218
+
219
+ ChartIndex.props = {
220
+ reapplyWhenUpdate: true,
221
+ };
@@ -194,3 +194,7 @@ export function ElementHighlight({
194
194
  });
195
195
  };
196
196
  }
197
+
198
+ ElementHighlight.props = {
199
+ reapplyWhenUpdate: true,
200
+ };
@@ -4,3 +4,7 @@ import { ElementHighlight } from './elementHighlight';
4
4
  export function ElementHighlightByColor(options) {
5
5
  return ElementHighlight({ ...options, createGroup: createColorKey });
6
6
  }
7
+
8
+ ElementHighlightByColor.props = {
9
+ reapplyWhenUpdate: true,
10
+ };
@@ -4,3 +4,7 @@ import { ElementHighlight } from './elementHighlight';
4
4
  export function ElementHighlightByX(options) {
5
5
  return ElementHighlight({ ...options, createGroup: createXKey });
6
6
  }
7
+
8
+ ElementHighlightByX.props = {
9
+ reapplyWhenUpdate: true,
10
+ };
@@ -209,3 +209,7 @@ export function ElementSelect({
209
209
  });
210
210
  };
211
211
  }
212
+
213
+ ElementSelect.props = {
214
+ reapplyWhenUpdate: true,
215
+ };
@@ -4,3 +4,7 @@ import { ElementSelect } from './elementSelect';
4
4
  export function ElementSelectByColor(options) {
5
5
  return ElementSelect({ ...options, createGroup: createColorKey });
6
6
  }
7
+
8
+ ElementSelectByColor.props = {
9
+ reapplyWhenUpdate: true,
10
+ };
@@ -4,3 +4,7 @@ import { ElementSelect } from './elementSelect';
4
4
  export function ElementSelectByX(options) {
5
5
  return ElementSelect({ ...options, createGroup: createXKey });
6
6
  }
7
+
8
+ ElementSelectByX.props = {
9
+ reapplyWhenUpdate: true,
10
+ };
@@ -162,3 +162,7 @@ export function Event() {
162
162
  };
163
163
  };
164
164
  }
165
+
166
+ Event.props = {
167
+ reapplyWhenUpdate: true,
168
+ };
@@ -85,3 +85,7 @@ export function Poptip({ offsetX = 8, offsetY = 8, ...style }) {
85
85
  };
86
86
  };
87
87
  }
88
+
89
+ Poptip.props = {
90
+ reapplyWhenUpdate: true,
91
+ };
@@ -207,6 +207,9 @@ export function SliderFilter({
207
207
  emitHandlers.add([eventName, emitHandler]);
208
208
  }
209
209
 
210
+ // Update to async state such as scale.
211
+ update();
212
+
210
213
  return () => {
211
214
  for (const [slider, handler] of sliderHandler) {
212
215
  slider.removeEventListener('valuechange', handler);
@@ -22,12 +22,15 @@ import { dataOf } from './event';
22
22
 
23
23
  function getContainer(
24
24
  group: IElement,
25
- mount: string | HTMLElement,
25
+ mount?: string | HTMLElement,
26
26
  ): HTMLElement {
27
- if (mount)
27
+ if (mount) {
28
28
  return typeof mount === 'string' ? document.querySelector(mount) : mount;
29
- // @ts-ignore
30
- return group.getRootNode().defaultView.getConfig().container;
29
+ }
30
+ const canvas: any = group.ownerDocument.defaultView
31
+ .getContextService()
32
+ .getDomElement();
33
+ return canvas.parentElement as unknown as HTMLElement;
31
34
  }
32
35
 
33
36
  function getBounding(root): BBox {
@@ -110,12 +113,10 @@ function showTooltip({
110
113
  mount,
111
114
  bounding,
112
115
  }) {
113
- const canvasContainer = root.getRootNode().defaultView.getConfig().container;
114
116
  const container = getContainer(root, mount);
115
-
117
+ const canvasContainer = getContainer(root);
116
118
  // All the views share the same tooltip.
117
119
  const parent = single ? canvasContainer : root;
118
-
119
120
  const b = bounding || getBounding(root);
120
121
  const containerOffset = getContainerOffset(canvasContainer, container);
121
122
  const {
@@ -149,8 +150,8 @@ function hideTooltip({ root, single, emitter, nativeEvent = true }) {
149
150
  if (nativeEvent) {
150
151
  emitter.emit('tooltip:hide', { nativeEvent });
151
152
  }
152
- const canvasContainer = root.getRootNode().defaultView.getConfig().container;
153
- const parent = single ? canvasContainer : root;
153
+ const container = getContainer(root);
154
+ const parent = single ? container : root;
154
155
  const { tooltipElement } = parent;
155
156
  if (tooltipElement) {
156
157
  tooltipElement.hide();
@@ -158,8 +159,8 @@ function hideTooltip({ root, single, emitter, nativeEvent = true }) {
158
159
  }
159
160
 
160
161
  function destroyTooltip({ root, single }) {
161
- const canvasContainer = root.getRootNode().defaultView.getConfig().container;
162
- const parent = single ? canvasContainer : root;
162
+ const container = getContainer(root);
163
+ const parent = single ? container : root;
163
164
  if (!parent) return;
164
165
  const { tooltipElement } = parent;
165
166
  if (tooltipElement) {
@@ -520,7 +521,8 @@ export function seriesTooltip(
520
521
 
521
522
  const indexByFocus = (focus, I, X) => {
522
523
  const finalX = abstractX(focus);
523
- const [minX, maxX] = sort([X[0], X[X.length - 1]]);
524
+ const DX = X.filter(defined);
525
+ const [minX, maxX] = sort([DX[0], DX[DX.length - 1]]);
524
526
  // If closest is true, always find at least one element.
525
527
  // Otherwise, skip element out of plot area.
526
528
  if (!closest && (finalX < minX || finalX > maxX)) return null;
@@ -992,3 +994,7 @@ export function Tooltip(options) {
992
994
  });
993
995
  };
994
996
  }
997
+
998
+ Tooltip.props = {
999
+ reapplyWhenUpdate: true,
1000
+ };
package/src/lib/core.ts CHANGED
@@ -116,6 +116,7 @@ import {
116
116
  NormalizeY,
117
117
  Jitter,
118
118
  JitterX,
119
+ JitterY,
119
120
  SymmetryY,
120
121
  DiffY,
121
122
  Select,
@@ -180,6 +181,7 @@ export function corelib() {
180
181
  'transform.dodgeX': DodgeX,
181
182
  'transform.jitter': Jitter,
182
183
  'transform.jitterX': JitterX,
184
+ 'transform.jitterY': JitterY,
183
185
  'transform.symmetryY': SymmetryY,
184
186
  'transform.diffY': DiffY,
185
187
  'transform.stackEnter': StackEnter,
package/src/mark/chord.ts CHANGED
@@ -140,6 +140,8 @@ export const Chord: CC<ChordOptions> = (options, context) => {
140
140
  type: 'polar',
141
141
  // Leave enough rendering space for the label.
142
142
  outerRadius: (minimumLen - 20) / minimumLen,
143
+ startAngle: -Math.PI * 2,
144
+ endAngle: 0,
143
145
  },
144
146
  labels: [
145
147
  {
@@ -23,15 +23,22 @@ export function useLibrary<
23
23
  const key = `${namespace}.${type}`;
24
24
  return library[key] || error(`Unknown Component: ${key}`);
25
25
  };
26
+
26
27
  const use = (options: O, context?) => {
27
28
  const { type, ...rest } = options;
28
- return create(type)(rest, context);
29
+ if (!type) error(`Plot type is required!`);
30
+ const currentLibrary = create(type);
31
+ return currentLibrary?.(rest, context);
29
32
  };
33
+
30
34
  return [use, create];
31
35
  }
32
36
 
33
37
  export function documentOf(library: G2Context): IDocument {
34
38
  const { canvas, group } = library;
35
- if (group) return group.ownerDocument;
36
- return canvas.document;
39
+ return (
40
+ canvas?.document ||
41
+ group?.ownerDocument ||
42
+ error(`Cannot find library document`)
43
+ );
37
44
  }
@@ -248,18 +248,23 @@ export async function plot<T extends G2ViewTree>(
248
248
  // Each state transform options to another options.
249
249
  const store = new Map<any, (options: G2ViewTree) => G2ViewTree>();
250
250
  const setState = (key, reducer = (x) => x) => store.set(key, reducer);
251
- const update = createUpdateView(select(container), library, context);
252
251
  const options = viewNode.get(view);
252
+ const update = createUpdateView(
253
+ select(container),
254
+ options,
255
+ library,
256
+ context,
257
+ );
253
258
  return {
254
259
  view,
255
260
  container,
256
261
  options,
257
262
  setState,
258
- update: async () => {
263
+ update: async (from) => {
259
264
  // Apply all state functions to get new options.
260
265
  const reducer = compose(Array.from(store.values()));
261
266
  const newOptions = reducer(options);
262
- return await update(newOptions);
267
+ return await update(newOptions, from);
263
268
  },
264
269
  };
265
270
  });
@@ -367,24 +372,56 @@ function applyTranslate(selection: Selection) {
367
372
  );
368
373
  }
369
374
 
375
+ function definedInteraction(library: G2Library) {
376
+ const [, createInteraction] = useLibrary<
377
+ G2InteractionOptions,
378
+ InteractionComponent,
379
+ Interaction
380
+ >('interaction', library);
381
+ return (d) => {
382
+ const [name, options] = d;
383
+ try {
384
+ return [name, createInteraction(name)] as const;
385
+ } catch {
386
+ return [name, options.type] as const;
387
+ }
388
+ };
389
+ }
390
+
370
391
  function createUpdateView(
371
392
  selection: Selection,
393
+ options: G2ViewTree,
372
394
  library: G2Library,
373
395
  context: G2Context,
374
396
  ): G2ViewInstance['update'] {
375
- return async (newOptions) => {
397
+ const createDefinedInteraction = definedInteraction(library);
398
+ const filter = (d) => d[1] && d[1].props && d[1].props.reapplyWhenUpdate;
399
+ const interactions = inferInteraction(options);
400
+ const updates = interactions
401
+ .map(createDefinedInteraction)
402
+ .filter(filter)
403
+ .map((d) => d[0]);
404
+
405
+ return async (newOptions, source) => {
376
406
  const transitions = [];
377
407
  const [newView, newChildren] = await initializeView(newOptions, library);
378
408
  plotView(newView, selection, transitions, library, context);
379
- updateTooltip(selection, newOptions, newView, library, context);
409
+
410
+ // Update interaction need to reapply when update.
411
+ for (const name of updates.filter((d) => d !== source)) {
412
+ updateInteraction(name, selection, newOptions, newView, library, context);
413
+ }
414
+
380
415
  for (const child of newChildren) {
381
416
  plot(child, selection, library, context);
382
417
  }
418
+
383
419
  return { options: newOptions, view: newView };
384
420
  };
385
421
  }
386
422
 
387
- function updateTooltip(
423
+ function updateInteraction(
424
+ name: string,
388
425
  selection: Selection,
389
426
  options: G2ViewTree,
390
427
  view: G2ViewDescriptor,
@@ -397,25 +434,25 @@ function updateTooltip(
397
434
  Interaction
398
435
  >('interaction', library);
399
436
 
400
- // Instances for tooltip.
437
+ // Instances for interaction.
401
438
  const container = selection.node();
402
439
  const nameInteraction = container['nameInteraction'];
403
- const tooltipOptions = inferInteraction(options).find(
404
- ([d]) => d === 'tooltip',
440
+ const interactionOptions = inferInteraction(options).find(
441
+ ([d]) => d === name,
405
442
  );
406
443
 
407
- // Destroy older tooltip.
408
- const tooltip = nameInteraction.get('tooltip');
409
- if (!tooltip) return;
410
- tooltip.destroy?.();
444
+ // Destroy older interaction.
445
+ const interaction = nameInteraction.get(name);
446
+ if (!interaction) return;
447
+ interaction.destroy?.();
411
448
 
412
- if (!tooltipOptions[1]) return;
449
+ if (!interactionOptions[1]) return;
413
450
 
414
- // Apply new tooltip interaction.
415
- const applyTooltip = useThemeInteraction(
451
+ // Apply new interaction.
452
+ const applyInteraction = useThemeInteraction(
416
453
  view,
417
- 'tooltip',
418
- tooltipOptions[1] as any,
454
+ name,
455
+ interactionOptions[1] as any,
419
456
  useInteraction,
420
457
  );
421
458
  const target = {
@@ -424,8 +461,8 @@ function updateTooltip(
424
461
  container: selection.node(),
425
462
  update: (options) => Promise.resolve(options),
426
463
  };
427
- const destroy = applyTooltip(target, [], context.emitter);
428
- nameInteraction.set('tooltip', { destroy });
464
+ const destroy = applyInteraction(target, [], context.emitter);
465
+ nameInteraction.set(name, { destroy });
429
466
  }
430
467
 
431
468
  async function initializeView(
@@ -1600,7 +1637,7 @@ function inferInteraction(
1600
1637
  scrollbarFilter: true,
1601
1638
  };
1602
1639
  const { interaction = {} } = view;
1603
- return Object.entries(deepMix(defaults, interaction));
1640
+ return Object.entries(deepMix(defaults, interaction)).reverse();
1604
1641
  }
1605
1642
 
1606
1643
  async function applyTransform<T extends G2ViewTree>(
@@ -140,14 +140,15 @@ export function renderToMountedElement<T extends G2ViewTree = G2ViewTree>(
140
140
  const selection = select(group);
141
141
  context.group = group;
142
142
  context.emitter = emitter;
143
+ context.canvas =
144
+ context.canvas || (group?.ownerDocument?.defaultView as GCanvas);
143
145
 
144
146
  emitter.emit(ChartEvent.BEFORE_RENDER);
145
147
  // Plot the chart and mutate context.
146
148
  // Make sure that plot chart after container is ready for every time.
147
149
  plot<T>({ ...keyed, width, height }, selection, library, context)
148
150
  .then(() => {
149
- const canvas = group.ownerDocument.defaultView;
150
- canvas.requestAnimationFrame(() => {
151
+ context.canvas?.requestAnimationFrame(() => {
151
152
  emitter.emit(ChartEvent.AFTER_RENDER);
152
153
  resolve?.();
153
154
  });
@@ -53,7 +53,7 @@ export type G2ViewInstance = {
53
53
  view: G2ViewDescriptor;
54
54
  container: DisplayObject;
55
55
  options: G2ViewTree;
56
- update: (options: G2ViewTree) => Promise<any>;
56
+ update: (options: G2ViewTree, source?: string) => Promise<any>;
57
57
  };
58
58
 
59
59
  export type ChannelGroups = {