@antv/g2 5.0.8 → 5.0.9
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 +4 -4
- package/esm/api/chart.d.ts +11 -2
- package/esm/api/chart.js +92 -44
- package/esm/api/chart.js.map +1 -1
- package/esm/api/node.d.ts +1 -0
- package/esm/api/node.js +11 -1
- package/esm/api/node.js.map +1 -1
- package/esm/api/utils.d.ts +8 -0
- package/esm/api/utils.js +146 -20
- package/esm/api/utils.js.map +1 -1
- package/esm/component/axis.js +21 -3
- package/esm/component/axis.js.map +1 -1
- package/esm/component/utils.d.ts +1 -1
- package/esm/component/utils.js +17 -3
- package/esm/component/utils.js.map +1 -1
- package/esm/interaction/brushHighlight.d.ts +3 -3
- package/esm/interaction/brushHighlight.js +12 -10
- package/esm/interaction/brushHighlight.js.map +1 -1
- package/esm/interaction/brushXHighlight.d.ts +1 -1
- package/esm/interaction/brushYHighlight.d.ts +1 -1
- package/esm/interaction/tooltip.js +5 -2
- package/esm/interaction/tooltip.js.map +1 -1
- package/esm/runtime/plot.js +21 -15
- package/esm/runtime/plot.js.map +1 -1
- package/esm/runtime/scale.js +1 -1
- package/esm/runtime/scale.js.map +1 -1
- package/esm/theme/academy.js +2 -1
- package/esm/theme/academy.js.map +1 -1
- package/esm/theme/classic.js +2 -2
- package/esm/theme/classic.js.map +1 -1
- package/esm/theme/classicDark.js +2 -2
- package/esm/theme/classicDark.js.map +1 -1
- package/lib/api/chart.d.ts +11 -2
- package/lib/api/chart.js +90 -42
- package/lib/api/chart.js.map +1 -1
- package/lib/api/node.d.ts +1 -0
- package/lib/api/node.js +11 -1
- package/lib/api/node.js.map +1 -1
- package/lib/api/utils.d.ts +8 -0
- package/lib/api/utils.js +149 -21
- package/lib/api/utils.js.map +1 -1
- package/lib/component/axis.js +21 -3
- package/lib/component/axis.js.map +1 -1
- package/lib/component/utils.d.ts +1 -1
- package/lib/component/utils.js +17 -3
- package/lib/component/utils.js.map +1 -1
- package/lib/interaction/brushHighlight.d.ts +3 -3
- package/lib/interaction/brushHighlight.js +12 -10
- package/lib/interaction/brushHighlight.js.map +1 -1
- package/lib/interaction/brushXHighlight.d.ts +1 -1
- package/lib/interaction/brushYHighlight.d.ts +1 -1
- package/lib/interaction/tooltip.js +5 -2
- package/lib/interaction/tooltip.js.map +1 -1
- package/lib/runtime/plot.js +21 -15
- package/lib/runtime/plot.js.map +1 -1
- package/lib/runtime/scale.js +1 -1
- package/lib/runtime/scale.js.map +1 -1
- package/lib/theme/academy.js +2 -1
- package/lib/theme/academy.js.map +1 -1
- package/lib/theme/classic.js +2 -2
- package/lib/theme/classic.js.map +1 -1
- package/lib/theme/classicDark.js +2 -2
- package/lib/theme/classicDark.js.map +1 -1
- package/package.json +2 -2
- package/src/api/chart.ts +104 -53
- package/src/api/node.ts +10 -1
- package/src/api/utils.ts +139 -20
- package/src/component/axis.ts +33 -12
- package/src/component/utils.ts +9 -4
- package/src/interaction/brushHighlight.ts +12 -10
- package/src/interaction/tooltip.ts +5 -2
- package/src/runtime/plot.ts +43 -20
- package/src/runtime/scale.ts +1 -1
- package/src/theme/academy.ts +2 -1
- package/src/theme/classic.ts +2 -2
- package/src/theme/classicDark.ts +2 -2
package/src/runtime/plot.ts
CHANGED
|
@@ -230,10 +230,17 @@ export async function plot<T extends G2ViewTree>(
|
|
|
230
230
|
target.container['nameInteraction'] = nameInteraction;
|
|
231
231
|
|
|
232
232
|
// Apply interactions.
|
|
233
|
-
for (const
|
|
234
|
-
const
|
|
235
|
-
|
|
236
|
-
|
|
233
|
+
for (const typeOption of inferInteraction(options)) {
|
|
234
|
+
const [type, option] = typeOption;
|
|
235
|
+
if (option) {
|
|
236
|
+
const interaction = useInteraction({ type, ...(option as any) });
|
|
237
|
+
const destroy = interaction(
|
|
238
|
+
target,
|
|
239
|
+
enterViewInstances,
|
|
240
|
+
context.emitter,
|
|
241
|
+
);
|
|
242
|
+
nameInteraction.set(type, { destroy });
|
|
243
|
+
}
|
|
237
244
|
}
|
|
238
245
|
}
|
|
239
246
|
|
|
@@ -242,15 +249,23 @@ export async function plot<T extends G2ViewTree>(
|
|
|
242
249
|
for (const target of updateViewInstances) {
|
|
243
250
|
const { options, container } = target;
|
|
244
251
|
const nameInteraction = container['nameInteraction'];
|
|
245
|
-
for (const
|
|
252
|
+
for (const typeOption of inferInteraction(options)) {
|
|
253
|
+
const [type, option] = typeOption;
|
|
254
|
+
|
|
246
255
|
// Remove interaction for existed views.
|
|
247
|
-
const prevInteraction = nameInteraction.get(
|
|
256
|
+
const prevInteraction = nameInteraction.get(type);
|
|
248
257
|
if (prevInteraction) prevInteraction.destroy?.();
|
|
249
258
|
|
|
250
259
|
// Apply new interaction.
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
260
|
+
if (option) {
|
|
261
|
+
const interaction = useInteraction({ type, ...(option as any) });
|
|
262
|
+
const destroy = interaction(
|
|
263
|
+
target,
|
|
264
|
+
updateViewInstances,
|
|
265
|
+
context.emitter,
|
|
266
|
+
);
|
|
267
|
+
nameInteraction.set(type, { destroy });
|
|
268
|
+
}
|
|
254
269
|
}
|
|
255
270
|
}
|
|
256
271
|
|
|
@@ -314,7 +329,13 @@ function createUpdateView(
|
|
|
314
329
|
};
|
|
315
330
|
}
|
|
316
331
|
|
|
317
|
-
function updateTooltip(
|
|
332
|
+
function updateTooltip(
|
|
333
|
+
selection: Selection,
|
|
334
|
+
options: G2ViewTree,
|
|
335
|
+
view: G2ViewDescriptor,
|
|
336
|
+
library: G2Library,
|
|
337
|
+
context: G2Context,
|
|
338
|
+
) {
|
|
318
339
|
const [useInteraction] = useLibrary<
|
|
319
340
|
G2InteractionOptions,
|
|
320
341
|
InteractionComponent,
|
|
@@ -325,7 +346,7 @@ function updateTooltip(selection, options, view, library, context) {
|
|
|
325
346
|
const container = selection.node();
|
|
326
347
|
const nameInteraction = container['nameInteraction'];
|
|
327
348
|
const tooltipOptions = inferInteraction(options).find(
|
|
328
|
-
(d) => d
|
|
349
|
+
([d]) => d === 'tooltip',
|
|
329
350
|
);
|
|
330
351
|
|
|
331
352
|
// Destroy older tooltip.
|
|
@@ -333,8 +354,13 @@ function updateTooltip(selection, options, view, library, context) {
|
|
|
333
354
|
if (!tooltip) return;
|
|
334
355
|
tooltip.destroy?.();
|
|
335
356
|
|
|
357
|
+
if (!tooltipOptions[1]) return;
|
|
358
|
+
|
|
336
359
|
// Apply new tooltip interaction.
|
|
337
|
-
const applyTooltip = useInteraction(
|
|
360
|
+
const applyTooltip = useInteraction({
|
|
361
|
+
type: 'tooltip',
|
|
362
|
+
...(tooltipOptions[1] as any),
|
|
363
|
+
});
|
|
338
364
|
const target = {
|
|
339
365
|
options,
|
|
340
366
|
view,
|
|
@@ -1082,7 +1108,7 @@ function createLabelShapeFunction(
|
|
|
1082
1108
|
);
|
|
1083
1109
|
const { shape = defaultLabelShape, text, ...style } = visualOptions;
|
|
1084
1110
|
const f = typeof formatter === 'string' ? format(formatter) : formatter;
|
|
1085
|
-
const value = { ...style, text: f(text) };
|
|
1111
|
+
const value = { ...style, text: f(text, datum, index, abstractData) };
|
|
1086
1112
|
const shapeFunction = useShape({ type: `label.${shape}`, ...style });
|
|
1087
1113
|
return shapeFunction(points, value, coordinate, theme, point2d);
|
|
1088
1114
|
};
|
|
@@ -1351,7 +1377,9 @@ function inferTheme(theme: G2ThemeOptions = {}): G2ThemeOptions {
|
|
|
1351
1377
|
/**
|
|
1352
1378
|
* @todo Infer builtin tooltips.
|
|
1353
1379
|
*/
|
|
1354
|
-
function inferInteraction(
|
|
1380
|
+
function inferInteraction(
|
|
1381
|
+
view: G2View,
|
|
1382
|
+
): [string, boolean | Omit<G2InteractionOptions, 'type'>][] {
|
|
1355
1383
|
const defaults = {
|
|
1356
1384
|
event: true,
|
|
1357
1385
|
tooltip: true,
|
|
@@ -1360,12 +1388,7 @@ function inferInteraction(view: G2View): G2InteractionOptions[] {
|
|
|
1360
1388
|
legendFilter: true,
|
|
1361
1389
|
};
|
|
1362
1390
|
const { interaction = {} } = view;
|
|
1363
|
-
return Object.entries(deepMix(defaults, interaction))
|
|
1364
|
-
.filter((d) => !!d[1])
|
|
1365
|
-
.map(([key, value]) => ({
|
|
1366
|
-
type: key,
|
|
1367
|
-
...(value as Record<string, any>),
|
|
1368
|
-
}));
|
|
1391
|
+
return Object.entries(deepMix(defaults, interaction));
|
|
1369
1392
|
}
|
|
1370
1393
|
|
|
1371
1394
|
async function applyTransform<T extends G2ViewTree>(
|
package/src/runtime/scale.ts
CHANGED
package/src/theme/academy.ts
CHANGED
|
@@ -253,11 +253,12 @@ export const Academy: TC<AcademyOptions> = (options) => {
|
|
|
253
253
|
titlePosition: 'top',
|
|
254
254
|
titleSpacing: 0,
|
|
255
255
|
titleTextBaseline: 'middle',
|
|
256
|
+
labelSpacing: 4,
|
|
256
257
|
},
|
|
257
258
|
axisBottom: {
|
|
258
259
|
gridDirection: 'negative',
|
|
259
260
|
labelDirection: 'positive',
|
|
260
|
-
labelSpacing:
|
|
261
|
+
labelSpacing: 4,
|
|
261
262
|
tickDirection: 'positive',
|
|
262
263
|
titlePosition: 'bottom',
|
|
263
264
|
titleSpacing: 4,
|
package/src/theme/classic.ts
CHANGED
|
@@ -249,7 +249,7 @@ export const Classic: TC<ClassicOptions> = (options) => {
|
|
|
249
249
|
axisTop: {
|
|
250
250
|
gridDirection: 'positive',
|
|
251
251
|
labelDirection: 'negative',
|
|
252
|
-
labelSpacing:
|
|
252
|
+
labelSpacing: 4,
|
|
253
253
|
tickDirection: 'negative',
|
|
254
254
|
titlePosition: 'top',
|
|
255
255
|
titleSpacing: 0,
|
|
@@ -258,7 +258,7 @@ export const Classic: TC<ClassicOptions> = (options) => {
|
|
|
258
258
|
axisBottom: {
|
|
259
259
|
gridDirection: 'negative',
|
|
260
260
|
labelDirection: 'positive',
|
|
261
|
-
labelSpacing:
|
|
261
|
+
labelSpacing: 4,
|
|
262
262
|
labelAutoRotate: true,
|
|
263
263
|
tickDirection: 'positive',
|
|
264
264
|
titlePosition: 'bottom',
|
package/src/theme/classicDark.ts
CHANGED
|
@@ -248,7 +248,7 @@ export const ClassicDark: TC<ClassicDarkOptions> = (options) => {
|
|
|
248
248
|
axisTop: {
|
|
249
249
|
gridDirection: 'positive',
|
|
250
250
|
labelDirection: 'negative',
|
|
251
|
-
labelSpacing:
|
|
251
|
+
labelSpacing: 4,
|
|
252
252
|
tickDirection: 'negative',
|
|
253
253
|
titlePosition: 'top',
|
|
254
254
|
titleSpacing: 0,
|
|
@@ -257,7 +257,7 @@ export const ClassicDark: TC<ClassicDarkOptions> = (options) => {
|
|
|
257
257
|
axisBottom: {
|
|
258
258
|
gridDirection: 'negative',
|
|
259
259
|
labelDirection: 'positive',
|
|
260
|
-
labelSpacing:
|
|
260
|
+
labelSpacing: 4,
|
|
261
261
|
tickDirection: 'positive',
|
|
262
262
|
titlePosition: 'bottom',
|
|
263
263
|
titleSpacing: 10,
|