@antv/g2 5.1.3 → 5.1.5-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/g2-lite.min.js +1 -1
- package/dist/g2.min.js +1 -1
- package/esm/api/chart.d.ts +1 -0
- package/esm/api/library.d.ts +1 -0
- package/esm/api/runtime.js +3 -2
- package/esm/api/runtime.js.map +1 -1
- package/esm/api/utils.d.ts +2 -0
- package/esm/api/utils.js +31 -8
- package/esm/api/utils.js.map +1 -1
- package/esm/composition/repeatMatrix.js +4 -1
- package/esm/composition/repeatMatrix.js.map +1 -1
- package/esm/interaction/fisheye.js +3 -1
- package/esm/interaction/fisheye.js.map +1 -1
- package/esm/interaction/legendFilter.d.ts +1 -1
- package/esm/interaction/legendFilter.js +72 -31
- package/esm/interaction/legendFilter.js.map +1 -1
- package/esm/interaction/tooltip.d.ts +2 -2
- package/esm/interaction/tooltip.js +82 -40
- 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/lib/threed.d.ts +1 -0
- package/esm/lib/threed.js +2 -1
- package/esm/lib/threed.js.map +1 -1
- package/esm/mark/index.d.ts +1 -0
- package/esm/mark/index.js +1 -0
- package/esm/mark/index.js.map +1 -1
- package/esm/mark/interval3D.d.ts +8 -0
- package/esm/mark/interval3D.js +65 -0
- package/esm/mark/interval3D.js.map +1 -0
- package/esm/runtime/plot.js +11 -4
- package/esm/runtime/plot.js.map +1 -1
- package/esm/shape/connector/connector.js +1 -1
- package/esm/shape/connector/connector.js.map +1 -1
- package/esm/shape/index.d.ts +2 -1
- package/esm/shape/index.js +1 -0
- package/esm/shape/index.js.map +1 -1
- package/esm/shape/interval3D/cube.d.ts +6 -0
- package/esm/shape/interval3D/cube.js +71 -0
- package/esm/shape/interval3D/cube.js.map +1 -0
- package/esm/spec/interaction.d.ts +1 -0
- package/esm/theme/academy.js +30 -358
- package/esm/theme/academy.js.map +1 -1
- package/esm/theme/classic.js +4 -433
- package/esm/theme/classic.js.map +1 -1
- package/esm/theme/classicDark.js +3 -404
- package/esm/theme/classicDark.js.map +1 -1
- package/esm/theme/create.d.ts +437 -0
- package/esm/theme/create.js +421 -0
- package/esm/theme/create.js.map +1 -0
- package/esm/theme/dark.d.ts +3 -0
- package/esm/theme/dark.js +76 -0
- package/esm/theme/dark.js.map +1 -0
- package/esm/theme/index.d.ts +1 -0
- package/esm/theme/index.js +1 -0
- package/esm/theme/index.js.map +1 -1
- package/esm/theme/light.js +52 -470
- package/esm/theme/light.js.map +1 -1
- package/lib/api/chart.d.ts +1 -0
- package/lib/api/library.d.ts +1 -0
- package/lib/api/runtime.js +2 -1
- package/lib/api/runtime.js.map +1 -1
- package/lib/api/utils.d.ts +2 -0
- package/lib/api/utils.js +32 -9
- package/lib/api/utils.js.map +1 -1
- package/lib/composition/repeatMatrix.js +4 -1
- package/lib/composition/repeatMatrix.js.map +1 -1
- package/lib/interaction/fisheye.js +3 -1
- package/lib/interaction/fisheye.js.map +1 -1
- package/lib/interaction/legendFilter.d.ts +1 -1
- package/lib/interaction/legendFilter.js +72 -31
- package/lib/interaction/legendFilter.js.map +1 -1
- package/lib/interaction/tooltip.d.ts +2 -2
- package/lib/interaction/tooltip.js +82 -40
- 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/lib/threed.d.ts +1 -0
- package/lib/lib/threed.js +1 -0
- package/lib/lib/threed.js.map +1 -1
- package/lib/mark/index.d.ts +1 -0
- package/lib/mark/index.js +3 -1
- package/lib/mark/index.js.map +1 -1
- package/lib/mark/interval3D.d.ts +8 -0
- package/lib/mark/interval3D.js +69 -0
- package/lib/mark/interval3D.js.map +1 -0
- package/lib/runtime/plot.js +11 -4
- package/lib/runtime/plot.js.map +1 -1
- package/lib/shape/connector/connector.js +1 -1
- package/lib/shape/connector/connector.js.map +1 -1
- package/lib/shape/index.d.ts +2 -1
- package/lib/shape/index.js +4 -2
- package/lib/shape/index.js.map +1 -1
- package/lib/shape/interval3D/cube.d.ts +6 -0
- package/lib/shape/interval3D/cube.js +75 -0
- package/lib/shape/interval3D/cube.js.map +1 -0
- package/lib/spec/interaction.d.ts +1 -0
- package/lib/theme/academy.js +30 -358
- package/lib/theme/academy.js.map +1 -1
- package/lib/theme/classic.js +4 -433
- package/lib/theme/classic.js.map +1 -1
- package/lib/theme/classicDark.js +3 -404
- package/lib/theme/classicDark.js.map +1 -1
- package/lib/theme/create.d.ts +437 -0
- package/lib/theme/create.js +425 -0
- package/lib/theme/create.js.map +1 -0
- package/lib/theme/dark.d.ts +3 -0
- package/lib/theme/dark.js +80 -0
- package/lib/theme/dark.js.map +1 -0
- package/lib/theme/index.d.ts +1 -0
- package/lib/theme/index.js +3 -1
- package/lib/theme/index.js.map +1 -1
- package/lib/theme/light.js +52 -470
- package/lib/theme/light.js.map +1 -1
- package/package.json +1 -1
- package/src/api/runtime.ts +2 -1
- package/src/api/utils.ts +29 -7
- package/src/composition/repeatMatrix.ts +11 -2
- package/src/interaction/fisheye.ts +3 -1
- package/src/interaction/legendFilter.ts +81 -48
- package/src/interaction/tooltip.ts +105 -49
- package/src/lib/core.ts +2 -1
- package/src/lib/threed.ts +2 -1
- package/src/mark/index.ts +1 -0
- package/src/mark/interval3D.ts +100 -0
- package/src/runtime/plot.ts +34 -7
- package/src/shape/connector/connector.ts +1 -1
- package/src/shape/index.ts +2 -1
- package/src/shape/interval3D/cube.ts +69 -0
- package/src/spec/interaction.ts +1 -0
- package/src/theme/academy.ts +74 -399
- package/src/theme/classic.ts +11 -438
- package/src/theme/classicDark.ts +10 -409
- package/src/theme/create.ts +439 -0
- package/src/theme/dark.ts +85 -0
- package/src/theme/index.ts +1 -0
- package/src/theme/light.ts +53 -473
- package/CHANGELOG.md +0 -385
|
@@ -36,7 +36,9 @@ export function Fisheye({
|
|
|
36
36
|
setState('fisheye', (options) => {
|
|
37
37
|
// Clone options and mutate it.
|
|
38
38
|
// Disable animation.
|
|
39
|
-
const clonedOptions = deepMix({}, options
|
|
39
|
+
const clonedOptions = deepMix({}, options, {
|
|
40
|
+
interaction: { tooltip: { preserve: true } },
|
|
41
|
+
});
|
|
40
42
|
for (const mark of clonedOptions.marks) mark.animate = false;
|
|
41
43
|
const [x, y] = focus;
|
|
42
44
|
const fisheye = maybeCoordinate(clonedOptions);
|
|
@@ -198,9 +198,69 @@ function legendFilterContinuous(_, { legend, filter, emitter, channel }) {
|
|
|
198
198
|
};
|
|
199
199
|
}
|
|
200
200
|
|
|
201
|
+
async function filterView(
|
|
202
|
+
context, // View instance,
|
|
203
|
+
{
|
|
204
|
+
legend, // Legend instance.
|
|
205
|
+
channel, // Filter Channel.
|
|
206
|
+
value, // Filtered Values.
|
|
207
|
+
ordinal, // Data type of the legend.
|
|
208
|
+
channels, // Channels for this legend.
|
|
209
|
+
allChannels, // Channels for all legends.
|
|
210
|
+
facet = false, // For facet.
|
|
211
|
+
},
|
|
212
|
+
) {
|
|
213
|
+
const { view, update, setState } = context;
|
|
214
|
+
setState(legend, (viewOptions) => {
|
|
215
|
+
const { marks } = viewOptions;
|
|
216
|
+
// Add filter transform for every marks,
|
|
217
|
+
// which will skip for mark without color channel.
|
|
218
|
+
const newMarks = marks.map((mark) => {
|
|
219
|
+
if (mark.type === 'legends') return mark;
|
|
220
|
+
|
|
221
|
+
// Inset after aggregate transform, such as group, and bin.
|
|
222
|
+
const { transform = [] } = mark;
|
|
223
|
+
const index = transform.findIndex(
|
|
224
|
+
({ type }) => type.startsWith('group') || type.startsWith('bin'),
|
|
225
|
+
);
|
|
226
|
+
const newTransform = [...transform];
|
|
227
|
+
newTransform.splice(index + 1, 0, {
|
|
228
|
+
type: 'filter',
|
|
229
|
+
[channel]: { value, ordinal },
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
// Set domain of scale to preserve encoding.
|
|
233
|
+
const newScale = Object.fromEntries(
|
|
234
|
+
channels.map((channel) => [
|
|
235
|
+
channel,
|
|
236
|
+
{ domain: view.scale[channel].getOptions().domain },
|
|
237
|
+
]),
|
|
238
|
+
);
|
|
239
|
+
return deepMix({}, mark, {
|
|
240
|
+
transform: newTransform,
|
|
241
|
+
scale: newScale,
|
|
242
|
+
...(!ordinal && { animate: false }),
|
|
243
|
+
legend: facet
|
|
244
|
+
? false
|
|
245
|
+
: Object.fromEntries(allChannels.map((d) => [d, { preserve: true }])),
|
|
246
|
+
});
|
|
247
|
+
});
|
|
248
|
+
return { ...viewOptions, marks: newMarks };
|
|
249
|
+
});
|
|
250
|
+
await update();
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
function filterFacets(facets, options) {
|
|
254
|
+
for (const facet of facets) {
|
|
255
|
+
filterView(facet, { ...options, facet: true });
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
|
|
201
259
|
export function LegendFilter() {
|
|
202
|
-
return (context,
|
|
203
|
-
const { container
|
|
260
|
+
return (context, contexts, emitter) => {
|
|
261
|
+
const { container } = context;
|
|
262
|
+
const facets = contexts.filter((d) => d !== context);
|
|
263
|
+
const isFacet = facets.length > 0;
|
|
204
264
|
|
|
205
265
|
const channelsOf = (legend) => {
|
|
206
266
|
return dataOf(legend).scales.map((d) => d.name);
|
|
@@ -211,54 +271,19 @@ export function LegendFilter() {
|
|
|
211
271
|
];
|
|
212
272
|
const allChannels = legends.flatMap(channelsOf);
|
|
213
273
|
|
|
214
|
-
const filter =
|
|
215
|
-
|
|
216
|
-
|
|
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
|
-
});
|
|
250
|
-
});
|
|
251
|
-
return { ...viewOptions, marks: newMarks };
|
|
252
|
-
});
|
|
253
|
-
await update();
|
|
254
|
-
},
|
|
255
|
-
50,
|
|
256
|
-
{ trailing: true },
|
|
257
|
-
);
|
|
274
|
+
const filter = isFacet
|
|
275
|
+
? throttle(filterFacets, 50, { trailing: true })
|
|
276
|
+
: throttle(filterView, 50, { trailing: true });
|
|
258
277
|
|
|
259
278
|
const removes = legends.map((legend) => {
|
|
260
279
|
const { name: channel, domain } = dataOf(legend).scales[0];
|
|
261
280
|
const channels = channelsOf(legend);
|
|
281
|
+
const common = {
|
|
282
|
+
legend,
|
|
283
|
+
channel,
|
|
284
|
+
channels,
|
|
285
|
+
allChannels,
|
|
286
|
+
};
|
|
262
287
|
if (legend.className === CATEGORY_LEGEND_CLASS_NAME) {
|
|
263
288
|
return legendFilterOrdinal(container, {
|
|
264
289
|
legends: itemsOf,
|
|
@@ -269,7 +294,11 @@ export function LegendFilter() {
|
|
|
269
294
|
const { index } = datum;
|
|
270
295
|
return domain[index];
|
|
271
296
|
},
|
|
272
|
-
filter: (value) =>
|
|
297
|
+
filter: (value) => {
|
|
298
|
+
const options = { ...common, value, ordinal: true };
|
|
299
|
+
if (isFacet) filter(facets, options);
|
|
300
|
+
else filter(context, options);
|
|
301
|
+
},
|
|
273
302
|
state: legend.attributes.state,
|
|
274
303
|
channel,
|
|
275
304
|
emitter,
|
|
@@ -277,7 +306,11 @@ export function LegendFilter() {
|
|
|
277
306
|
} else {
|
|
278
307
|
return legendFilterContinuous(container, {
|
|
279
308
|
legend,
|
|
280
|
-
filter: (value) =>
|
|
309
|
+
filter: (value) => {
|
|
310
|
+
const options = { ...common, value, ordinal: false };
|
|
311
|
+
if (isFacet) filter(facets, options);
|
|
312
|
+
else filter(context, options);
|
|
313
|
+
},
|
|
281
314
|
emitter,
|
|
282
315
|
channel,
|
|
283
316
|
});
|
|
@@ -2,7 +2,7 @@ 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';
|
|
5
|
-
import { Constant,
|
|
5
|
+
import { Constant, Band } from '@antv/scale';
|
|
6
6
|
import { defined, subObject } from '../utils/helper';
|
|
7
7
|
import { isTranspose, isPolar } from '../utils/coordinate';
|
|
8
8
|
import { angle, sub } from '../utils/vector';
|
|
@@ -63,7 +63,16 @@ function createTooltip(
|
|
|
63
63
|
enterable,
|
|
64
64
|
bounding,
|
|
65
65
|
containerOffset,
|
|
66
|
+
css = {},
|
|
66
67
|
) {
|
|
68
|
+
const defaults = {
|
|
69
|
+
'.g2-tooltip': {},
|
|
70
|
+
'.g2-tooltip-title': {
|
|
71
|
+
overflow: 'hidden',
|
|
72
|
+
'white-space': 'nowrap',
|
|
73
|
+
'text-overflow': 'ellipsis',
|
|
74
|
+
},
|
|
75
|
+
};
|
|
67
76
|
const tooltipElement = new TooltipComponent({
|
|
68
77
|
className: 'tooltip',
|
|
69
78
|
style: {
|
|
@@ -79,14 +88,7 @@ function createTooltip(
|
|
|
79
88
|
template: {
|
|
80
89
|
prefixCls: 'g2-',
|
|
81
90
|
},
|
|
82
|
-
style:
|
|
83
|
-
'.g2-tooltip': {},
|
|
84
|
-
'.g2-tooltip-title': {
|
|
85
|
-
overflow: 'hidden',
|
|
86
|
-
'white-space': 'nowrap',
|
|
87
|
-
'text-overflow': 'ellipsis',
|
|
88
|
-
},
|
|
89
|
-
},
|
|
91
|
+
style: deepMix(defaults, css),
|
|
90
92
|
},
|
|
91
93
|
});
|
|
92
94
|
container.appendChild(tooltipElement.HTMLTooltipElement);
|
|
@@ -103,6 +105,7 @@ function showTooltip({
|
|
|
103
105
|
single,
|
|
104
106
|
position = 'right-bottom',
|
|
105
107
|
enterable = false,
|
|
108
|
+
css,
|
|
106
109
|
mount,
|
|
107
110
|
bounding,
|
|
108
111
|
}) {
|
|
@@ -123,6 +126,7 @@ function showTooltip({
|
|
|
123
126
|
enterable,
|
|
124
127
|
b,
|
|
125
128
|
containerOffset,
|
|
129
|
+
css,
|
|
126
130
|
),
|
|
127
131
|
} = parent as any;
|
|
128
132
|
const { items, title = '' } = data;
|
|
@@ -196,7 +200,10 @@ function groupNameOf(scale, datum) {
|
|
|
196
200
|
);
|
|
197
201
|
};
|
|
198
202
|
// For non constant color channel.
|
|
199
|
-
if (invertAble(scaleSeries))
|
|
203
|
+
if (invertAble(scaleSeries)) {
|
|
204
|
+
const cloned = scaleSeries.clone();
|
|
205
|
+
return cloned.invert(series);
|
|
206
|
+
}
|
|
200
207
|
if (
|
|
201
208
|
series &&
|
|
202
209
|
scaleSeries instanceof Band &&
|
|
@@ -232,6 +239,7 @@ function groupItems(
|
|
|
232
239
|
scale,
|
|
233
240
|
groupName,
|
|
234
241
|
data = elements.map((d) => d['__data__']),
|
|
242
|
+
theme: Record<string, any> = {},
|
|
235
243
|
) {
|
|
236
244
|
const key = (d) => (d instanceof Date ? +d : d);
|
|
237
245
|
const T = unique(
|
|
@@ -249,10 +257,9 @@ function groupItems(
|
|
|
249
257
|
groupName !== undefined ? groupName : items.length <= 1 ? true : false;
|
|
250
258
|
|
|
251
259
|
return definedItems.map(
|
|
252
|
-
({ color = itemColorOf(element), name, ...item }) => {
|
|
253
|
-
const
|
|
254
|
-
|
|
255
|
-
: name || groupNameOf(scale, datum);
|
|
260
|
+
({ color = itemColorOf(element) || theme.color, name, ...item }) => {
|
|
261
|
+
const groupName = groupNameOf(scale, datum);
|
|
262
|
+
const name1 = useGroupName ? groupName || name : name || groupName;
|
|
256
263
|
return {
|
|
257
264
|
...item,
|
|
258
265
|
color,
|
|
@@ -343,30 +350,34 @@ function hideRuleY(root) {
|
|
|
343
350
|
}
|
|
344
351
|
}
|
|
345
352
|
|
|
346
|
-
|
|
347
|
-
function updateMarker(root, { data, style }) {
|
|
353
|
+
function updateMarker(root, { data, style, theme }) {
|
|
348
354
|
if (root.markers) root.markers.forEach((d) => d.remove());
|
|
349
|
-
const markers = data
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
355
|
+
const markers = data
|
|
356
|
+
.filter((d) => {
|
|
357
|
+
const [{ x, y }] = d;
|
|
358
|
+
return defined(x) && defined(y);
|
|
359
|
+
})
|
|
360
|
+
.map((d) => {
|
|
361
|
+
const [{ color, element }, point] = d;
|
|
362
|
+
const fill =
|
|
363
|
+
color || // encode value
|
|
364
|
+
element.style.fill ||
|
|
365
|
+
element.style.stroke ||
|
|
366
|
+
theme.color;
|
|
367
|
+
|
|
368
|
+
const shape = new Circle({
|
|
369
|
+
style: {
|
|
370
|
+
cx: point[0],
|
|
371
|
+
cy: point[1],
|
|
372
|
+
fill,
|
|
373
|
+
r: 4,
|
|
374
|
+
stroke: '#fff',
|
|
375
|
+
strokeWidth: 2,
|
|
376
|
+
...style,
|
|
377
|
+
},
|
|
378
|
+
});
|
|
379
|
+
return shape;
|
|
367
380
|
});
|
|
368
|
-
return shape;
|
|
369
|
-
});
|
|
370
381
|
for (const marker of markers) root.appendChild(marker);
|
|
371
382
|
root.markers = markers;
|
|
372
383
|
}
|
|
@@ -428,9 +439,12 @@ export function seriesTooltip(
|
|
|
428
439
|
enterable,
|
|
429
440
|
mount,
|
|
430
441
|
bounding,
|
|
442
|
+
theme,
|
|
431
443
|
disableNative = false,
|
|
432
444
|
marker = true,
|
|
445
|
+
preserve = false,
|
|
433
446
|
style: _style = {},
|
|
447
|
+
css = {},
|
|
434
448
|
...rest
|
|
435
449
|
}: Record<string, any>,
|
|
436
450
|
) {
|
|
@@ -452,11 +466,14 @@ export function seriesTooltip(
|
|
|
452
466
|
const itemElements = [];
|
|
453
467
|
for (const element of elements) {
|
|
454
468
|
const { __data__: data } = element;
|
|
455
|
-
const { seriesX } = data;
|
|
469
|
+
const { seriesX, title, items } = data;
|
|
456
470
|
if (seriesX) seriesElements.push(element);
|
|
457
|
-
else itemElements.push(element);
|
|
471
|
+
else if (title || items) itemElements.push(element);
|
|
458
472
|
}
|
|
459
473
|
|
|
474
|
+
const isBandScale = !!(transposed ? scale.y : scale.x).getBandWidth;
|
|
475
|
+
const closest = isBandScale && itemElements.length > 0;
|
|
476
|
+
|
|
460
477
|
// Sorted elements from top to bottom visually,
|
|
461
478
|
// or from right to left in transpose coordinate.
|
|
462
479
|
seriesElements.sort((a, b) => {
|
|
@@ -465,6 +482,20 @@ export function seriesTooltip(
|
|
|
465
482
|
return transposed ? minY(b) - minY(a) : minY(a) - minY(b);
|
|
466
483
|
});
|
|
467
484
|
|
|
485
|
+
const extent = (d) => {
|
|
486
|
+
const index = transposed ? 1 : 0;
|
|
487
|
+
const { min, max } = d.getLocalBounds();
|
|
488
|
+
return sort([min[index], max[index]]);
|
|
489
|
+
};
|
|
490
|
+
// Sort itemElements by x or y.
|
|
491
|
+
itemElements.sort((a, b) => {
|
|
492
|
+
const [minA, maxA] = extent(a);
|
|
493
|
+
const [minB, maxB] = extent(b);
|
|
494
|
+
const midA = (minA + maxA) / 2;
|
|
495
|
+
const midB = (minB + maxB) / 2;
|
|
496
|
+
return transposed ? midB - midA : midA - midB;
|
|
497
|
+
});
|
|
498
|
+
|
|
468
499
|
// Get sortedIndex and X for each series elements
|
|
469
500
|
const elementSortedX = new Map(
|
|
470
501
|
seriesElements.map((element) => {
|
|
@@ -489,8 +520,9 @@ export function seriesTooltip(
|
|
|
489
520
|
const indexByFocus = (focus, I, X) => {
|
|
490
521
|
const finalX = abstractX(focus);
|
|
491
522
|
const [minX, maxX] = sort([X[0], X[X.length - 1]]);
|
|
492
|
-
//
|
|
493
|
-
|
|
523
|
+
// If closest is true, always find at least one element.
|
|
524
|
+
// Otherwise, skip element out of plot area.
|
|
525
|
+
if (!closest && (finalX < minX || finalX > maxX)) return null;
|
|
494
526
|
const search = bisector((i) => X[+i]).center;
|
|
495
527
|
const i = search(I, finalX);
|
|
496
528
|
return I[i];
|
|
@@ -499,14 +531,20 @@ export function seriesTooltip(
|
|
|
499
531
|
const elementsByFocus = (focus, elements) => {
|
|
500
532
|
const index = transposed ? 1 : 0;
|
|
501
533
|
const x = focus[index];
|
|
502
|
-
const
|
|
503
|
-
const { min, max } = d.getLocalBounds();
|
|
504
|
-
return sort([min[index], max[index]]);
|
|
505
|
-
};
|
|
506
|
-
return elements.filter((element) => {
|
|
534
|
+
const filtered = elements.filter((element) => {
|
|
507
535
|
const [min, max] = extent(element);
|
|
508
536
|
return x >= min && x <= max;
|
|
509
537
|
});
|
|
538
|
+
// If closet is true, always find at least one element.
|
|
539
|
+
if (!closest || filtered.length > 0) return filtered;
|
|
540
|
+
|
|
541
|
+
// Search the closet element to the focus.
|
|
542
|
+
const search = bisector((element) => {
|
|
543
|
+
const [min, max] = extent(element);
|
|
544
|
+
return (min + max) / 2;
|
|
545
|
+
}).center;
|
|
546
|
+
const i = search(elements, x);
|
|
547
|
+
return [elements[i]].filter(defined);
|
|
510
548
|
};
|
|
511
549
|
|
|
512
550
|
const seriesData = (element, index) => {
|
|
@@ -568,6 +606,7 @@ export function seriesTooltip(
|
|
|
568
606
|
scale,
|
|
569
607
|
groupName,
|
|
570
608
|
selectedData,
|
|
609
|
+
theme,
|
|
571
610
|
);
|
|
572
611
|
|
|
573
612
|
// Sort items and filter items.
|
|
@@ -597,6 +636,7 @@ export function seriesTooltip(
|
|
|
597
636
|
enterable,
|
|
598
637
|
mount,
|
|
599
638
|
bounding,
|
|
639
|
+
css,
|
|
600
640
|
});
|
|
601
641
|
}
|
|
602
642
|
|
|
@@ -623,6 +663,7 @@ export function seriesTooltip(
|
|
|
623
663
|
updateMarker(root, {
|
|
624
664
|
data: filteredSeriesData,
|
|
625
665
|
style: markerStyles,
|
|
666
|
+
theme,
|
|
626
667
|
});
|
|
627
668
|
}
|
|
628
669
|
|
|
@@ -702,7 +743,11 @@ export function seriesTooltip(
|
|
|
702
743
|
emitter.off('tooltip:hide', onTooltipHide);
|
|
703
744
|
emitter.off('tooltip:disable', onTooltipDisable);
|
|
704
745
|
emitter.off('tooltip:enable', onTooltipEnable);
|
|
705
|
-
|
|
746
|
+
if (preserve) {
|
|
747
|
+
hideTooltip({ root, single, emitter, nativeEvent: false });
|
|
748
|
+
} else {
|
|
749
|
+
destroy();
|
|
750
|
+
}
|
|
706
751
|
};
|
|
707
752
|
}
|
|
708
753
|
|
|
@@ -730,9 +775,12 @@ export function tooltip(
|
|
|
730
775
|
view,
|
|
731
776
|
mount,
|
|
732
777
|
bounding,
|
|
778
|
+
theme,
|
|
733
779
|
shared = false,
|
|
734
780
|
body = true,
|
|
735
781
|
disableNative = false,
|
|
782
|
+
preserve = false,
|
|
783
|
+
css = {},
|
|
736
784
|
}: Record<string, any>,
|
|
737
785
|
) {
|
|
738
786
|
const elements = elementsof(root);
|
|
@@ -751,7 +799,7 @@ export function tooltip(
|
|
|
751
799
|
const data =
|
|
752
800
|
group.length === 1 && !shared
|
|
753
801
|
? singleItem(group[0])
|
|
754
|
-
: groupItems(group, scale, groupName);
|
|
802
|
+
: groupItems(group, scale, groupName, undefined, theme);
|
|
755
803
|
|
|
756
804
|
// Sort items and sort.
|
|
757
805
|
if (sortFunction) {
|
|
@@ -780,6 +828,7 @@ export function tooltip(
|
|
|
780
828
|
enterable,
|
|
781
829
|
mount,
|
|
782
830
|
bounding,
|
|
831
|
+
css,
|
|
783
832
|
});
|
|
784
833
|
}
|
|
785
834
|
|
|
@@ -856,7 +905,11 @@ export function tooltip(
|
|
|
856
905
|
removeEventListeners();
|
|
857
906
|
emitter.off('tooltip:show', onTooltipShow);
|
|
858
907
|
emitter.off('tooltip:hide', onTooltipHide);
|
|
859
|
-
|
|
908
|
+
if (preserve) {
|
|
909
|
+
hideTooltip({ root, single, emitter, nativeEvent: false });
|
|
910
|
+
} else {
|
|
911
|
+
destroyTooltip({ root, single });
|
|
912
|
+
}
|
|
860
913
|
};
|
|
861
914
|
}
|
|
862
915
|
|
|
@@ -872,7 +925,7 @@ export function Tooltip(options) {
|
|
|
872
925
|
} = options;
|
|
873
926
|
return (target, viewInstances, emitter) => {
|
|
874
927
|
const { container, view } = target;
|
|
875
|
-
const { scale, markState, coordinate } = view;
|
|
928
|
+
const { scale, markState, coordinate, theme } = view;
|
|
876
929
|
// Get default value from mark states.
|
|
877
930
|
const defaultSeries = interactionKeyof(markState, 'seriesTooltip');
|
|
878
931
|
const defaultShowCrosshairs = interactionKeyof(markState, 'crosshairs');
|
|
@@ -883,6 +936,7 @@ export function Tooltip(options) {
|
|
|
883
936
|
if (isSeries && hasSeries(markState) && !facet) {
|
|
884
937
|
return seriesTooltip(plotArea, {
|
|
885
938
|
...rest,
|
|
939
|
+
theme,
|
|
886
940
|
elements: selectG2Elements,
|
|
887
941
|
scale,
|
|
888
942
|
coordinate,
|
|
@@ -911,6 +965,7 @@ export function Tooltip(options) {
|
|
|
911
965
|
// @ts-ignore
|
|
912
966
|
return seriesTooltip(plotArea.parentNode.parentNode, {
|
|
913
967
|
...rest,
|
|
968
|
+
theme,
|
|
914
969
|
elements: () => elements,
|
|
915
970
|
scale,
|
|
916
971
|
coordinate,
|
|
@@ -932,6 +987,7 @@ export function Tooltip(options) {
|
|
|
932
987
|
item,
|
|
933
988
|
emitter,
|
|
934
989
|
view,
|
|
990
|
+
theme,
|
|
935
991
|
shared,
|
|
936
992
|
});
|
|
937
993
|
};
|
package/src/lib/core.ts
CHANGED
|
@@ -50,7 +50,7 @@ import {
|
|
|
50
50
|
Sequential as ScaleSequential,
|
|
51
51
|
Constant as ScaleConstant,
|
|
52
52
|
} from '../scale';
|
|
53
|
-
import { Classic, ClassicDark, Academy, Light } from '../theme';
|
|
53
|
+
import { Classic, ClassicDark, Academy, Light, Dark } from '../theme';
|
|
54
54
|
import {
|
|
55
55
|
AxisX,
|
|
56
56
|
AxisY,
|
|
@@ -252,6 +252,7 @@ export function corelib() {
|
|
|
252
252
|
'theme.classicDark': ClassicDark,
|
|
253
253
|
'theme.academy': Academy,
|
|
254
254
|
'theme.light': Light,
|
|
255
|
+
'theme.dark': Dark,
|
|
255
256
|
'component.axisX': AxisX,
|
|
256
257
|
'component.axisY': AxisY,
|
|
257
258
|
'component.legendCategory': LegendCategory,
|
package/src/lib/threed.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Cartesian3D } from '../coordinate';
|
|
2
2
|
import { AxisZ } from '../component';
|
|
3
|
-
import { Point3D, Line3D } from '../mark';
|
|
3
|
+
import { Point3D, Line3D, Interval3D } from '../mark';
|
|
4
4
|
|
|
5
5
|
export function threedlib() {
|
|
6
6
|
return {
|
|
@@ -8,5 +8,6 @@ export function threedlib() {
|
|
|
8
8
|
'component.axisZ': AxisZ,
|
|
9
9
|
'mark.point3D': Point3D,
|
|
10
10
|
'mark.line3D': Line3D,
|
|
11
|
+
'mark.interval3D': Interval3D,
|
|
11
12
|
} as const;
|
|
12
13
|
}
|
package/src/mark/index.ts
CHANGED
|
@@ -4,6 +4,7 @@ export { Line } from './line';
|
|
|
4
4
|
export { Line3D } from './line3D';
|
|
5
5
|
export { Point } from './point';
|
|
6
6
|
export { Point3D } from './point3D';
|
|
7
|
+
export { Interval3D } from './interval3D';
|
|
7
8
|
export { Text } from './text';
|
|
8
9
|
export { Cell } from './cell';
|
|
9
10
|
export { Area } from './area';
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { Coordinate3D } from '@antv/coord';
|
|
2
|
+
import { Band } from '@antv/scale';
|
|
3
|
+
import { MarkComponent as MC, Vector3 } from '../runtime';
|
|
4
|
+
import { PointMark } from '../spec';
|
|
5
|
+
import {
|
|
6
|
+
MaybeZeroX,
|
|
7
|
+
MaybeZeroY,
|
|
8
|
+
MaybeZeroZ,
|
|
9
|
+
MaybeSize,
|
|
10
|
+
MaybeZeroY1,
|
|
11
|
+
} from '../transform';
|
|
12
|
+
import { Sphere, IntervalCube } from '../shape';
|
|
13
|
+
import {
|
|
14
|
+
baseGeometryChannels,
|
|
15
|
+
basePostInference,
|
|
16
|
+
basePreInference,
|
|
17
|
+
tooltip3d,
|
|
18
|
+
} from './utils';
|
|
19
|
+
|
|
20
|
+
export type PointOptions = Omit<PointMark, 'type'>;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Convert value for each channel to rect shapes.
|
|
24
|
+
* return two 3D points, which represents the bounding box of a rect.
|
|
25
|
+
*/
|
|
26
|
+
export const Interval3D: MC<PointOptions> = (options) => {
|
|
27
|
+
return (index, scale, value, coordinate) => {
|
|
28
|
+
const {
|
|
29
|
+
x: X,
|
|
30
|
+
y: Y,
|
|
31
|
+
y1: Y1,
|
|
32
|
+
z: Z,
|
|
33
|
+
size: SZ,
|
|
34
|
+
dx: DX,
|
|
35
|
+
dy: DY,
|
|
36
|
+
dz: DZ,
|
|
37
|
+
} = value;
|
|
38
|
+
|
|
39
|
+
// The scales for x and series channels must be band scale.
|
|
40
|
+
const x = scale.x as Band;
|
|
41
|
+
const z = scale.x as Band;
|
|
42
|
+
const [width, height, depth] = (
|
|
43
|
+
coordinate as unknown as Coordinate3D
|
|
44
|
+
).getSize();
|
|
45
|
+
const x1x2 = (x: number, w: number, i: number) => [x, x + w];
|
|
46
|
+
|
|
47
|
+
// Calc the points of bounding box for the interval.
|
|
48
|
+
// They are start from left-top corner in clock wise order.
|
|
49
|
+
// TODO: series support
|
|
50
|
+
const P = Array.from(index, (i) => {
|
|
51
|
+
const groupWidthX = bandWidth(x, X[i]);
|
|
52
|
+
const groupWidthZ = bandWidth(z, Z[i]);
|
|
53
|
+
const x0 = +X[i];
|
|
54
|
+
const z0 = +Z[i];
|
|
55
|
+
const [x1, x2] = x1x2(x0, groupWidthX, i);
|
|
56
|
+
const [z1, z2] = x1x2(z0, groupWidthZ, i);
|
|
57
|
+
const y1 = +Y[i];
|
|
58
|
+
const y2 = +Y1[i];
|
|
59
|
+
|
|
60
|
+
const p1 = [x1, y1, z1];
|
|
61
|
+
const p2 = [x2, y2, z2];
|
|
62
|
+
|
|
63
|
+
return [
|
|
64
|
+
(coordinate as unknown as Coordinate3D).map([...p1]),
|
|
65
|
+
(coordinate as unknown as Coordinate3D).map([...p2]),
|
|
66
|
+
];
|
|
67
|
+
});
|
|
68
|
+
return [index, P];
|
|
69
|
+
};
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
function bandWidth(scale: Band, xz: any): number {
|
|
73
|
+
return scale.getBandWidth(scale.invert(xz));
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const shape = {
|
|
77
|
+
cube: IntervalCube,
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
Interval3D.props = {
|
|
81
|
+
defaultShape: 'cube',
|
|
82
|
+
defaultLabelShape: 'label',
|
|
83
|
+
composite: false,
|
|
84
|
+
shape,
|
|
85
|
+
channels: [
|
|
86
|
+
...baseGeometryChannels({ shapes: Object.keys(shape) }),
|
|
87
|
+
{ name: 'x', scale: 'band', required: true },
|
|
88
|
+
{ name: 'z', scale: 'band', required: true },
|
|
89
|
+
{ name: 'y', required: true },
|
|
90
|
+
{ name: 'series', scale: 'band' },
|
|
91
|
+
{ name: 'size' },
|
|
92
|
+
],
|
|
93
|
+
preInference: [
|
|
94
|
+
...basePreInference(),
|
|
95
|
+
{ type: MaybeZeroX },
|
|
96
|
+
{ type: MaybeZeroY1 },
|
|
97
|
+
{ type: MaybeZeroZ },
|
|
98
|
+
],
|
|
99
|
+
postInference: [...basePostInference(), { type: MaybeSize }, ...tooltip3d()],
|
|
100
|
+
};
|