@antv/g2 5.1.8 → 5.1.10

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 (160) hide show
  1. package/CHANGELOG.md +484 -0
  2. package/README.md +7 -0
  3. package/README.zh-CN.md +7 -0
  4. package/dist/g2.lite.min.js +1 -1
  5. package/dist/g2.min.js +1 -1
  6. package/esm/component/slider.js +1 -1
  7. package/esm/component/slider.js.map +1 -1
  8. package/esm/composition/facetCircle.js +1 -1
  9. package/esm/data/utils/arc/arc.js +4 -4
  10. package/esm/data/utils/arc/arc.js.map +1 -1
  11. package/esm/index.d.ts +2 -0
  12. package/esm/interaction/chartIndex.d.ts +5 -0
  13. package/esm/interaction/chartIndex.js +4 -1
  14. package/esm/interaction/chartIndex.js.map +1 -1
  15. package/esm/interaction/elementHighlight.d.ts +5 -0
  16. package/esm/interaction/elementHighlight.js +3 -0
  17. package/esm/interaction/elementHighlight.js.map +1 -1
  18. package/esm/interaction/elementHighlightByColor.d.ts +5 -0
  19. package/esm/interaction/elementHighlightByColor.js +3 -0
  20. package/esm/interaction/elementHighlightByColor.js.map +1 -1
  21. package/esm/interaction/elementHighlightByX.d.ts +5 -0
  22. package/esm/interaction/elementHighlightByX.js +3 -0
  23. package/esm/interaction/elementHighlightByX.js.map +1 -1
  24. package/esm/interaction/elementSelect.d.ts +5 -0
  25. package/esm/interaction/elementSelect.js +3 -0
  26. package/esm/interaction/elementSelect.js.map +1 -1
  27. package/esm/interaction/elementSelectByColor.d.ts +5 -0
  28. package/esm/interaction/elementSelectByColor.js +3 -0
  29. package/esm/interaction/elementSelectByColor.js.map +1 -1
  30. package/esm/interaction/elementSelectByX.d.ts +5 -0
  31. package/esm/interaction/elementSelectByX.js +3 -0
  32. package/esm/interaction/elementSelectByX.js.map +1 -1
  33. package/esm/interaction/event.d.ts +5 -0
  34. package/esm/interaction/event.js +3 -0
  35. package/esm/interaction/event.js.map +1 -1
  36. package/esm/interaction/poptip.d.ts +5 -0
  37. package/esm/interaction/poptip.js +3 -0
  38. package/esm/interaction/poptip.js.map +1 -1
  39. package/esm/interaction/sliderFilter.js +2 -0
  40. package/esm/interaction/sliderFilter.js.map +1 -1
  41. package/esm/interaction/tooltip.d.ts +5 -0
  42. package/esm/interaction/tooltip.js +7 -3
  43. package/esm/interaction/tooltip.js.map +1 -1
  44. package/esm/interaction/utils.d.ts +1 -0
  45. package/esm/interaction/utils.js +7 -1
  46. package/esm/interaction/utils.js.map +1 -1
  47. package/esm/lib/graph.d.ts +1 -0
  48. package/esm/lib/graph.js +2 -1
  49. package/esm/lib/graph.js.map +1 -1
  50. package/esm/lib/std.d.ts +1 -0
  51. package/esm/mark/chord.d.ts +4 -0
  52. package/esm/mark/chord.js +121 -0
  53. package/esm/mark/chord.js.map +1 -0
  54. package/esm/mark/index.d.ts +2 -0
  55. package/esm/mark/index.js +1 -0
  56. package/esm/mark/index.js.map +1 -1
  57. package/esm/runtime/plot.js +29 -19
  58. package/esm/runtime/plot.js.map +1 -1
  59. package/esm/runtime/scale.js +11 -18
  60. package/esm/runtime/scale.js.map +1 -1
  61. package/esm/runtime/types/common.d.ts +1 -1
  62. package/esm/shape/area/curve.js +5 -2
  63. package/esm/shape/area/curve.js.map +1 -1
  64. package/esm/shape/line/curve.js +4 -3
  65. package/esm/shape/line/curve.js.map +1 -1
  66. package/esm/shape/utils.d.ts +1 -1
  67. package/esm/shape/utils.js +21 -2
  68. package/esm/shape/utils.js.map +1 -1
  69. package/esm/spec/mark.d.ts +17 -2
  70. package/lib/component/slider.js +1 -1
  71. package/lib/component/slider.js.map +1 -1
  72. package/lib/composition/facetCircle.js +1 -1
  73. package/lib/data/utils/arc/arc.js +4 -4
  74. package/lib/data/utils/arc/arc.js.map +1 -1
  75. package/lib/index.d.ts +2 -0
  76. package/lib/interaction/chartIndex.d.ts +5 -0
  77. package/lib/interaction/chartIndex.js +4 -1
  78. package/lib/interaction/chartIndex.js.map +1 -1
  79. package/lib/interaction/elementHighlight.d.ts +5 -0
  80. package/lib/interaction/elementHighlight.js +3 -0
  81. package/lib/interaction/elementHighlight.js.map +1 -1
  82. package/lib/interaction/elementHighlightByColor.d.ts +5 -0
  83. package/lib/interaction/elementHighlightByColor.js +3 -0
  84. package/lib/interaction/elementHighlightByColor.js.map +1 -1
  85. package/lib/interaction/elementHighlightByX.d.ts +5 -0
  86. package/lib/interaction/elementHighlightByX.js +3 -0
  87. package/lib/interaction/elementHighlightByX.js.map +1 -1
  88. package/lib/interaction/elementSelect.d.ts +5 -0
  89. package/lib/interaction/elementSelect.js +3 -0
  90. package/lib/interaction/elementSelect.js.map +1 -1
  91. package/lib/interaction/elementSelectByColor.d.ts +5 -0
  92. package/lib/interaction/elementSelectByColor.js +3 -0
  93. package/lib/interaction/elementSelectByColor.js.map +1 -1
  94. package/lib/interaction/elementSelectByX.d.ts +5 -0
  95. package/lib/interaction/elementSelectByX.js +3 -0
  96. package/lib/interaction/elementSelectByX.js.map +1 -1
  97. package/lib/interaction/event.d.ts +5 -0
  98. package/lib/interaction/event.js +3 -0
  99. package/lib/interaction/event.js.map +1 -1
  100. package/lib/interaction/poptip.d.ts +5 -0
  101. package/lib/interaction/poptip.js +3 -0
  102. package/lib/interaction/poptip.js.map +1 -1
  103. package/lib/interaction/sliderFilter.js +2 -0
  104. package/lib/interaction/sliderFilter.js.map +1 -1
  105. package/lib/interaction/tooltip.d.ts +5 -0
  106. package/lib/interaction/tooltip.js +6 -2
  107. package/lib/interaction/tooltip.js.map +1 -1
  108. package/lib/interaction/utils.d.ts +1 -0
  109. package/lib/interaction/utils.js +9 -2
  110. package/lib/interaction/utils.js.map +1 -1
  111. package/lib/lib/graph.d.ts +1 -0
  112. package/lib/lib/graph.js +1 -0
  113. package/lib/lib/graph.js.map +1 -1
  114. package/lib/lib/std.d.ts +1 -0
  115. package/lib/mark/chord.d.ts +4 -0
  116. package/lib/mark/chord.js +125 -0
  117. package/lib/mark/chord.js.map +1 -0
  118. package/lib/mark/index.d.ts +2 -0
  119. package/lib/mark/index.js +3 -1
  120. package/lib/mark/index.js.map +1 -1
  121. package/lib/runtime/plot.js +29 -19
  122. package/lib/runtime/plot.js.map +1 -1
  123. package/lib/runtime/scale.js +11 -18
  124. package/lib/runtime/scale.js.map +1 -1
  125. package/lib/runtime/types/common.d.ts +1 -1
  126. package/lib/shape/area/curve.js +5 -2
  127. package/lib/shape/area/curve.js.map +1 -1
  128. package/lib/shape/line/curve.js +3 -2
  129. package/lib/shape/line/curve.js.map +1 -1
  130. package/lib/shape/utils.d.ts +1 -1
  131. package/lib/shape/utils.js +21 -2
  132. package/lib/shape/utils.js.map +1 -1
  133. package/lib/spec/mark.d.ts +17 -2
  134. package/package.json +4 -7
  135. package/src/component/slider.ts +1 -1
  136. package/src/composition/facetCircle.ts +1 -1
  137. package/src/data/utils/arc/arc.ts +4 -4
  138. package/src/interaction/chartIndex.ts +5 -1
  139. package/src/interaction/elementHighlight.ts +4 -0
  140. package/src/interaction/elementHighlightByColor.ts +4 -0
  141. package/src/interaction/elementHighlightByX.ts +4 -0
  142. package/src/interaction/elementSelect.ts +4 -0
  143. package/src/interaction/elementSelectByColor.ts +4 -0
  144. package/src/interaction/elementSelectByX.ts +4 -0
  145. package/src/interaction/event.ts +4 -0
  146. package/src/interaction/poptip.ts +4 -0
  147. package/src/interaction/sliderFilter.ts +3 -0
  148. package/src/interaction/tooltip.ts +8 -2
  149. package/src/interaction/utils.ts +7 -1
  150. package/src/lib/graph.ts +2 -1
  151. package/src/mark/chord.ts +161 -0
  152. package/src/mark/index.ts +2 -0
  153. package/src/runtime/plot.ts +47 -21
  154. package/src/runtime/scale.ts +11 -16
  155. package/src/runtime/types/common.ts +1 -1
  156. package/src/shape/area/curve.ts +6 -2
  157. package/src/shape/line/curve.ts +6 -3
  158. package/src/shape/utils.ts +20 -1
  159. package/src/spec/mark.ts +31 -0
  160. package/dist/g2.full.min.js +0 -1
package/package.json CHANGED
@@ -1,11 +1,12 @@
1
1
  {
2
2
  "name": "@antv/g2",
3
- "version": "5.1.8",
3
+ "version": "5.1.10",
4
4
  "description": "the Grammar of Graphics in Javascript",
5
5
  "license": "MIT",
6
6
  "main": "lib/index.js",
7
7
  "module": "esm/index.js",
8
8
  "types": "lib/index.d.ts",
9
+ "unpkg": "dist/g2.min.js",
9
10
  "exports": {
10
11
  ".": {
11
12
  "types": "./lib/index.d.ts",
@@ -40,6 +41,7 @@
40
41
  "build": "run-p build:*",
41
42
  "bundle-vis": "cross-env BUNDLE_VIS=1 run-p build:umd",
42
43
  "ci": "run-s lint test build",
44
+ "prepublishOnly": "npm run ci",
43
45
  "prepare": "husky install",
44
46
  "upload": "node scripts/upload/snapshot.js",
45
47
  "changelog": "conventional-changelog -p angular -i CHANGELOG.md -s",
@@ -87,7 +89,7 @@
87
89
  "@antv/g-plugin-rough-svg-renderer": "^1.9.22",
88
90
  "@antv/g-svg": "^1.10.21",
89
91
  "@antv/g-webgl": "^1.9.29",
90
- "@antv/g2-extension-3d": "0.1.1",
92
+ "@antv/g2-extension-3d": "^0.1.3",
91
93
  "@antv/g2-extension-ava": "^0.1.1",
92
94
  "@antv/translator": "^1.0.1",
93
95
  "@commitlint/cli": "^11.0.0",
@@ -161,11 +163,6 @@
161
163
  "path": "dist/g2.lite.min.js",
162
164
  "limit": "240 Kb",
163
165
  "gzip": true
164
- },
165
- {
166
- "path": "dist/g2.full.min.js",
167
- "limit": "350 Kb",
168
- "gzip": true
169
166
  }
170
167
  ],
171
168
  "author": {
@@ -37,7 +37,7 @@ export const Slider: GCC<SliderOptions> = (options) => {
37
37
 
38
38
  const { width, height } = bbox;
39
39
  const { slider: sliderTheme = {} } = theme;
40
- const defaultFormatter = scale.getFormatter?.() || ((v) => v.toString());
40
+ const defaultFormatter = scale.getFormatter?.() || ((v) => v + '');
41
41
  const formatter =
42
42
  typeof labelFormatter === 'string'
43
43
  ? format(labelFormatter)
@@ -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
 
@@ -190,16 +190,16 @@ export function Arc(options?: ArcOptions) {
190
190
  */
191
191
  sourceEdges.map((edge) => {
192
192
  const w = (edge.sourceWeight / value) * width;
193
- edge.x[0] = node.x[0] + offset;
194
- edge.x[1] = node.x[0] + offset + w;
193
+ edge.x[0] = x[0] + offset;
194
+ edge.x[1] = x[0] + offset + w;
195
195
 
196
196
  offset += w;
197
197
  });
198
198
 
199
199
  targetEdges.forEach((edge) => {
200
200
  const w = (edge.targetWeight / value) * width;
201
- edge.x[3] = node.x[0] + offset;
202
- edge.x[2] = node.x[0] + offset + w;
201
+ edge.x[3] = x[0] + offset;
202
+ edge.x[2] = x[0] + offset + w;
203
203
 
204
204
  offset += w;
205
205
  });
@@ -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);
@@ -16,6 +16,7 @@ import {
16
16
  selectFacetG2Elements,
17
17
  createDatumof,
18
18
  selectElementByData,
19
+ bboxOf,
19
20
  } from './utils';
20
21
  import { dataOf } from './event';
21
22
 
@@ -519,7 +520,8 @@ export function seriesTooltip(
519
520
 
520
521
  const indexByFocus = (focus, I, X) => {
521
522
  const finalX = abstractX(focus);
522
- const [minX, maxX] = sort([X[0], X[X.length - 1]]);
523
+ const DX = X.filter(defined);
524
+ const [minX, maxX] = sort([DX[0], DX[DX.length - 1]]);
523
525
  // If closest is true, always find at least one element.
524
526
  // Otherwise, skip element out of plot area.
525
527
  if (!closest && (finalX < minX || finalX > maxX)) return null;
@@ -563,7 +565,7 @@ export function seriesTooltip(
563
565
  (event) => {
564
566
  const mouse = mousePosition(root, event);
565
567
  if (!mouse) return;
566
- const bbox = root.getRenderBounds();
568
+ const bbox = bboxOf(root);
567
569
  const x = bbox.min[0];
568
570
  const y = bbox.min[1];
569
571
  const focus = [mouse[0] - startX, mouse[1] - startY];
@@ -991,3 +993,7 @@ export function Tooltip(options) {
991
993
  });
992
994
  };
993
995
  }
996
+
997
+ Tooltip.props = {
998
+ reapplyWhenUpdate: true,
999
+ };
@@ -42,9 +42,15 @@ export function selectPlotArea(root: DisplayObject): DisplayObject {
42
42
  return select(root).select(`.${PLOT_CLASS_NAME}`).node();
43
43
  }
44
44
 
45
+ export function bboxOf(node) {
46
+ if (node.nodeName !== 'rect') return node.getRenderBounds();
47
+ const { x, y, width, height } = node.style;
48
+ return { min: [x, y], max: [x + width, y + height] };
49
+ }
50
+
45
51
  export function mousePosition(target, event) {
46
52
  const { offsetX, offsetY } = event;
47
- const bbox = target.getRenderBounds();
53
+ const bbox = bboxOf(target);
48
54
  const {
49
55
  min: [x, y],
50
56
  max: [x1, y1],
package/src/lib/graph.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Sankey, Treemap, Pack, ForceGraph, Tree } from '../mark';
1
+ import { Sankey, Treemap, Pack, ForceGraph, Tree, Chord } from '../mark';
2
2
  import { Arc, Cluster } from '../data';
3
3
 
4
4
  export function graphlib() {
@@ -9,6 +9,7 @@ export function graphlib() {
9
9
  'mark.tree': Tree,
10
10
  'mark.pack': Pack,
11
11
  'mark.sankey': Sankey,
12
+ 'mark.chord': Chord,
12
13
  'mark.treemap': Treemap,
13
14
  } as const;
14
15
  }
@@ -0,0 +1,161 @@
1
+ import { deepMix } from '@antv/util';
2
+ import { CompositeMarkComponent as CC, MarkOptions } from '../runtime';
3
+ import { ChordMark } from '../spec';
4
+ import { subObject } from '../utils/helper';
5
+ import { subTooltip, maybeAnimation } from '../utils/mark';
6
+ import { Arc } from '../data/arc';
7
+ import { ArcOptions } from '../data/utils/arc/types';
8
+ import { field, initializeData } from './utils';
9
+
10
+ const DEFAULT_LAYOUT_OPTIONS: ArcOptions = {
11
+ y: 0,
12
+ thickness: 0.05, // width of the node, (0, 1)
13
+ marginRatio: 0.1, // margin ratio, [0, 1)
14
+ id: (node) => node.key,
15
+ source: (edge) => edge.source,
16
+ target: (edge) => edge.target,
17
+ sourceWeight: (edge) => edge.value || 1,
18
+ targetWeight: (edge) => edge.value || 1,
19
+ sortBy: null, // optional, id | weight | frequency | {function}
20
+ };
21
+
22
+ const DEFAULT_NODE_OPTIONS = {
23
+ type: 'polygon',
24
+ axis: false,
25
+ legend: false,
26
+ encode: {
27
+ shape: 'polygon',
28
+ x: 'x',
29
+ y: 'y',
30
+ },
31
+ scale: {
32
+ x: { type: 'identity' },
33
+ y: { type: 'identity' },
34
+ },
35
+ style: {
36
+ opacity: 1,
37
+ fillOpacity: 1,
38
+ lineWidth: 1,
39
+ },
40
+ };
41
+
42
+ const DEFAULT_LINK_OPTIONS = {
43
+ type: 'polygon',
44
+ axis: false,
45
+ legend: false,
46
+ encode: {
47
+ shape: 'ribbon',
48
+ x: 'x',
49
+ y: 'y',
50
+ },
51
+ style: {
52
+ opacity: 0.5,
53
+ lineWidth: 1,
54
+ strokeWidth: 1,
55
+ },
56
+ };
57
+
58
+ const DEFAULT_LABEL_OPTIONS = {
59
+ position: 'outside',
60
+ fontSize: 10,
61
+ };
62
+
63
+ export type ChordOptions = Omit<ChordMark, 'type'>;
64
+
65
+ export const Chord: CC<ChordOptions> = (options, context) => {
66
+ const {
67
+ data,
68
+ encode = {},
69
+ scale,
70
+ style = {},
71
+ layout = {},
72
+ nodeLabels = [],
73
+ linkLabels = [],
74
+ animate = {},
75
+ tooltip = {},
76
+ } = options;
77
+
78
+ // Initialize data, generating nodes by link if is not specified.
79
+ const { nodes, links } = initializeData(data, encode);
80
+
81
+ // Extract encode for node and link.
82
+ const nodeEncode = subObject(encode, 'node');
83
+ const linkEncode = subObject(encode, 'link');
84
+ const { key: nodeKey = (d) => d.key, color = nodeKey } = nodeEncode;
85
+ const { linkEncodeColor = (d) => d.source } = linkEncode;
86
+ const {
87
+ nodeWidthRatio = DEFAULT_LAYOUT_OPTIONS.thickness,
88
+ nodePaddingRatio = DEFAULT_LAYOUT_OPTIONS.marginRatio,
89
+ ...restLayout
90
+ } = layout;
91
+
92
+ const { nodes: nodeData, edges: linkData } = Arc({
93
+ ...DEFAULT_LAYOUT_OPTIONS,
94
+ id: field(nodeKey),
95
+ thickness: nodeWidthRatio,
96
+ marginRatio: nodePaddingRatio,
97
+ ...restLayout,
98
+ weight: true,
99
+ })({ nodes, edges: links });
100
+
101
+ // Extract label style and apply defaults.
102
+ const { text = nodeKey, ...labelStyle } = subObject(style, 'label');
103
+
104
+ const nodeTooltip = subTooltip(
105
+ tooltip,
106
+ 'node',
107
+ {
108
+ title: '',
109
+ items: [(d) => ({ name: d.key, value: d.value })],
110
+ },
111
+ true,
112
+ );
113
+ const linkTooltip = subTooltip(tooltip, 'link', {
114
+ title: '',
115
+ items: [(d) => ({ name: `${d.source} -> ${d.target}`, value: d.value })],
116
+ });
117
+
118
+ const { height, width } = context;
119
+
120
+ const minimumLen = Math.min(height, width);
121
+
122
+ return [
123
+ deepMix({}, DEFAULT_LINK_OPTIONS, {
124
+ data: linkData,
125
+ encode: { ...linkEncode, color: linkEncodeColor },
126
+ labels: linkLabels,
127
+ style: {
128
+ fill: linkEncodeColor ? undefined : '#aaa',
129
+ ...subObject(style, 'link'),
130
+ },
131
+ tooltip: linkTooltip,
132
+ animate: maybeAnimation(animate, 'link'),
133
+ }),
134
+ deepMix({}, DEFAULT_NODE_OPTIONS, {
135
+ data: nodeData,
136
+ encode: { ...nodeEncode, color },
137
+ scale,
138
+ style: subObject(style, 'node'),
139
+ coordinate: {
140
+ type: 'polar',
141
+ // Leave enough rendering space for the label.
142
+ outerRadius: (minimumLen - 20) / minimumLen,
143
+ startAngle: -Math.PI * 2,
144
+ endAngle: 0,
145
+ },
146
+ labels: [
147
+ {
148
+ ...DEFAULT_LABEL_OPTIONS,
149
+ text,
150
+ ...labelStyle,
151
+ },
152
+ ...nodeLabels,
153
+ ],
154
+ tooltip: nodeTooltip,
155
+ animate: maybeAnimation(animate, 'node'),
156
+ axis: false,
157
+ }),
158
+ ] as MarkOptions[];
159
+ };
160
+
161
+ Chord.props = {};
package/src/mark/index.ts CHANGED
@@ -17,6 +17,7 @@ export { Range } from './range';
17
17
  export { RangeX } from './rangeX';
18
18
  export { RangeY } from './rangeY';
19
19
  export { Sankey } from './sankey';
20
+ export { Chord } from './chord';
20
21
  export { Path } from './path';
21
22
  export { Treemap } from './treemap';
22
23
  export { Pack } from './pack';
@@ -49,6 +50,7 @@ export type { RangeOptions } from './range';
49
50
  export type { RangeXOptions } from './rangeX';
50
51
  export type { RangeYOptions } from './rangeY';
51
52
  export type { SankeyOptions } from './sankey';
53
+ export type { ChordOptions } from './chord';
52
54
  export type { TreemapOptions } from './treemap';
53
55
  export type { PackOptions } from './pack';
54
56
  export type { ShapeOptions } from './shape';
@@ -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
  });
@@ -369,22 +374,43 @@ function applyTranslate(selection: Selection) {
369
374
 
370
375
  function createUpdateView(
371
376
  selection: Selection,
377
+ options: G2ViewTree,
372
378
  library: G2Library,
373
379
  context: G2Context,
374
380
  ): G2ViewInstance['update'] {
375
- return async (newOptions) => {
381
+ const [, createInteraction] = useLibrary<
382
+ G2InteractionOptions,
383
+ InteractionComponent,
384
+ Interaction
385
+ >('interaction', library);
386
+
387
+ // Filter interaction need to reapply when update.
388
+ const interactions = inferInteraction(options);
389
+ const updates = interactions
390
+ .map((d) => [d[0], createInteraction(d[0])] as const)
391
+ .filter((d) => d[1].props && d[1].props.reapplyWhenUpdate)
392
+ .map((d) => d[0]);
393
+
394
+ return async (newOptions, source) => {
376
395
  const transitions = [];
377
396
  const [newView, newChildren] = await initializeView(newOptions, library);
378
397
  plotView(newView, selection, transitions, library, context);
379
- updateTooltip(selection, newOptions, newView, library, context);
398
+
399
+ // Update interaction need to reapply when update.
400
+ for (const name of updates.filter((d) => d !== source)) {
401
+ updateInteraction(name, selection, newOptions, newView, library, context);
402
+ }
403
+
380
404
  for (const child of newChildren) {
381
405
  plot(child, selection, library, context);
382
406
  }
407
+
383
408
  return { options: newOptions, view: newView };
384
409
  };
385
410
  }
386
411
 
387
- function updateTooltip(
412
+ function updateInteraction(
413
+ name: string,
388
414
  selection: Selection,
389
415
  options: G2ViewTree,
390
416
  view: G2ViewDescriptor,
@@ -397,25 +423,25 @@ function updateTooltip(
397
423
  Interaction
398
424
  >('interaction', library);
399
425
 
400
- // Instances for tooltip.
426
+ // Instances for interaction.
401
427
  const container = selection.node();
402
428
  const nameInteraction = container['nameInteraction'];
403
- const tooltipOptions = inferInteraction(options).find(
404
- ([d]) => d === 'tooltip',
429
+ const interactionOptions = inferInteraction(options).find(
430
+ ([d]) => d === name,
405
431
  );
406
432
 
407
- // Destroy older tooltip.
408
- const tooltip = nameInteraction.get('tooltip');
409
- if (!tooltip) return;
410
- tooltip.destroy?.();
433
+ // Destroy older interaction.
434
+ const interaction = nameInteraction.get(name);
435
+ if (!interaction) return;
436
+ interaction.destroy?.();
411
437
 
412
- if (!tooltipOptions[1]) return;
438
+ if (!interactionOptions[1]) return;
413
439
 
414
- // Apply new tooltip interaction.
415
- const applyTooltip = useThemeInteraction(
440
+ // Apply new interaction.
441
+ const applyInteraction = useThemeInteraction(
416
442
  view,
417
- 'tooltip',
418
- tooltipOptions[1] as any,
443
+ name,
444
+ interactionOptions[1] as any,
419
445
  useInteraction,
420
446
  );
421
447
  const target = {
@@ -424,8 +450,8 @@ function updateTooltip(
424
450
  container: selection.node(),
425
451
  update: (options) => Promise.resolve(options),
426
452
  };
427
- const destroy = applyTooltip(target, [], context.emitter);
428
- nameInteraction.set('tooltip', { destroy });
453
+ const destroy = applyInteraction(target, [], context.emitter);
454
+ nameInteraction.set(name, { destroy });
429
455
  }
430
456
 
431
457
  async function initializeView(
@@ -1600,7 +1626,7 @@ function inferInteraction(
1600
1626
  scrollbarFilter: true,
1601
1627
  };
1602
1628
  const { interaction = {} } = view;
1603
- return Object.entries(deepMix(defaults, interaction));
1629
+ return Object.entries(deepMix(defaults, interaction)).reverse();
1604
1630
  }
1605
1631
 
1606
1632
  async function applyTransform<T extends G2ViewTree>(
@@ -174,22 +174,17 @@ export function assignScale(
174
174
  ): Record<string, Scale> {
175
175
  const keys = Object.keys(target);
176
176
  for (const scale of Object.values(source)) {
177
- const { name, key } = scale.getOptions();
178
- if (typeof key === 'string') {
179
- if (!(key in target)) target[key] = scale;
180
- } else {
181
- // For scale.key = Symbol('independent')
182
- if (!(name in target)) target[name] = scale;
183
- else {
184
- const I = keys
185
- .filter((d) => d.startsWith(name))
186
- // Reg is for extract `1` from `x1`;
187
- .map((d) => +(d.replace(name, '') || 0));
188
- const index = max(I) + 1;
189
- const newKey = `${name}${index}`;
190
- target[newKey] = scale;
191
- scale.getOptions().key = newKey;
192
- }
177
+ const { name } = scale.getOptions();
178
+ if (!(name in target)) target[name] = scale;
179
+ else {
180
+ const I = keys
181
+ .filter((d) => d.startsWith(name))
182
+ // Reg is for extract `1` from `x1`;
183
+ .map((d) => +(d.replace(name, '') || 0));
184
+ const index = max(I) + 1;
185
+ const newKey = `${name}${index}`;
186
+ target[newKey] = scale;
187
+ scale.getOptions().key = newKey;
193
188
  }
194
189
  }
195
190
  return target;
@@ -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 = {
@@ -89,8 +89,12 @@ export const Curve: SC<CurveOptions> = (options, context) => {
89
89
  seriesX: sx,
90
90
  seriesY: sy,
91
91
  } = value;
92
+ const tpShape = isTranspose(coordinate);
92
93
  const transform = getTransform(coordinate, value);
93
- const fill = gradient && sc ? computeGradient(sc, sx, sy, gradient) : color;
94
+ const fill =
95
+ gradient && sc
96
+ ? computeGradient(sc, sx, sy, gradient, undefined, tpShape)
97
+ : color;
94
98
 
95
99
  const finalStyle = {
96
100
  ...defaults,
@@ -119,7 +123,7 @@ export const Curve: SC<CurveOptions> = (options, context) => {
119
123
  const areaPath = (points) => {
120
124
  const Y1 = points.slice(0, points.length / 2);
121
125
  const Y0 = points.slice(points.length / 2);
122
- return isTranspose(coordinate)
126
+ return tpShape
123
127
  ? area()
124
128
  .y((_, idx) => Y1[idx][1])
125
129
  .x1((_, idx) => Y1[idx][0])
@@ -1,6 +1,6 @@
1
1
  import { line, lineRadial, CurveFactory, CurveFactoryLineOnly } from 'd3-shape';
2
2
  import { Vector2 } from '@antv/coord';
3
- import { isPolar } from '../../utils/coordinate';
3
+ import { isPolar, isTranspose } from '../../utils/coordinate';
4
4
  import { select } from '../../utils/selection';
5
5
  import { ShapeComponent as SC } from '../../runtime';
6
6
  import { applyStyle, computeGradient, getTransform } from '../utils';
@@ -89,11 +89,14 @@ export const Curve: SC<CurveOptions> = (options, context) => {
89
89
  seriesX: sx,
90
90
  seriesY: sy,
91
91
  } = value;
92
+
93
+ const transform = getTransform(coordinate, value);
94
+ const tpShape = isTranspose(coordinate);
92
95
  const stroke =
93
96
  gradient && sc
94
- ? computeGradient(sc, sx, sy, gradient, gradientColor)
97
+ ? computeGradient(sc, sx, sy, gradient, gradientColor, tpShape)
95
98
  : color;
96
- const transform = getTransform(coordinate, value);
99
+
97
100
  const finalStyle = {
98
101
  ...rest,
99
102
  ...(stroke && { stroke }),