@antv/g2 5.0.0-beta.11 → 5.0.0-beta.12
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.
- package/dist/g2-lite.min.js +3 -3
- package/dist/g2.min.js +3 -3
- package/esm/api/chart.d.ts +2 -1
- package/esm/api/chart.js +2 -2
- package/esm/api/chart.js.map +1 -1
- package/esm/api/composition/base.d.ts +1 -1
- package/esm/api/composition/base.js +6 -17
- package/esm/api/composition/base.js.map +1 -1
- package/esm/api/composition/facetCircle.d.ts +2 -2
- package/esm/api/composition/facetCircle.js +2 -2
- package/esm/api/composition/facetCircle.js.map +1 -1
- package/esm/api/composition/facetRect.d.ts +2 -2
- package/esm/api/composition/facetRect.js +2 -2
- package/esm/api/composition/facetRect.js.map +1 -1
- package/esm/api/composition/geoPath.d.ts +2 -2
- package/esm/api/composition/geoPath.js +2 -2
- package/esm/api/composition/geoPath.js.map +1 -1
- package/esm/api/composition/geoView.d.ts +2 -2
- package/esm/api/composition/geoView.js +2 -2
- package/esm/api/composition/geoView.js.map +1 -1
- package/esm/api/composition/index.d.ts +2 -2
- package/esm/api/composition/index.js +2 -2
- package/esm/api/composition/index.js.map +1 -1
- package/esm/api/composition/repeatMatrix.d.ts +2 -2
- package/esm/api/composition/repeatMatrix.js +2 -2
- package/esm/api/composition/repeatMatrix.js.map +1 -1
- package/esm/api/composition/spaceFlex.d.ts +2 -2
- package/esm/api/composition/spaceFlex.js +2 -2
- package/esm/api/composition/spaceFlex.js.map +1 -1
- package/esm/api/composition/spaceLayer.d.ts +2 -2
- package/esm/api/composition/spaceLayer.js +2 -2
- package/esm/api/composition/spaceLayer.js.map +1 -1
- package/esm/api/composition/timingKeyframe.d.ts +2 -2
- package/esm/api/composition/timingKeyframe.js +2 -2
- package/esm/api/composition/timingKeyframe.js.map +1 -1
- package/esm/api/composition/view.d.ts +2 -2
- package/esm/api/composition/view.js +2 -2
- package/esm/api/composition/view.js.map +1 -1
- package/esm/api/index.d.ts +2 -0
- package/esm/api/index.js +2 -0
- package/esm/api/index.js.map +1 -1
- package/esm/api/mark/base.d.ts +1 -1
- package/esm/api/mark/base.js +7 -7
- package/esm/api/mark/base.js.map +1 -1
- package/esm/api/mark/index.d.ts +1 -0
- package/esm/api/mark/index.js +1 -0
- package/esm/api/mark/index.js.map +1 -1
- package/esm/api/mark/mark.d.ts +27 -27
- package/esm/api/mark/mark.js +28 -27
- package/esm/api/mark/mark.js.map +1 -1
- package/esm/api/mark/types.d.ts +1 -0
- package/esm/api/node.d.ts +1 -1
- package/esm/api/node.js +1 -1
- package/esm/api/node.js.map +1 -1
- package/esm/api/props.d.ts +1 -1
- package/esm/api/props.js +20 -0
- package/esm/api/props.js.map +1 -1
- package/esm/composition/timingKeyframe.js +13 -7
- package/esm/composition/timingKeyframe.js.map +1 -1
- package/esm/index.d.ts +1 -1
- package/esm/index.js +1 -1
- package/esm/index.js.map +1 -1
- package/esm/interaction/builtin/tooltip.d.ts +10 -2
- package/esm/interaction/index.d.ts +1 -0
- package/esm/interaction/index.js +1 -0
- package/esm/interaction/index.js.map +1 -1
- package/esm/interaction/native/event.d.ts +1 -0
- package/esm/interaction/native/event.js +42 -0
- package/esm/interaction/native/event.js.map +1 -0
- package/esm/interaction/native/tooltip.d.ts +2 -3
- package/esm/interaction/native/tooltip.js +68 -73
- package/esm/interaction/native/tooltip.js.map +1 -1
- package/esm/mark/utils.js +1 -5
- package/esm/mark/utils.js.map +1 -1
- package/esm/runtime/mark.js +5 -3
- package/esm/runtime/mark.js.map +1 -1
- package/esm/runtime/plot.js +33 -16
- package/esm/runtime/plot.js.map +1 -1
- package/esm/runtime/transform.d.ts +5 -0
- package/esm/runtime/transform.js +62 -4
- package/esm/runtime/transform.js.map +1 -1
- package/esm/runtime/types/common.d.ts +1 -0
- package/esm/runtime/types/component.d.ts +2 -1
- package/esm/runtime/types/options.d.ts +6 -1
- package/esm/spec/geometry.d.ts +33 -17
- package/esm/spec/interaction.d.ts +6 -1
- package/esm/stdlib/index.js +2 -2
- package/esm/stdlib/index.js.map +1 -1
- package/esm/transform/groupN.js +2 -2
- package/esm/transform/groupN.js.map +1 -1
- package/esm/transform/maybeTitle.js +13 -3
- package/esm/transform/maybeTitle.js.map +1 -1
- package/esm/transform/maybeTooltip.js +20 -20
- package/esm/transform/maybeTooltip.js.map +1 -1
- package/esm/transform/maybeZeroX.js +2 -2
- package/esm/transform/maybeZeroX.js.map +1 -1
- package/esm/transform/maybeZeroY.js +2 -2
- package/esm/transform/maybeZeroY.js.map +1 -1
- package/esm/transform/maybeZeroY1.js +2 -2
- package/esm/transform/maybeZeroY1.js.map +1 -1
- package/esm/transform/utils/helper.d.ts +12 -0
- package/esm/transform/utils/helper.js +8 -0
- package/esm/transform/utils/helper.js.map +1 -1
- package/esm/utils/helper.js +4 -1
- package/esm/utils/helper.js.map +1 -1
- package/lib/api/chart.d.ts +2 -1
- package/lib/api/chart.js +2 -2
- package/lib/api/chart.js.map +1 -1
- package/lib/api/composition/base.d.ts +1 -1
- package/lib/api/composition/base.js +8 -18
- package/lib/api/composition/base.js.map +1 -1
- package/lib/api/composition/facetCircle.d.ts +2 -2
- package/lib/api/composition/facetCircle.js +1 -1
- package/lib/api/composition/facetCircle.js.map +1 -1
- package/lib/api/composition/facetRect.d.ts +2 -2
- package/lib/api/composition/facetRect.js +1 -1
- package/lib/api/composition/facetRect.js.map +1 -1
- package/lib/api/composition/geoPath.d.ts +2 -2
- package/lib/api/composition/geoPath.js +1 -1
- package/lib/api/composition/geoPath.js.map +1 -1
- package/lib/api/composition/geoView.d.ts +2 -2
- package/lib/api/composition/geoView.js +1 -1
- package/lib/api/composition/geoView.js.map +1 -1
- package/lib/api/composition/index.d.ts +2 -2
- package/lib/api/composition/index.js +2 -2
- package/lib/api/composition/index.js.map +1 -1
- package/lib/api/composition/repeatMatrix.d.ts +2 -2
- package/lib/api/composition/repeatMatrix.js +1 -1
- package/lib/api/composition/repeatMatrix.js.map +1 -1
- package/lib/api/composition/spaceFlex.d.ts +2 -2
- package/lib/api/composition/spaceFlex.js +1 -1
- package/lib/api/composition/spaceFlex.js.map +1 -1
- package/lib/api/composition/spaceLayer.d.ts +2 -2
- package/lib/api/composition/spaceLayer.js +1 -1
- package/lib/api/composition/spaceLayer.js.map +1 -1
- package/lib/api/composition/timingKeyframe.d.ts +2 -2
- package/lib/api/composition/timingKeyframe.js +1 -1
- package/lib/api/composition/timingKeyframe.js.map +1 -1
- package/lib/api/composition/view.d.ts +2 -2
- package/lib/api/composition/view.js +1 -1
- package/lib/api/composition/view.js.map +1 -1
- package/lib/api/index.d.ts +2 -0
- package/lib/api/index.js +5 -1
- package/lib/api/index.js.map +1 -1
- package/lib/api/mark/base.d.ts +1 -1
- package/lib/api/mark/base.js +9 -9
- package/lib/api/mark/base.js.map +1 -1
- package/lib/api/mark/index.d.ts +1 -0
- package/lib/api/mark/index.js +3 -1
- package/lib/api/mark/index.js.map +1 -1
- package/lib/api/mark/mark.d.ts +27 -27
- package/lib/api/mark/mark.js +27 -26
- package/lib/api/mark/mark.js.map +1 -1
- package/lib/api/mark/types.d.ts +1 -0
- package/lib/api/node.d.ts +1 -1
- package/lib/api/node.js +1 -1
- package/lib/api/node.js.map +1 -1
- package/lib/api/props.d.ts +1 -1
- package/lib/api/props.js +20 -0
- package/lib/api/props.js.map +1 -1
- package/lib/composition/timingKeyframe.js +13 -7
- package/lib/composition/timingKeyframe.js.map +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.js +3 -1
- package/lib/index.js.map +1 -1
- package/lib/interaction/builtin/tooltip.d.ts +10 -2
- package/lib/interaction/index.d.ts +1 -0
- package/lib/interaction/index.js +3 -1
- package/lib/interaction/index.js.map +1 -1
- package/lib/interaction/native/event.d.ts +1 -0
- package/lib/interaction/native/event.js +46 -0
- package/lib/interaction/native/event.js.map +1 -0
- package/lib/interaction/native/tooltip.d.ts +2 -3
- package/lib/interaction/native/tooltip.js +67 -72
- package/lib/interaction/native/tooltip.js.map +1 -1
- package/lib/mark/utils.js +1 -5
- package/lib/mark/utils.js.map +1 -1
- package/lib/runtime/mark.js +4 -2
- package/lib/runtime/mark.js.map +1 -1
- package/lib/runtime/plot.js +33 -16
- package/lib/runtime/plot.js.map +1 -1
- package/lib/runtime/transform.d.ts +5 -0
- package/lib/runtime/transform.js +64 -4
- package/lib/runtime/transform.js.map +1 -1
- package/lib/runtime/types/common.d.ts +1 -0
- package/lib/runtime/types/component.d.ts +2 -1
- package/lib/runtime/types/options.d.ts +6 -1
- package/lib/spec/geometry.d.ts +33 -17
- package/lib/spec/interaction.d.ts +6 -1
- package/lib/stdlib/index.js +1 -1
- package/lib/stdlib/index.js.map +1 -1
- package/lib/transform/groupN.js +1 -1
- package/lib/transform/groupN.js.map +1 -1
- package/lib/transform/maybeTitle.js +12 -2
- package/lib/transform/maybeTitle.js.map +1 -1
- package/lib/transform/maybeTooltip.js +20 -20
- package/lib/transform/maybeTooltip.js.map +1 -1
- package/lib/transform/maybeZeroX.js +1 -1
- package/lib/transform/maybeZeroX.js.map +1 -1
- package/lib/transform/maybeZeroY.js +1 -1
- package/lib/transform/maybeZeroY.js.map +1 -1
- package/lib/transform/maybeZeroY1.js +1 -1
- package/lib/transform/maybeZeroY1.js.map +1 -1
- package/lib/transform/utils/helper.d.ts +12 -0
- package/lib/transform/utils/helper.js +11 -1
- package/lib/transform/utils/helper.js.map +1 -1
- package/lib/utils/helper.js +4 -1
- package/lib/utils/helper.js.map +1 -1
- package/package.json +1 -1
- package/src/api/chart.ts +2 -2
- package/src/api/composition/base.ts +5 -7
- package/src/api/composition/facetCircle.ts +2 -2
- package/src/api/composition/facetRect.ts +2 -2
- package/src/api/composition/geoPath.ts +2 -2
- package/src/api/composition/geoView.ts +2 -2
- package/src/api/composition/index.ts +2 -2
- package/src/api/composition/repeatMatrix.ts +2 -2
- package/src/api/composition/spaceFlex.ts +2 -2
- package/src/api/composition/spaceLayer.ts +2 -2
- package/src/api/composition/timingKeyframe.ts +2 -2
- package/src/api/composition/view.ts +2 -2
- package/src/api/index.ts +2 -0
- package/src/api/mark/base.ts +7 -7
- package/src/api/mark/index.ts +2 -0
- package/src/api/mark/mark.ts +28 -27
- package/src/api/mark/types.ts +1 -0
- package/src/api/node.ts +1 -1
- package/src/api/props.ts +22 -1
- package/src/composition/timingKeyframe.ts +13 -7
- package/src/index.ts +1 -1
- package/src/interaction/index.ts +1 -0
- package/src/interaction/native/event.ts +44 -0
- package/src/interaction/native/tooltip.ts +66 -92
- package/src/mark/utils.ts +1 -5
- package/src/runtime/mark.ts +6 -2
- package/src/runtime/plot.ts +44 -18
- package/src/runtime/transform.ts +71 -4
- package/src/runtime/types/common.ts +1 -0
- package/src/runtime/types/component.ts +2 -0
- package/src/runtime/types/options.ts +6 -1
- package/src/spec/geometry.ts +38 -30
- package/src/spec/interaction.ts +5 -1
- package/src/stdlib/index.ts +2 -0
- package/src/transform/groupN.ts +2 -2
- package/src/transform/maybeTitle.ts +11 -3
- package/src/transform/maybeTooltip.ts +17 -21
- package/src/transform/maybeZeroX.ts +2 -2
- package/src/transform/maybeZeroY.ts +2 -2
- package/src/transform/maybeZeroY1.ts +2 -2
- package/src/transform/utils/helper.ts +10 -0
- package/src/utils/helper.ts +6 -1
|
@@ -55,7 +55,7 @@ function createTooltip(root, x0, y0) {
|
|
|
55
55
|
return tooltipElement;
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
-
function showTooltip(root, data, x, y) {
|
|
58
|
+
function showTooltip(root, data, x, y, render, event) {
|
|
59
59
|
const { tooltipElement = createTooltip(root, x, y) } = root;
|
|
60
60
|
const { items, title } = data;
|
|
61
61
|
tooltipElement.show();
|
|
@@ -63,6 +63,9 @@ function showTooltip(root, data, x, y) {
|
|
|
63
63
|
tooltipElement.update({
|
|
64
64
|
items,
|
|
65
65
|
title,
|
|
66
|
+
...(render !== undefined && {
|
|
67
|
+
customContent: render(event, { items, title }),
|
|
68
|
+
}),
|
|
66
69
|
});
|
|
67
70
|
root.tooltipElement = tooltipElement;
|
|
68
71
|
}
|
|
@@ -80,39 +83,16 @@ function destroyTooltip(root) {
|
|
|
80
83
|
}
|
|
81
84
|
}
|
|
82
85
|
|
|
83
|
-
function
|
|
84
|
-
return Object.fromEntries(
|
|
85
|
-
Object.entries(obj).filter(([, value]) => defined(value)),
|
|
86
|
-
);
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
function singleItem(element, item, scale) {
|
|
86
|
+
function singleItem(element) {
|
|
90
87
|
const { __data__: datum } = element;
|
|
91
|
-
const { title,
|
|
92
|
-
const
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
const { field: f, title = f } = scale[key].getOptions();
|
|
97
|
-
const {
|
|
98
|
-
field = undefined,
|
|
99
|
-
color = defaultColor,
|
|
100
|
-
name = field || title,
|
|
101
|
-
value,
|
|
102
|
-
...rest
|
|
103
|
-
} = normalizeTooltip(d);
|
|
104
|
-
return {
|
|
105
|
-
...rest,
|
|
106
|
-
color,
|
|
107
|
-
name,
|
|
108
|
-
value,
|
|
109
|
-
...filterDefined(item({ channel: key, value })),
|
|
110
|
-
};
|
|
111
|
-
})
|
|
112
|
-
.filter(({ value }) => value !== undefined);
|
|
88
|
+
const { title, items = [] } = datum;
|
|
89
|
+
const newItems = items.map(({ color = itemColorOf(element), ...item }) => ({
|
|
90
|
+
...item,
|
|
91
|
+
color,
|
|
92
|
+
}));
|
|
113
93
|
return {
|
|
114
94
|
...(title && { title }),
|
|
115
|
-
items,
|
|
95
|
+
items: newItems,
|
|
116
96
|
};
|
|
117
97
|
}
|
|
118
98
|
|
|
@@ -157,39 +137,22 @@ function uniqueTitles(titles) {
|
|
|
157
137
|
|
|
158
138
|
function groupItems(
|
|
159
139
|
elements,
|
|
160
|
-
item,
|
|
161
140
|
scale,
|
|
162
141
|
data = elements.map((d) => d['__data__']),
|
|
163
142
|
) {
|
|
164
143
|
const T = uniqueTitles(data.map((d) => d.title)).filter(defined);
|
|
165
|
-
const
|
|
144
|
+
const newItems = data.flatMap((datum, i) => {
|
|
166
145
|
const element = elements[i];
|
|
167
|
-
const {
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
const {
|
|
174
|
-
field = undefined,
|
|
175
|
-
color = defaultColor,
|
|
176
|
-
name = groupNameOf(scale, datum) || field || title,
|
|
177
|
-
value,
|
|
178
|
-
...rest
|
|
179
|
-
} = normalizeTooltip(d);
|
|
180
|
-
return {
|
|
181
|
-
...rest,
|
|
182
|
-
name,
|
|
183
|
-
color,
|
|
184
|
-
value,
|
|
185
|
-
...filterDefined(item({ channel: key, value })),
|
|
186
|
-
};
|
|
187
|
-
})
|
|
188
|
-
.filter(({ value }) => defined(value));
|
|
146
|
+
const { items = [], title } = datum;
|
|
147
|
+
return items.map(({ color = itemColorOf(element), name, ...item }) => ({
|
|
148
|
+
...item,
|
|
149
|
+
color,
|
|
150
|
+
name: groupNameOf(scale, datum) || name || title,
|
|
151
|
+
}));
|
|
189
152
|
});
|
|
190
153
|
return {
|
|
191
154
|
...(T.length > 0 && { title: T.join(',') }),
|
|
192
|
-
items,
|
|
155
|
+
items: newItems,
|
|
193
156
|
};
|
|
194
157
|
}
|
|
195
158
|
|
|
@@ -265,6 +228,7 @@ export function seriesTooltip(
|
|
|
265
228
|
coordinate,
|
|
266
229
|
crosshairs,
|
|
267
230
|
item,
|
|
231
|
+
render,
|
|
268
232
|
startX = 0,
|
|
269
233
|
startY = 0,
|
|
270
234
|
...rest
|
|
@@ -283,6 +247,12 @@ export function seriesTooltip(
|
|
|
283
247
|
else itemElements.push(element);
|
|
284
248
|
}
|
|
285
249
|
|
|
250
|
+
// Sorted elements from top to bottom visually.
|
|
251
|
+
seriesElements.sort((a, b) => {
|
|
252
|
+
const minY = (d) => d.getBounds().min[1];
|
|
253
|
+
return minY(a) - minY(b);
|
|
254
|
+
});
|
|
255
|
+
|
|
286
256
|
// Get sortedIndex and X for each series elements
|
|
287
257
|
const elementSortedX = new Map(
|
|
288
258
|
seriesElements.map((element) => {
|
|
@@ -310,32 +280,32 @@ export function seriesTooltip(
|
|
|
310
280
|
|
|
311
281
|
const indexByFocus = (focus, I, X) => {
|
|
312
282
|
const [normalizedX] = coordinate.invert(focus);
|
|
283
|
+
const finalX = normalizedX - offsetX;
|
|
284
|
+
const [minX, maxX] = sort([X[0], X[X.length - 1]]);
|
|
285
|
+
// Skip x out of range.
|
|
286
|
+
if (finalX < minX || finalX > maxX) return null;
|
|
313
287
|
const search = bisector((i) => X[+i]).center;
|
|
314
|
-
const i = search(I,
|
|
288
|
+
const i = search(I, finalX);
|
|
315
289
|
return I[i];
|
|
316
290
|
};
|
|
317
291
|
|
|
318
|
-
const
|
|
319
|
-
const
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
let right = center;
|
|
329
|
-
while (left - 1 > 0 && X[I[left - 1]] == X[I[center]]) left--;
|
|
330
|
-
while (right + 1 < len && X[I[right + 1]] === X[I[center]]) right++;
|
|
331
|
-
return range(left, right + 1).map((i) => I[i]);
|
|
292
|
+
const elementsByFocus = (focus, elements) => {
|
|
293
|
+
const x = focus[0];
|
|
294
|
+
const extent = (d) => {
|
|
295
|
+
const { min, max } = d.getLocalBounds();
|
|
296
|
+
return sort([min[0], max[0]]);
|
|
297
|
+
};
|
|
298
|
+
return elements.filter((element) => {
|
|
299
|
+
const [min, max] = extent(element);
|
|
300
|
+
return x >= min && x <= max;
|
|
301
|
+
});
|
|
332
302
|
};
|
|
333
303
|
|
|
334
304
|
const seriesData = (element, index) => {
|
|
335
305
|
const { __data__: data } = element;
|
|
336
306
|
return Object.fromEntries(
|
|
337
307
|
Object.entries(data)
|
|
338
|
-
.filter(([key]) => key.startsWith('series'))
|
|
308
|
+
.filter(([key]) => key.startsWith('series') && key !== 'series')
|
|
339
309
|
.map(([key, V]) => {
|
|
340
310
|
const d = V[index];
|
|
341
311
|
return [lowerFirst(key.replace('series', '')), d];
|
|
@@ -353,32 +323,38 @@ export function seriesTooltip(
|
|
|
353
323
|
const focus = [mouse[0] - startX, mouse[1] - startY];
|
|
354
324
|
if (!focus) return;
|
|
355
325
|
// Get selected item element.
|
|
356
|
-
const
|
|
357
|
-
const selectedItems = selectedItemIndices.map((i) => itemElements[i]);
|
|
326
|
+
const selectedItems = elementsByFocus(focus, itemElements);
|
|
358
327
|
|
|
359
328
|
// Get selected data item from both series element and item element.
|
|
360
|
-
const
|
|
329
|
+
const selectedSeriesElements = [];
|
|
330
|
+
const selectedSeriesData = [];
|
|
331
|
+
for (const element of seriesElements) {
|
|
361
332
|
const [sortedIndex, X] = elementSortedX.get(element);
|
|
362
333
|
const index = indexByFocus(focus, sortedIndex, X);
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
334
|
+
if (index !== null) {
|
|
335
|
+
selectedSeriesElements.push(element);
|
|
336
|
+
const d = seriesData(element, index);
|
|
337
|
+
const { x, y } = d;
|
|
338
|
+
const p = coordinate.map([x + offsetX, y]);
|
|
339
|
+
selectedSeriesData.push([d, p] as const);
|
|
340
|
+
}
|
|
341
|
+
}
|
|
367
342
|
const selectedData = [
|
|
368
343
|
...selectedSeriesData.map((d) => d[0]),
|
|
369
344
|
...selectedItems.map((d) => d.__data__),
|
|
370
345
|
];
|
|
371
346
|
|
|
372
347
|
// Get the displayed tooltip data.
|
|
373
|
-
const selectedElements = [...
|
|
374
|
-
const tooltipData = groupItems(
|
|
375
|
-
selectedElements,
|
|
376
|
-
item,
|
|
377
|
-
scale,
|
|
378
|
-
selectedData,
|
|
379
|
-
);
|
|
348
|
+
const selectedElements = [...selectedSeriesElements, ...selectedItems];
|
|
349
|
+
const tooltipData = groupItems(selectedElements, scale, selectedData);
|
|
380
350
|
|
|
381
|
-
|
|
351
|
+
// Hide tooltip with no selected tooltip.
|
|
352
|
+
if (selectedElements.length === 0) {
|
|
353
|
+
hide();
|
|
354
|
+
return;
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
showTooltip(root, tooltipData, mouse[0] + x, mouse[1] + y, render, event);
|
|
382
358
|
if (crosshairs) {
|
|
383
359
|
const points = selectedSeriesData.map((d) => d[1]);
|
|
384
360
|
updateRuleY(root, points, { ...ruleStyle, height, startX, startY });
|
|
@@ -414,11 +390,11 @@ export function tooltip(
|
|
|
414
390
|
{
|
|
415
391
|
elements: elementsof,
|
|
416
392
|
scale,
|
|
393
|
+
render,
|
|
417
394
|
wait = 50,
|
|
418
395
|
leading = true,
|
|
419
396
|
trailing = false,
|
|
420
397
|
groupKey = (d) => d, // group elements by specified key
|
|
421
|
-
item,
|
|
422
398
|
}: Record<string, any>,
|
|
423
399
|
) {
|
|
424
400
|
const elements = elementsof(root);
|
|
@@ -432,11 +408,9 @@ export function tooltip(
|
|
|
432
408
|
const k = groupKey(element);
|
|
433
409
|
const group = keyGroup.get(k);
|
|
434
410
|
const data =
|
|
435
|
-
group.length === 1
|
|
436
|
-
? singleItem(group[0], item, scale)
|
|
437
|
-
: groupItems(group, item, scale);
|
|
411
|
+
group.length === 1 ? singleItem(group[0]) : groupItems(group, scale);
|
|
438
412
|
const { offsetX, offsetY } = event;
|
|
439
|
-
showTooltip(root, data, offsetX, offsetY);
|
|
413
|
+
showTooltip(root, data, offsetX, offsetY, render, event);
|
|
440
414
|
},
|
|
441
415
|
wait,
|
|
442
416
|
{ leading, trailing },
|
package/src/mark/utils.ts
CHANGED
|
@@ -26,11 +26,7 @@ export function baseChannels(options: ChannelOptions = {}): Channel[] {
|
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
export function baseGeometryChannels(options: ChannelOptions = {}): Channel[] {
|
|
29
|
-
return [
|
|
30
|
-
...baseChannels(options),
|
|
31
|
-
{ name: 'title', scale: 'identity' },
|
|
32
|
-
{ name: 'tooltip', scale: 'identity', independent: true },
|
|
33
|
-
];
|
|
29
|
+
return [...baseChannels(options), { name: 'title', scale: 'identity' }];
|
|
34
30
|
}
|
|
35
31
|
|
|
36
32
|
export function tooltip2d() {
|
package/src/runtime/mark.ts
CHANGED
|
@@ -26,6 +26,8 @@ import {
|
|
|
26
26
|
maybeVisualChannel,
|
|
27
27
|
addGuideToScale,
|
|
28
28
|
maybeNonAnimate,
|
|
29
|
+
normalizeTooltip,
|
|
30
|
+
extractTooltip,
|
|
29
31
|
} from './transform';
|
|
30
32
|
|
|
31
33
|
export async function initializeMark(
|
|
@@ -41,7 +43,7 @@ export async function initializeMark(
|
|
|
41
43
|
context,
|
|
42
44
|
);
|
|
43
45
|
|
|
44
|
-
const { encode, scale, data } = transformedMark;
|
|
46
|
+
const { encode, scale, data, tooltip } = transformedMark;
|
|
45
47
|
|
|
46
48
|
// Skip mark with non-tabular data. Do not skip empty
|
|
47
49
|
// data, they are useful for facet to display axes.
|
|
@@ -109,7 +111,7 @@ export async function initializeMark(
|
|
|
109
111
|
});
|
|
110
112
|
});
|
|
111
113
|
|
|
112
|
-
return [transformedMark, { ...partialProps, index: I, channels }];
|
|
114
|
+
return [transformedMark, { ...partialProps, index: I, channels, tooltip }];
|
|
113
115
|
}
|
|
114
116
|
|
|
115
117
|
export function createColumnOf(library: G2Library): ColumnOf {
|
|
@@ -152,9 +154,11 @@ async function applyMarkTransform(
|
|
|
152
154
|
maybeArrayField,
|
|
153
155
|
maybeNonAnimate,
|
|
154
156
|
addGuideToScale,
|
|
157
|
+
normalizeTooltip,
|
|
155
158
|
...preInference.map(useTransform),
|
|
156
159
|
...transform.map(useTransform),
|
|
157
160
|
...postInference.map(useTransform),
|
|
161
|
+
extractTooltip,
|
|
158
162
|
];
|
|
159
163
|
let index = [];
|
|
160
164
|
let transformedMark = mark;
|
package/src/runtime/plot.ts
CHANGED
|
@@ -231,7 +231,7 @@ export async function plot<T extends G2ViewTree>(
|
|
|
231
231
|
// Apply interactions.
|
|
232
232
|
for (const option of inferInteraction(options)) {
|
|
233
233
|
const interaction = useInteraction(option);
|
|
234
|
-
const destroy = interaction(target, enterViewInstances);
|
|
234
|
+
const destroy = interaction(target, enterViewInstances, context.emitter);
|
|
235
235
|
nameInteraction.set(option.type, { destroy });
|
|
236
236
|
}
|
|
237
237
|
}
|
|
@@ -248,7 +248,7 @@ export async function plot<T extends G2ViewTree>(
|
|
|
248
248
|
|
|
249
249
|
// Apply new interaction.
|
|
250
250
|
const interaction = useInteraction(option);
|
|
251
|
-
const destroy = interaction(target, updateViewInstances);
|
|
251
|
+
const destroy = interaction(target, updateViewInstances, context.emitter);
|
|
252
252
|
nameInteraction.set(options.type, { destroy });
|
|
253
253
|
}
|
|
254
254
|
}
|
|
@@ -317,7 +317,14 @@ async function initializeView(
|
|
|
317
317
|
library: G2Library,
|
|
318
318
|
): Promise<[G2ViewDescriptor, G2ViewTree[]]> {
|
|
319
319
|
const flattenOptions = await transformMarks(options, library);
|
|
320
|
+
|
|
320
321
|
const mergedOptions = bubbleOptions(flattenOptions);
|
|
322
|
+
// @todo Remove this.
|
|
323
|
+
// !!! NOTE: Mute original view options.
|
|
324
|
+
// Update interaction and coordinate for this view.
|
|
325
|
+
options.interaction = mergedOptions.interaction;
|
|
326
|
+
options.coordinate = mergedOptions.coordinate;
|
|
327
|
+
|
|
321
328
|
const transformedOptions = coordinate2Transform(mergedOptions, library);
|
|
322
329
|
const state = await initializeMarks(transformedOptions, library);
|
|
323
330
|
return initializeState(state, transformedOptions, library);
|
|
@@ -376,7 +383,7 @@ async function transformMarks(
|
|
|
376
383
|
useMark as (options: G2MarkOptions) => CompositeMark
|
|
377
384
|
)(mark)(options);
|
|
378
385
|
const M = Array.isArray(marks) ? marks : [marks];
|
|
379
|
-
discovered.unshift(...M.map((d, i) => ({ key: `${key}-${i}
|
|
386
|
+
discovered.unshift(...M.map((d, i) => ({ ...d, key: `${key}-${i}` })));
|
|
380
387
|
}
|
|
381
388
|
}
|
|
382
389
|
|
|
@@ -520,7 +527,7 @@ function initializeState(
|
|
|
520
527
|
modifier,
|
|
521
528
|
key: markKey,
|
|
522
529
|
} = mark;
|
|
523
|
-
const { index, channels } = state;
|
|
530
|
+
const { index, channels, tooltip } = state;
|
|
524
531
|
const scale = Object.fromEntries(
|
|
525
532
|
channels.map(({ name, scale }) => [name, scale]),
|
|
526
533
|
);
|
|
@@ -541,6 +548,8 @@ function initializeState(
|
|
|
541
548
|
);
|
|
542
549
|
const count = dataDomain || I.length;
|
|
543
550
|
const T = modifier ? modifier(P, count, layout) : [];
|
|
551
|
+
const titleOf = (i) => tooltip.title?.[i]?.value;
|
|
552
|
+
const itemsOf = (i) => tooltip.items.map((V) => V[i]);
|
|
544
553
|
const visualData: Record<string, any>[] = I.map((d, i) => {
|
|
545
554
|
const datum = {
|
|
546
555
|
points: P[i],
|
|
@@ -548,12 +557,20 @@ function initializeState(
|
|
|
548
557
|
index: d,
|
|
549
558
|
markKey,
|
|
550
559
|
viewKey: key,
|
|
560
|
+
...(tooltip && {
|
|
561
|
+
title: titleOf(d),
|
|
562
|
+
items: itemsOf(d),
|
|
563
|
+
}),
|
|
551
564
|
};
|
|
552
565
|
for (const [k, V] of Object.entries(value)) {
|
|
553
566
|
datum[k] = V[d];
|
|
554
567
|
if (S) datum[`series${upperFirst(k)}`] = S[i].map((i) => V[i]);
|
|
555
568
|
}
|
|
556
569
|
if (S) datum['seriesIndex'] = S[i];
|
|
570
|
+
if (S && tooltip) {
|
|
571
|
+
datum['seriesItems'] = S[i].map((si) => itemsOf(si));
|
|
572
|
+
datum['seriesTitle'] = S[i].map((si) => titleOf(si));
|
|
573
|
+
}
|
|
557
574
|
return datum;
|
|
558
575
|
});
|
|
559
576
|
state.data = visualData;
|
|
@@ -726,12 +743,14 @@ async function plotView(
|
|
|
726
743
|
// Render marks with corresponding data.
|
|
727
744
|
for (const [mark, state] of markState.entries()) {
|
|
728
745
|
const { data } = state;
|
|
729
|
-
const { key, class: cls } = mark;
|
|
746
|
+
const { key, class: cls, type } = mark;
|
|
730
747
|
const shapeFunction = createMarkShapeFunction(mark, state, view, library);
|
|
731
748
|
const enterFunction = createEnterFunction(mark, state, view, library);
|
|
732
749
|
const updateFunction = createUpdateFunction(mark, state, view, library);
|
|
733
750
|
const exitFunction = createExitFunction(mark, state, view, library);
|
|
734
751
|
const facetElements = selectFacetElements(selection, cls, 'element');
|
|
752
|
+
const classNames = [ELEMENT_CLASS_NAME];
|
|
753
|
+
if (typeof type === 'string') classNames.push(type);
|
|
735
754
|
const T = selection
|
|
736
755
|
.select(`#${key}`)
|
|
737
756
|
.selectAll(className(ELEMENT_CLASS_NAME))
|
|
@@ -745,7 +764,7 @@ async function plotView(
|
|
|
745
764
|
(enter) =>
|
|
746
765
|
enter
|
|
747
766
|
.append(shapeFunction)
|
|
748
|
-
.attr('className',
|
|
767
|
+
.attr('className', classNames.join(' '))
|
|
749
768
|
.transition(function (data) {
|
|
750
769
|
return enterFunction(data, [this]);
|
|
751
770
|
}),
|
|
@@ -1041,17 +1060,22 @@ function computeAnimationExtent(markState): [number, number] {
|
|
|
1041
1060
|
for (const [mark, state] of markState) {
|
|
1042
1061
|
const { animate = {} } = mark;
|
|
1043
1062
|
const { data } = state;
|
|
1063
|
+
const { enter = {}, update = {}, exit = {} } = animate;
|
|
1064
|
+
const {
|
|
1065
|
+
type: defaultUpdateType,
|
|
1066
|
+
duration: defaultUpdateDuration = 300,
|
|
1067
|
+
delay: defaultUpdateDelay = 0,
|
|
1068
|
+
} = update;
|
|
1044
1069
|
const {
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
} = animate;
|
|
1070
|
+
type: defaultEnterType,
|
|
1071
|
+
duration: defaultEnterDuration = 300,
|
|
1072
|
+
delay: defaultEnterDelay = 0,
|
|
1073
|
+
} = enter;
|
|
1074
|
+
const {
|
|
1075
|
+
type: defaultExitType,
|
|
1076
|
+
duration: defaultExitDuration = 300,
|
|
1077
|
+
delay: defaultExitDelay = 0,
|
|
1078
|
+
} = exit;
|
|
1055
1079
|
for (const d of data) {
|
|
1056
1080
|
const {
|
|
1057
1081
|
updateType = defaultUpdateType,
|
|
@@ -1192,7 +1216,7 @@ function createAnimationFunction(
|
|
|
1192
1216
|
shapeName(mark, defaultShape),
|
|
1193
1217
|
).props;
|
|
1194
1218
|
const { [type]: defaultEffectTiming = {} } = theme;
|
|
1195
|
-
const animate =
|
|
1219
|
+
const animate = mark.animate?.[type] || {};
|
|
1196
1220
|
return (data, from, to) => {
|
|
1197
1221
|
const {
|
|
1198
1222
|
[`${type}Type`]: animation,
|
|
@@ -1272,7 +1296,9 @@ function inferTheme(theme: G2ThemeOptions = { type: 'light' }): G2ThemeOptions {
|
|
|
1272
1296
|
* @todo Infer builtin tooltips.
|
|
1273
1297
|
*/
|
|
1274
1298
|
function inferInteraction(view: G2View): G2InteractionOptions[] {
|
|
1275
|
-
const defaults = {
|
|
1299
|
+
const defaults = {
|
|
1300
|
+
event: true,
|
|
1301
|
+
};
|
|
1276
1302
|
const { interaction = {} } = view;
|
|
1277
1303
|
return Object.entries(deepMix(defaults, interaction))
|
|
1278
1304
|
.filter((d) => !!d[1])
|
package/src/runtime/transform.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Primitive } from 'd3-array';
|
|
2
2
|
import { deepMix } from '@antv/util';
|
|
3
3
|
import { indexOf, mapObject } from '../utils/array';
|
|
4
|
-
import { composeAsync, defined } from '../utils/helper';
|
|
4
|
+
import { composeAsync, defined, isStrictObject } from '../utils/helper';
|
|
5
5
|
import { useLibrary } from './library';
|
|
6
6
|
import { createColumnOf } from './mark';
|
|
7
7
|
import { Data, DataComponent } from './types/data';
|
|
@@ -105,6 +105,73 @@ export function extractColumns(
|
|
|
105
105
|
return [I, { ...mark, encode: valuedEncode }];
|
|
106
106
|
}
|
|
107
107
|
|
|
108
|
+
/**
|
|
109
|
+
* Normalize mark.tooltip to {title, items}.
|
|
110
|
+
*/
|
|
111
|
+
export function normalizeTooltip(
|
|
112
|
+
I: number[],
|
|
113
|
+
mark: G2Mark,
|
|
114
|
+
context: TransformContext,
|
|
115
|
+
): [number[], G2Mark] {
|
|
116
|
+
const { tooltip = {} } = mark;
|
|
117
|
+
const isFullTooltip = (tooltip) => {
|
|
118
|
+
if (Object.keys(tooltip).length === 0) return true;
|
|
119
|
+
const { title, items } = tooltip;
|
|
120
|
+
return title !== undefined || items !== undefined;
|
|
121
|
+
};
|
|
122
|
+
if (tooltip === null) return [I, mark];
|
|
123
|
+
if (Array.isArray(tooltip)) {
|
|
124
|
+
return [I, { ...mark, tooltip: { items: tooltip } }];
|
|
125
|
+
}
|
|
126
|
+
if (isStrictObject(tooltip) && isFullTooltip(tooltip)) {
|
|
127
|
+
return [I, { ...mark, tooltip }];
|
|
128
|
+
}
|
|
129
|
+
return [I, { ...mark, tooltip: { items: [tooltip] } }];
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
export function extractTooltip(
|
|
133
|
+
I: number[],
|
|
134
|
+
mark: G2Mark,
|
|
135
|
+
context: TransformContext,
|
|
136
|
+
): [number[], G2Mark] {
|
|
137
|
+
const { data, encode, tooltip = {} } = mark;
|
|
138
|
+
if (tooltip === null) return [I, mark];
|
|
139
|
+
const valueOf = (item) => {
|
|
140
|
+
if (!item) return item;
|
|
141
|
+
if (typeof item === 'string') {
|
|
142
|
+
return I.map((i) => ({ name: item, value: data[i][item] }));
|
|
143
|
+
}
|
|
144
|
+
if (isStrictObject(item)) {
|
|
145
|
+
const { field, channel, color, name = field } = item;
|
|
146
|
+
const channelField = channel && encode[channel].field;
|
|
147
|
+
return I.map((i) => ({
|
|
148
|
+
name: name || channelField || channel,
|
|
149
|
+
color,
|
|
150
|
+
value: field
|
|
151
|
+
? data[i][field]
|
|
152
|
+
: channel
|
|
153
|
+
? encode[channel].value[i]
|
|
154
|
+
: null,
|
|
155
|
+
}));
|
|
156
|
+
}
|
|
157
|
+
if (typeof item === 'function') {
|
|
158
|
+
return I.map((i) => {
|
|
159
|
+
const v = item(data[i], i, data, encode);
|
|
160
|
+
if (isStrictObject(v)) return v;
|
|
161
|
+
return { value: v };
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
return item;
|
|
165
|
+
};
|
|
166
|
+
const { title, items = [], ...rest } = tooltip;
|
|
167
|
+
const newTooltip = {
|
|
168
|
+
title: valueOf(title),
|
|
169
|
+
items: items.map(valueOf),
|
|
170
|
+
...rest,
|
|
171
|
+
};
|
|
172
|
+
return [I, { ...mark, tooltip: newTooltip }];
|
|
173
|
+
}
|
|
174
|
+
|
|
108
175
|
export function maybeArrayField(
|
|
109
176
|
I: number[],
|
|
110
177
|
mark: G2Mark,
|
|
@@ -190,9 +257,9 @@ export function maybeNonAnimate(
|
|
|
190
257
|
if (animate || animate === undefined) return [I, mark];
|
|
191
258
|
deepMix(mark, {
|
|
192
259
|
animate: {
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
260
|
+
enter: { type: null },
|
|
261
|
+
exit: { type: null },
|
|
262
|
+
update: { type: null },
|
|
196
263
|
},
|
|
197
264
|
});
|
|
198
265
|
return [I, mark];
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Coordinate, Transformation } from '@antv/coord';
|
|
2
2
|
import { DisplayObject, IAnimation as GAnimation } from '@antv/g';
|
|
3
|
+
import EventEmitter from '@antv/event-emitter';
|
|
3
4
|
import { G2ViewTree } from './options';
|
|
4
5
|
import {
|
|
5
6
|
G2Theme,
|
|
@@ -191,6 +192,7 @@ export type AnimationComponent<O = Record<string, unknown>> = G2BaseComponent<
|
|
|
191
192
|
export type Interaction = (
|
|
192
193
|
target: G2ViewInstance,
|
|
193
194
|
viewInstances: G2ViewInstance[],
|
|
195
|
+
emitter?: EventEmitter,
|
|
194
196
|
) => void;
|
|
195
197
|
export type InteractionComponent<O = Record<string, unknown>> = G2BaseComponent<
|
|
196
198
|
Interaction,
|
|
@@ -106,12 +106,17 @@ export type G2Mark = {
|
|
|
106
106
|
scale?: Record<string, G2ScaleOptions>;
|
|
107
107
|
encode?: Record<string, any | G2EncodeOptions>;
|
|
108
108
|
type?: string | MarkComponent;
|
|
109
|
-
animate?:
|
|
109
|
+
animate?: {
|
|
110
|
+
enter?: Record<string, Primitive>;
|
|
111
|
+
update?: Record<string, Primitive>;
|
|
112
|
+
exit?: Record<string, Primitive>;
|
|
113
|
+
};
|
|
110
114
|
facet?: boolean;
|
|
111
115
|
axis?: boolean | Record<string, any>;
|
|
112
116
|
legend?: boolean | Record<string, any>;
|
|
113
117
|
slider?: Record<string, any>;
|
|
114
118
|
scrollbar?: Record<string, any>;
|
|
119
|
+
tooltip?: any; // @todo
|
|
115
120
|
filter?: (i: number) => boolean;
|
|
116
121
|
children?: G2MarkChildrenCallback;
|
|
117
122
|
dataDomain?: number;
|