@antv/g2 5.0.8 → 5.0.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (84) hide show
  1. package/dist/g2-lite.min.js +3 -3
  2. package/dist/g2.min.js +4 -4
  3. package/esm/api/chart.d.ts +11 -2
  4. package/esm/api/chart.js +92 -44
  5. package/esm/api/chart.js.map +1 -1
  6. package/esm/api/node.d.ts +1 -0
  7. package/esm/api/node.js +11 -1
  8. package/esm/api/node.js.map +1 -1
  9. package/esm/api/utils.d.ts +8 -0
  10. package/esm/api/utils.js +146 -20
  11. package/esm/api/utils.js.map +1 -1
  12. package/esm/component/axis.js +21 -3
  13. package/esm/component/axis.js.map +1 -1
  14. package/esm/component/utils.d.ts +1 -1
  15. package/esm/component/utils.js +17 -3
  16. package/esm/component/utils.js.map +1 -1
  17. package/esm/index.d.ts +1 -1
  18. package/esm/index.js +3 -1
  19. package/esm/index.js.map +1 -1
  20. package/esm/interaction/brushHighlight.d.ts +3 -3
  21. package/esm/interaction/brushHighlight.js +12 -10
  22. package/esm/interaction/brushHighlight.js.map +1 -1
  23. package/esm/interaction/brushXHighlight.d.ts +1 -1
  24. package/esm/interaction/brushYHighlight.d.ts +1 -1
  25. package/esm/interaction/tooltip.js +5 -2
  26. package/esm/interaction/tooltip.js.map +1 -1
  27. package/esm/runtime/plot.js +21 -15
  28. package/esm/runtime/plot.js.map +1 -1
  29. package/esm/runtime/scale.js +1 -1
  30. package/esm/runtime/scale.js.map +1 -1
  31. package/esm/theme/academy.js +2 -1
  32. package/esm/theme/academy.js.map +1 -1
  33. package/esm/theme/classic.js +2 -2
  34. package/esm/theme/classic.js.map +1 -1
  35. package/esm/theme/classicDark.js +2 -2
  36. package/esm/theme/classicDark.js.map +1 -1
  37. package/lib/api/chart.d.ts +11 -2
  38. package/lib/api/chart.js +90 -42
  39. package/lib/api/chart.js.map +1 -1
  40. package/lib/api/node.d.ts +1 -0
  41. package/lib/api/node.js +11 -1
  42. package/lib/api/node.js.map +1 -1
  43. package/lib/api/utils.d.ts +8 -0
  44. package/lib/api/utils.js +149 -21
  45. package/lib/api/utils.js.map +1 -1
  46. package/lib/component/axis.js +21 -3
  47. package/lib/component/axis.js.map +1 -1
  48. package/lib/component/utils.d.ts +1 -1
  49. package/lib/component/utils.js +17 -3
  50. package/lib/component/utils.js.map +1 -1
  51. package/lib/index.d.ts +1 -1
  52. package/lib/index.js +3 -1
  53. package/lib/index.js.map +1 -1
  54. package/lib/interaction/brushHighlight.d.ts +3 -3
  55. package/lib/interaction/brushHighlight.js +12 -10
  56. package/lib/interaction/brushHighlight.js.map +1 -1
  57. package/lib/interaction/brushXHighlight.d.ts +1 -1
  58. package/lib/interaction/brushYHighlight.d.ts +1 -1
  59. package/lib/interaction/tooltip.js +5 -2
  60. package/lib/interaction/tooltip.js.map +1 -1
  61. package/lib/runtime/plot.js +21 -15
  62. package/lib/runtime/plot.js.map +1 -1
  63. package/lib/runtime/scale.js +1 -1
  64. package/lib/runtime/scale.js.map +1 -1
  65. package/lib/theme/academy.js +2 -1
  66. package/lib/theme/academy.js.map +1 -1
  67. package/lib/theme/classic.js +2 -2
  68. package/lib/theme/classic.js.map +1 -1
  69. package/lib/theme/classicDark.js +2 -2
  70. package/lib/theme/classicDark.js.map +1 -1
  71. package/package.json +2 -2
  72. package/src/api/chart.ts +104 -53
  73. package/src/api/node.ts +10 -1
  74. package/src/api/utils.ts +139 -20
  75. package/src/component/axis.ts +33 -12
  76. package/src/component/utils.ts +9 -4
  77. package/src/index.ts +10 -1
  78. package/src/interaction/brushHighlight.ts +12 -10
  79. package/src/interaction/tooltip.ts +5 -2
  80. package/src/runtime/plot.ts +43 -20
  81. package/src/runtime/scale.ts +1 -1
  82. package/src/theme/academy.ts +2 -1
  83. package/src/theme/classic.ts +2 -2
  84. package/src/theme/classicDark.ts +2 -2
@@ -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 option of inferInteraction(options)) {
234
- const interaction = useInteraction(option);
235
- const destroy = interaction(target, enterViewInstances, context.emitter);
236
- nameInteraction.set(option.type, { destroy });
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 option of inferInteraction(options)) {
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(option.type);
256
+ const prevInteraction = nameInteraction.get(type);
248
257
  if (prevInteraction) prevInteraction.destroy?.();
249
258
 
250
259
  // Apply new interaction.
251
- const interaction = useInteraction(option);
252
- const destroy = interaction(target, updateViewInstances, context.emitter);
253
- nameInteraction.set(option.type, { destroy });
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(selection, options, view, library, context) {
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.type === 'tooltip',
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(tooltipOptions);
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(view: G2View): G2InteractionOptions[] {
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>(
@@ -348,7 +348,7 @@ function inferOptionsQ(
348
348
  const {
349
349
  interpolate = createInterpolateValue,
350
350
  nice = false,
351
- tickCount = 10,
351
+ tickCount = 5,
352
352
  } = options;
353
353
  return { ...options, interpolate, nice, tickCount };
354
354
  }
@@ -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: 8,
261
+ labelSpacing: 4,
261
262
  tickDirection: 'positive',
262
263
  titlePosition: 'bottom',
263
264
  titleSpacing: 4,
@@ -249,7 +249,7 @@ export const Classic: TC<ClassicOptions> = (options) => {
249
249
  axisTop: {
250
250
  gridDirection: 'positive',
251
251
  labelDirection: 'negative',
252
- labelSpacing: 8,
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: 12,
261
+ labelSpacing: 4,
262
262
  labelAutoRotate: true,
263
263
  tickDirection: 'positive',
264
264
  titlePosition: 'bottom',
@@ -248,7 +248,7 @@ export const ClassicDark: TC<ClassicDarkOptions> = (options) => {
248
248
  axisTop: {
249
249
  gridDirection: 'positive',
250
250
  labelDirection: 'negative',
251
- labelSpacing: 8,
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: 12,
260
+ labelSpacing: 4,
261
261
  tickDirection: 'positive',
262
262
  titlePosition: 'bottom',
263
263
  titleSpacing: 10,