@antv/g2 5.0.19 → 5.0.20
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 +13 -855
- package/esm/api/chart.js.map +1 -1
- package/esm/api/extend.d.ts +2 -1
- package/esm/api/extend.js.map +1 -1
- package/esm/api/library.d.ts +1 -0
- package/esm/data/index.d.ts +2 -0
- package/esm/data/index.js +1 -0
- package/esm/data/index.js.map +1 -1
- package/esm/data/log.d.ts +7 -0
- package/esm/data/log.js +11 -0
- package/esm/data/log.js.map +1 -0
- package/esm/interaction/brushFilter.js +18 -16
- package/esm/interaction/brushFilter.js.map +1 -1
- package/esm/interaction/chartIndex.js +25 -22
- package/esm/interaction/chartIndex.js.map +1 -1
- package/esm/interaction/fisheye.js +17 -13
- package/esm/interaction/fisheye.js.map +1 -1
- package/esm/interaction/legendFilter.js +32 -26
- package/esm/interaction/legendFilter.js.map +1 -1
- package/esm/interaction/sliderFilter.js +8 -9
- package/esm/interaction/sliderFilter.js.map +1 -1
- package/esm/interaction/tooltip.d.ts +1 -1
- package/esm/interaction/tooltip.js +39 -4
- package/esm/interaction/tooltip.js.map +1 -1
- package/esm/lib/core.d.ts +1 -0
- package/esm/lib/core.js +2 -1
- package/esm/lib/core.js.map +1 -1
- package/esm/lib/std.d.ts +1 -0
- package/esm/runtime/plot.js +21 -6
- package/esm/runtime/plot.js.map +1 -1
- package/esm/spec/dataTransform.d.ts +3 -2
- package/esm/spec/interaction.d.ts +2 -1
- package/lib/api/chart.d.ts +13 -855
- package/lib/api/chart.js.map +1 -1
- package/lib/api/extend.d.ts +2 -1
- package/lib/api/extend.js.map +1 -1
- package/lib/api/library.d.ts +1 -0
- package/lib/data/index.d.ts +2 -0
- package/lib/data/index.js +3 -1
- package/lib/data/index.js.map +1 -1
- package/lib/data/log.d.ts +7 -0
- package/lib/data/log.js +15 -0
- package/lib/data/log.js.map +1 -0
- package/lib/interaction/brushFilter.js +18 -16
- package/lib/interaction/brushFilter.js.map +1 -1
- package/lib/interaction/chartIndex.js +25 -22
- package/lib/interaction/chartIndex.js.map +1 -1
- package/lib/interaction/fisheye.js +17 -13
- package/lib/interaction/fisheye.js.map +1 -1
- package/lib/interaction/legendFilter.js +32 -26
- package/lib/interaction/legendFilter.js.map +1 -1
- package/lib/interaction/sliderFilter.js +8 -9
- package/lib/interaction/sliderFilter.js.map +1 -1
- package/lib/interaction/tooltip.d.ts +1 -1
- package/lib/interaction/tooltip.js +38 -3
- package/lib/interaction/tooltip.js.map +1 -1
- package/lib/lib/core.d.ts +1 -0
- package/lib/lib/core.js +1 -0
- package/lib/lib/core.js.map +1 -1
- package/lib/lib/std.d.ts +1 -0
- package/lib/runtime/plot.js +21 -6
- package/lib/runtime/plot.js.map +1 -1
- package/lib/spec/dataTransform.d.ts +3 -2
- package/lib/spec/interaction.d.ts +2 -1
- package/package.json +1 -1
- package/src/api/chart.ts +3 -3
- package/src/api/extend.ts +5 -3
- package/src/data/index.ts +2 -0
- package/src/data/log.ts +16 -0
- package/src/interaction/brushFilter.ts +31 -28
- package/src/interaction/chartIndex.ts +26 -23
- package/src/interaction/fisheye.ts +16 -12
- package/src/interaction/legendFilter.ts +45 -40
- package/src/interaction/sliderFilter.ts +15 -16
- package/src/interaction/tooltip.ts +47 -3
- package/src/lib/core.ts +2 -0
- package/src/runtime/plot.ts +22 -7
- package/src/spec/dataTransform.ts +5 -0
- package/src/spec/interaction.ts +3 -1
package/src/data/log.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { DataComponent as DC } from '../runtime';
|
|
2
|
+
import { LogDataTransform } from '../spec';
|
|
3
|
+
|
|
4
|
+
export type LogDataOptions = Omit<LogDataTransform, 'type'>;
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Console.log the data section for dev debugger.
|
|
8
|
+
*/
|
|
9
|
+
export const Log: DC<LogDataOptions> = () => {
|
|
10
|
+
return (data) => {
|
|
11
|
+
console.log('G2 data section:', data);
|
|
12
|
+
return data;
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
Log.props = {};
|
|
@@ -82,7 +82,7 @@ export function brushFilter(
|
|
|
82
82
|
|
|
83
83
|
export function BrushFilter({ hideX = true, hideY = true, ...rest }) {
|
|
84
84
|
return (target, viewInstances, emitter) => {
|
|
85
|
-
const { container, view, options: viewOptions, update } = target;
|
|
85
|
+
const { container, view, options: viewOptions, update, setState } = target;
|
|
86
86
|
const plotArea = selectPlotArea(container);
|
|
87
87
|
const defaultOptions = {
|
|
88
88
|
maskFill: '#777',
|
|
@@ -110,26 +110,35 @@ export function BrushFilter({ hideX = true, hideY = true, ...rest }) {
|
|
|
110
110
|
|
|
111
111
|
// Update the domain of x and y scale to filter data.
|
|
112
112
|
const [domainX, domainY] = selection;
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
113
|
+
|
|
114
|
+
setState('brushFilter', (options) => {
|
|
115
|
+
const { marks } = options;
|
|
116
|
+
const newMarks = marks.map((mark) =>
|
|
117
|
+
deepMix(
|
|
118
|
+
{
|
|
119
|
+
// Hide label to keep smooth transition.
|
|
120
|
+
axis: {
|
|
121
|
+
...(hideX && { x: { transform: [{ type: 'hide' }] } }),
|
|
122
|
+
...(hideY && { y: { transform: [{ type: 'hide' }] } }),
|
|
123
|
+
},
|
|
121
124
|
},
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
125
|
+
mark,
|
|
126
|
+
{
|
|
127
|
+
// Set nice to false to avoid modify domain.
|
|
128
|
+
scale: {
|
|
129
|
+
x: { domain: domainX, nice: false },
|
|
130
|
+
y: { domain: domainY, nice: false },
|
|
131
|
+
},
|
|
129
132
|
},
|
|
130
|
-
|
|
131
|
-
)
|
|
132
|
-
|
|
133
|
+
),
|
|
134
|
+
);
|
|
135
|
+
|
|
136
|
+
return {
|
|
137
|
+
...viewOptions,
|
|
138
|
+
marks: newMarks,
|
|
139
|
+
clip: true, // Clip shapes out of plot area.
|
|
140
|
+
};
|
|
141
|
+
});
|
|
133
142
|
|
|
134
143
|
// Emit event.
|
|
135
144
|
emitter.emit('brush:filter', {
|
|
@@ -137,13 +146,7 @@ export function BrushFilter({ hideX = true, hideY = true, ...rest }) {
|
|
|
137
146
|
data: { selection: [domainX, domainY] },
|
|
138
147
|
});
|
|
139
148
|
|
|
140
|
-
|
|
141
|
-
const newOptions = {
|
|
142
|
-
...viewOptions,
|
|
143
|
-
marks: newMarks,
|
|
144
|
-
clip: true, // Clip shapes out of plot area.
|
|
145
|
-
};
|
|
146
|
-
const newState = await update(newOptions);
|
|
149
|
+
const newState = await update();
|
|
147
150
|
newView = newState.view;
|
|
148
151
|
filtering = false;
|
|
149
152
|
filtered = true;
|
|
@@ -160,10 +163,10 @@ export function BrushFilter({ hideX = true, hideY = true, ...rest }) {
|
|
|
160
163
|
...event,
|
|
161
164
|
data: { selection: [domainX, domainY] },
|
|
162
165
|
});
|
|
163
|
-
|
|
164
166
|
filtered = false;
|
|
165
167
|
newView = view;
|
|
166
|
-
|
|
168
|
+
setState('brushFilter');
|
|
169
|
+
update();
|
|
167
170
|
},
|
|
168
171
|
extent: undefined,
|
|
169
172
|
emitter,
|
|
@@ -58,7 +58,7 @@ export function ChartIndex({
|
|
|
58
58
|
...style
|
|
59
59
|
}: Record<string, any>) {
|
|
60
60
|
return (context) => {
|
|
61
|
-
const {
|
|
61
|
+
const { view, container, update, setState } = context;
|
|
62
62
|
const { markState, scale, coordinate } = view;
|
|
63
63
|
|
|
64
64
|
// Get line mark value, exit if it is not existed.
|
|
@@ -70,18 +70,6 @@ export function ChartIndex({
|
|
|
70
70
|
const I = Y.map((_, i) => i);
|
|
71
71
|
const sortedX: number[] = sort(I.map((i) => X[i]));
|
|
72
72
|
|
|
73
|
-
// Clone options and get line mark.
|
|
74
|
-
const clonedOptions = deepMix({}, options);
|
|
75
|
-
const lineMark = clonedOptions.marks.find((d) => d.type === 'line');
|
|
76
|
-
|
|
77
|
-
// Update domain of y scale for the line mark.
|
|
78
|
-
const r = (I: number[]) => max(I, (i) => +Y[i]) / min(I, (i) => +Y[i]);
|
|
79
|
-
const k = max(rollup(I, r, (i) => S[i]).values());
|
|
80
|
-
const domainY = [1 / k, k];
|
|
81
|
-
deepMix(lineMark, {
|
|
82
|
-
scale: { y: { domain: domainY } },
|
|
83
|
-
});
|
|
84
|
-
|
|
85
73
|
// Prepare shapes.
|
|
86
74
|
const plotArea = selectPlotArea(container);
|
|
87
75
|
const lines = container.getElementsByClassName(ELEMENT_CLASS_NAME);
|
|
@@ -142,16 +130,31 @@ export function ChartIndex({
|
|
|
142
130
|
|
|
143
131
|
updateRule(focus, date);
|
|
144
132
|
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
133
|
+
setState('chartIndex', (options) => {
|
|
134
|
+
// Clone options and get line mark.
|
|
135
|
+
const clonedOptions = deepMix({}, options);
|
|
136
|
+
const lineMark = clonedOptions.marks.find((d) => d.type === 'line');
|
|
137
|
+
|
|
138
|
+
// Update domain of y scale for the line mark.
|
|
139
|
+
const r = (I: number[]) => max(I, (i) => +Y[i]) / min(I, (i) => +Y[i]);
|
|
140
|
+
const k = max(rollup(I, r, (i) => S[i]).values());
|
|
141
|
+
const domainY = [1 / k, k];
|
|
142
|
+
deepMix(lineMark, {
|
|
143
|
+
scale: { y: { domain: domainY } },
|
|
144
|
+
});
|
|
145
|
+
// Update normalize options.
|
|
146
|
+
const normalizeY = maybeTransform(lineMark);
|
|
147
|
+
normalizeY.groupBy = 'color';
|
|
148
|
+
normalizeY.basis = (I, Y) => {
|
|
149
|
+
const i = I[bisector((i) => X[+i]).center(I, date)];
|
|
150
|
+
return Y[i];
|
|
151
|
+
};
|
|
152
|
+
// Disable animation.
|
|
153
|
+
for (const mark of clonedOptions.marks) mark.animate = false;
|
|
154
|
+
return clonedOptions;
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
const newState = await update();
|
|
155
158
|
newView = newState.view;
|
|
156
159
|
};
|
|
157
160
|
|
|
@@ -22,26 +22,30 @@ export function Fisheye({
|
|
|
22
22
|
trailing = false,
|
|
23
23
|
}: Record<string, any>) {
|
|
24
24
|
return (context) => {
|
|
25
|
-
const { options, update, container } = context;
|
|
25
|
+
const { options, update, setState, container } = context;
|
|
26
26
|
const plotArea = selectPlotArea(container);
|
|
27
27
|
|
|
28
|
-
// Clone options and mutate it.
|
|
29
|
-
// Disable animation.
|
|
30
|
-
const clonedOptions = deepMix({}, options);
|
|
31
|
-
for (const mark of clonedOptions.marks) mark.animate = false;
|
|
32
28
|
const updateFocus = throttle(
|
|
33
29
|
(event) => {
|
|
34
30
|
const focus = mousePosition(plotArea, event);
|
|
35
31
|
if (!focus) {
|
|
36
|
-
|
|
32
|
+
setState('fisheye');
|
|
33
|
+
update();
|
|
37
34
|
return;
|
|
38
35
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
36
|
+
setState('fisheye', (options) => {
|
|
37
|
+
// Clone options and mutate it.
|
|
38
|
+
// Disable animation.
|
|
39
|
+
const clonedOptions = deepMix({}, options);
|
|
40
|
+
for (const mark of clonedOptions.marks) mark.animate = false;
|
|
41
|
+
const [x, y] = focus;
|
|
42
|
+
const fisheye = maybeCoordinate(clonedOptions);
|
|
43
|
+
fisheye.focusX = x;
|
|
44
|
+
fisheye.focusY = y;
|
|
45
|
+
fisheye.visual = true;
|
|
46
|
+
return clonedOptions;
|
|
47
|
+
});
|
|
48
|
+
update();
|
|
45
49
|
},
|
|
46
50
|
wait,
|
|
47
51
|
{ leading, trailing },
|
|
@@ -200,52 +200,57 @@ function legendFilterContinuous(_, { legend, filter, emitter, channel }) {
|
|
|
200
200
|
|
|
201
201
|
export function LegendFilter() {
|
|
202
202
|
return (context, _, emitter) => {
|
|
203
|
-
const { container, view,
|
|
203
|
+
const { container, view, update, setState } = context;
|
|
204
204
|
|
|
205
|
+
const channelsOf = (legend) => {
|
|
206
|
+
return dataOf(legend).scales.map((d) => d.name);
|
|
207
|
+
};
|
|
205
208
|
const legends = [
|
|
206
209
|
...legendsOf(container),
|
|
207
210
|
...legendsContinuousOf(container),
|
|
208
211
|
];
|
|
212
|
+
const allChannels = legends.flatMap(channelsOf);
|
|
209
213
|
|
|
210
214
|
const filter = throttle(
|
|
211
|
-
async (channel, value, ordinal: boolean, channels) => {
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
channel
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
215
|
+
async (legend, channel, value, ordinal: boolean, channels) => {
|
|
216
|
+
setState(legend, (viewOptions) => {
|
|
217
|
+
const { marks } = viewOptions;
|
|
218
|
+
// Add filter transform for every marks,
|
|
219
|
+
// which will skip for mark without color channel.
|
|
220
|
+
const newMarks = marks.map((mark) => {
|
|
221
|
+
if (mark.type === 'legends') return mark;
|
|
222
|
+
|
|
223
|
+
// Inset after aggregate transform, such as group, and bin.
|
|
224
|
+
const { transform = [] } = mark;
|
|
225
|
+
const index = transform.findIndex(
|
|
226
|
+
({ type }) => type.startsWith('group') || type.startsWith('bin'),
|
|
227
|
+
);
|
|
228
|
+
const newTransform = [...transform];
|
|
229
|
+
newTransform.splice(index + 1, 0, {
|
|
230
|
+
type: 'filter',
|
|
231
|
+
[channel]: { value, ordinal },
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
// Set domain of scale to preserve encoding.
|
|
235
|
+
const newScale = Object.fromEntries(
|
|
236
|
+
channels.map((channel) => [
|
|
237
|
+
channel,
|
|
238
|
+
{ domain: view.scale[channel].getOptions().domain },
|
|
239
|
+
]),
|
|
240
|
+
);
|
|
241
|
+
|
|
242
|
+
return deepMix({}, mark, {
|
|
243
|
+
transform: newTransform,
|
|
244
|
+
scale: newScale,
|
|
245
|
+
...(!ordinal && { animate: false }),
|
|
246
|
+
legend: Object.fromEntries(
|
|
247
|
+
allChannels.map((d) => [d, { preserve: true }]),
|
|
248
|
+
),
|
|
249
|
+
});
|
|
242
250
|
});
|
|
251
|
+
return { ...viewOptions, marks: newMarks };
|
|
243
252
|
});
|
|
244
|
-
|
|
245
|
-
...viewOptions,
|
|
246
|
-
marks: newMarks,
|
|
247
|
-
};
|
|
248
|
-
await update(newOptions);
|
|
253
|
+
await update();
|
|
249
254
|
},
|
|
250
255
|
50,
|
|
251
256
|
{ trailing: true },
|
|
@@ -253,7 +258,7 @@ export function LegendFilter() {
|
|
|
253
258
|
|
|
254
259
|
const removes = legends.map((legend) => {
|
|
255
260
|
const { name: channel, domain } = dataOf(legend).scales[0];
|
|
256
|
-
const channels =
|
|
261
|
+
const channels = channelsOf(legend);
|
|
257
262
|
if (legend.className === CATEGORY_LEGEND_CLASS_NAME) {
|
|
258
263
|
return legendFilterOrdinal(container, {
|
|
259
264
|
legends: itemsOf,
|
|
@@ -264,7 +269,7 @@ export function LegendFilter() {
|
|
|
264
269
|
const { index } = datum;
|
|
265
270
|
return domain[index];
|
|
266
271
|
},
|
|
267
|
-
filter: (value) => filter(channel, value, true, channels),
|
|
272
|
+
filter: (value) => filter(legend, channel, value, true, channels),
|
|
268
273
|
state: legend.attributes.state,
|
|
269
274
|
channel,
|
|
270
275
|
emitter,
|
|
@@ -272,7 +277,7 @@ export function LegendFilter() {
|
|
|
272
277
|
} else {
|
|
273
278
|
return legendFilterContinuous(container, {
|
|
274
279
|
legend,
|
|
275
|
-
filter: (value) => filter(channel, value, false, channels),
|
|
280
|
+
filter: (value) => filter(legend, channel, value, false, channels),
|
|
276
281
|
emitter,
|
|
277
282
|
channel,
|
|
278
283
|
});
|
|
@@ -68,7 +68,7 @@ export function SliderFilter({
|
|
|
68
68
|
trailing = false,
|
|
69
69
|
}: any) {
|
|
70
70
|
return (context, _, emitter) => {
|
|
71
|
-
const { container, view,
|
|
71
|
+
const { container, view, update, setState } = context;
|
|
72
72
|
const sliders = container.getElementsByClassName(className);
|
|
73
73
|
if (!sliders.length) return () => {};
|
|
74
74
|
|
|
@@ -138,18 +138,6 @@ export function SliderFilter({
|
|
|
138
138
|
channelDomain[channel0] = domain0;
|
|
139
139
|
channelDomain[channel1] = domain1;
|
|
140
140
|
|
|
141
|
-
// Filter data.
|
|
142
|
-
const newOptions = filterDataByDomain(
|
|
143
|
-
options,
|
|
144
|
-
{
|
|
145
|
-
// Set nice to false to avoid modify domain.
|
|
146
|
-
[channel0]: { domain: domain0, nice: false },
|
|
147
|
-
[channel1]: { domain: domain1, nice: false },
|
|
148
|
-
},
|
|
149
|
-
prefix,
|
|
150
|
-
hasState,
|
|
151
|
-
);
|
|
152
|
-
|
|
153
141
|
if (nativeEvent) {
|
|
154
142
|
// Emit events.
|
|
155
143
|
const X = isX ? domain0 : domain1;
|
|
@@ -161,13 +149,24 @@ export function SliderFilter({
|
|
|
161
149
|
});
|
|
162
150
|
}
|
|
163
151
|
|
|
164
|
-
|
|
165
|
-
...
|
|
152
|
+
setState(slider, (options) => ({
|
|
153
|
+
...filterDataByDomain(
|
|
154
|
+
options,
|
|
155
|
+
{
|
|
156
|
+
// Set nice to false to avoid modify domain.
|
|
157
|
+
[channel0]: { domain: domain0, nice: false },
|
|
158
|
+
[channel1]: { domain: domain1, nice: false },
|
|
159
|
+
},
|
|
160
|
+
prefix,
|
|
161
|
+
hasState,
|
|
162
|
+
),
|
|
166
163
|
paddingLeft,
|
|
167
164
|
paddingTop,
|
|
168
165
|
paddingBottom,
|
|
169
166
|
paddingRight,
|
|
170
|
-
});
|
|
167
|
+
}));
|
|
168
|
+
|
|
169
|
+
await update();
|
|
171
170
|
filtering = false;
|
|
172
171
|
},
|
|
173
172
|
wait,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DisplayObject, IElement, Line } from '@antv/g';
|
|
1
|
+
import { Circle, DisplayObject, IElement, Line } from '@antv/g';
|
|
2
2
|
import { sort, group, mean, bisector, minIndex } from 'd3-array';
|
|
3
3
|
import { deepMix, lowerFirst, throttle } from '@antv/util';
|
|
4
4
|
import { Tooltip as TooltipComponent } from '@antv/gui';
|
|
@@ -333,6 +333,38 @@ function hideRuleY(root) {
|
|
|
333
333
|
}
|
|
334
334
|
}
|
|
335
335
|
|
|
336
|
+
function updateMarker(root, { data, style, items }) {
|
|
337
|
+
if (root.markers) root.markers.forEach((d) => d.remove());
|
|
338
|
+
const markers = data.map((d) => {
|
|
339
|
+
const [{ color, element }, point] = d;
|
|
340
|
+
const fill =
|
|
341
|
+
color || // encode value
|
|
342
|
+
element.style.fill ||
|
|
343
|
+
element.style.stroke;
|
|
344
|
+
const shape = new Circle({
|
|
345
|
+
style: {
|
|
346
|
+
cx: point[0],
|
|
347
|
+
cy: point[1],
|
|
348
|
+
fill,
|
|
349
|
+
r: 4,
|
|
350
|
+
stroke: '#fff',
|
|
351
|
+
strokeWidth: 2,
|
|
352
|
+
...style,
|
|
353
|
+
},
|
|
354
|
+
});
|
|
355
|
+
return shape;
|
|
356
|
+
});
|
|
357
|
+
for (const marker of markers) root.appendChild(marker);
|
|
358
|
+
root.markers = markers;
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
function hideMarker(root) {
|
|
362
|
+
if (root.markers) {
|
|
363
|
+
root.markers.forEach((d) => d.remove());
|
|
364
|
+
root.markers = [];
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
|
|
336
368
|
function interactionKeyof(markState, key) {
|
|
337
369
|
return Array.from(markState.values()).some(
|
|
338
370
|
// @ts-ignore
|
|
@@ -384,6 +416,7 @@ export function seriesTooltip(
|
|
|
384
416
|
mount,
|
|
385
417
|
bounding,
|
|
386
418
|
disableNative = false,
|
|
419
|
+
marker = true,
|
|
387
420
|
style: _style = {},
|
|
388
421
|
...rest
|
|
389
422
|
}: Record<string, any>,
|
|
@@ -430,7 +463,6 @@ export function seriesTooltip(
|
|
|
430
463
|
}),
|
|
431
464
|
);
|
|
432
465
|
|
|
433
|
-
const ruleStyle = subObject(style, 'crosshairs');
|
|
434
466
|
const { x: scaleX } = scale;
|
|
435
467
|
|
|
436
468
|
// Apply offset for band scale x.
|
|
@@ -499,7 +531,7 @@ export function seriesTooltip(
|
|
|
499
531
|
const d = seriesData(element, index);
|
|
500
532
|
const { x, y } = d;
|
|
501
533
|
const p = coordinate.map([(x || 0) + offsetX, y || 0]);
|
|
502
|
-
selectedSeriesData.push([d, p] as const);
|
|
534
|
+
selectedSeriesData.push([{ ...d, element }, p] as const);
|
|
503
535
|
}
|
|
504
536
|
}
|
|
505
537
|
|
|
@@ -557,6 +589,7 @@ export function seriesTooltip(
|
|
|
557
589
|
|
|
558
590
|
if (crosshairs) {
|
|
559
591
|
const points = filteredSeriesData.map((d) => d[1]);
|
|
592
|
+
const ruleStyle = subObject(style, 'crosshairs');
|
|
560
593
|
updateRuleY(root, points, {
|
|
561
594
|
...ruleStyle,
|
|
562
595
|
plotWidth,
|
|
@@ -572,6 +605,15 @@ export function seriesTooltip(
|
|
|
572
605
|
});
|
|
573
606
|
}
|
|
574
607
|
|
|
608
|
+
if (marker) {
|
|
609
|
+
const markerStyles = subObject(style, 'marker');
|
|
610
|
+
updateMarker(root, {
|
|
611
|
+
data: filteredSeriesData,
|
|
612
|
+
items: tooltipData.items,
|
|
613
|
+
style: markerStyles,
|
|
614
|
+
});
|
|
615
|
+
}
|
|
616
|
+
|
|
575
617
|
emitter.emit('tooltip:show', {
|
|
576
618
|
...event,
|
|
577
619
|
nativeEvent: true,
|
|
@@ -585,6 +627,7 @@ export function seriesTooltip(
|
|
|
585
627
|
const hide = () => {
|
|
586
628
|
hideTooltip({ root, single, emitter, mount });
|
|
587
629
|
if (crosshairs) hideRuleY(root);
|
|
630
|
+
if (marker) hideMarker(root);
|
|
588
631
|
};
|
|
589
632
|
|
|
590
633
|
const onTooltipShow = ({ nativeEvent, data }) => {
|
|
@@ -622,6 +665,7 @@ export function seriesTooltip(
|
|
|
622
665
|
emitter.off('tooltip:hide', onTooltipHide);
|
|
623
666
|
destroyTooltip(root);
|
|
624
667
|
if (crosshairs) hideRuleY(root);
|
|
668
|
+
if (marker) hideMarker(root);
|
|
625
669
|
};
|
|
626
670
|
}
|
|
627
671
|
|
package/src/lib/core.ts
CHANGED
|
@@ -159,6 +159,7 @@ import {
|
|
|
159
159
|
Join as DataJoin,
|
|
160
160
|
Sort as DataSort,
|
|
161
161
|
KDE as DataKDE,
|
|
162
|
+
Log as DataLog,
|
|
162
163
|
} from '../data';
|
|
163
164
|
import {
|
|
164
165
|
OverlapDodgeY,
|
|
@@ -183,6 +184,7 @@ export function corelib() {
|
|
|
183
184
|
'data.map': DataMap,
|
|
184
185
|
'data.join': DataJoin,
|
|
185
186
|
'data.kde': DataKDE,
|
|
187
|
+
'data.log': DataLog,
|
|
186
188
|
'transform.stackY': StackY,
|
|
187
189
|
'transform.binX': BinX,
|
|
188
190
|
'transform.bin': Bin,
|
package/src/runtime/plot.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Vector2 } from '@antv/coord';
|
|
2
2
|
import { DisplayObject, IAnimation as GAnimation, Rect } from '@antv/g';
|
|
3
3
|
import { deepMix, upperFirst } from '@antv/util';
|
|
4
|
-
import { group, groups } from 'd3-array';
|
|
4
|
+
import { group, groups, sort } from 'd3-array';
|
|
5
5
|
import { format } from 'd3-format';
|
|
6
6
|
import { mapObject } from '../utils/array';
|
|
7
7
|
import { ChartEvent } from '../utils/event';
|
|
@@ -237,12 +237,27 @@ export async function plot<T extends G2ViewTree>(
|
|
|
237
237
|
const viewInstanceof = (
|
|
238
238
|
viewContainer: Map<G2ViewDescriptor, DisplayObject>,
|
|
239
239
|
) => {
|
|
240
|
-
return Array.from(viewContainer.entries()).map(([view, container]) =>
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
options
|
|
244
|
-
|
|
245
|
-
|
|
240
|
+
return Array.from(viewContainer.entries()).map(([view, container]) => {
|
|
241
|
+
// Index state by component or interaction name,
|
|
242
|
+
// such as legend, scrollbar, brushFilter.
|
|
243
|
+
// Each state transform options to another options.
|
|
244
|
+
const store = new Map<any, (options: G2ViewTree) => G2ViewTree>();
|
|
245
|
+
const setState = (key, reducer = (x) => x) => store.set(key, reducer);
|
|
246
|
+
const update = createUpdateView(select(container), library, context);
|
|
247
|
+
const options = viewNode.get(view);
|
|
248
|
+
return {
|
|
249
|
+
view,
|
|
250
|
+
container,
|
|
251
|
+
options,
|
|
252
|
+
setState,
|
|
253
|
+
update: async () => {
|
|
254
|
+
// Apply all state functions to get new options.
|
|
255
|
+
const reducer = compose(Array.from(store.values()));
|
|
256
|
+
const newOptions = reducer(options);
|
|
257
|
+
return await update(newOptions);
|
|
258
|
+
},
|
|
259
|
+
};
|
|
260
|
+
});
|
|
246
261
|
};
|
|
247
262
|
|
|
248
263
|
// Interactions for enter views.
|
|
@@ -12,6 +12,7 @@ export type DataTransform =
|
|
|
12
12
|
| SliceTransform
|
|
13
13
|
| KDEDataTransform
|
|
14
14
|
| VennDataTransform
|
|
15
|
+
| LogDataTransform
|
|
15
16
|
| CustomTransform;
|
|
16
17
|
|
|
17
18
|
export type DataTransformTypes =
|
|
@@ -26,6 +27,7 @@ export type DataTransformTypes =
|
|
|
26
27
|
| 'slice'
|
|
27
28
|
| 'kde'
|
|
28
29
|
| 'venn'
|
|
30
|
+
| 'log'
|
|
29
31
|
| 'custom'
|
|
30
32
|
| DataComponent;
|
|
31
33
|
|
|
@@ -179,6 +181,9 @@ export type VennDataTransform = {
|
|
|
179
181
|
as?: [string, string];
|
|
180
182
|
};
|
|
181
183
|
|
|
184
|
+
// eslint-disable-next-line
|
|
185
|
+
export type LogDataTransform = {};
|
|
186
|
+
|
|
182
187
|
export type CustomTransform = {
|
|
183
188
|
type?: DataComponent;
|
|
184
189
|
[key: string]: any;
|
package/src/spec/interaction.ts
CHANGED
|
@@ -175,6 +175,7 @@ export type TooltipInteraction = {
|
|
|
175
175
|
facet?: boolean;
|
|
176
176
|
body?: boolean;
|
|
177
177
|
crosshairs?: boolean;
|
|
178
|
+
marker?: boolean;
|
|
178
179
|
groupName?: boolean;
|
|
179
180
|
position?: TooltipStyleProps['position'];
|
|
180
181
|
bounding?: BBox;
|
|
@@ -186,7 +187,8 @@ export type TooltipInteraction = {
|
|
|
186
187
|
event, // @todo
|
|
187
188
|
options: { title: 'string'; items: TooltipItemValue[] },
|
|
188
189
|
) => HTMLElement | string;
|
|
189
|
-
} & Record<`crosshairs${any}`, any
|
|
190
|
+
} & Record<`crosshairs${any}`, any> &
|
|
191
|
+
Record<`marker${any}`, any>;
|
|
190
192
|
|
|
191
193
|
export type FisheyeInteraction = {
|
|
192
194
|
type?: 'fisheye';
|