@antv/g2 5.1.16 → 5.1.17

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 (50) hide show
  1. package/dist/g2.lite.min.js +1 -1
  2. package/dist/g2.min.js +1 -1
  3. package/esm/index.d.ts +2 -0
  4. package/esm/interaction/elementPointMove.d.ts +9 -0
  5. package/esm/interaction/elementPointMove.js +506 -0
  6. package/esm/interaction/elementPointMove.js.map +1 -0
  7. package/esm/interaction/event.js +1 -8
  8. package/esm/interaction/event.js.map +1 -1
  9. package/esm/interaction/index.d.ts +1 -0
  10. package/esm/interaction/index.js +1 -0
  11. package/esm/interaction/index.js.map +1 -1
  12. package/esm/interaction/tooltip.js +11 -4
  13. package/esm/interaction/tooltip.js.map +1 -1
  14. package/esm/interaction/treemapDrillDown.js +1 -4
  15. package/esm/interaction/treemapDrillDown.js.map +1 -1
  16. package/esm/interaction/utils.d.ts +8 -2
  17. package/esm/interaction/utils.js +49 -6
  18. package/esm/interaction/utils.js.map +1 -1
  19. package/esm/lib/core.d.ts +2 -1
  20. package/esm/lib/core.js +2 -1
  21. package/esm/lib/core.js.map +1 -1
  22. package/esm/lib/std.d.ts +1 -0
  23. package/lib/index.d.ts +2 -0
  24. package/lib/interaction/elementPointMove.d.ts +9 -0
  25. package/lib/interaction/elementPointMove.js +510 -0
  26. package/lib/interaction/elementPointMove.js.map +1 -0
  27. package/lib/interaction/event.js +4 -11
  28. package/lib/interaction/event.js.map +1 -1
  29. package/lib/interaction/index.d.ts +1 -0
  30. package/lib/interaction/index.js +3 -1
  31. package/lib/interaction/index.js.map +1 -1
  32. package/lib/interaction/tooltip.js +10 -3
  33. package/lib/interaction/tooltip.js.map +1 -1
  34. package/lib/interaction/treemapDrillDown.js +2 -5
  35. package/lib/interaction/treemapDrillDown.js.map +1 -1
  36. package/lib/interaction/utils.d.ts +8 -2
  37. package/lib/interaction/utils.js +54 -6
  38. package/lib/interaction/utils.js.map +1 -1
  39. package/lib/lib/core.d.ts +2 -1
  40. package/lib/lib/core.js +1 -0
  41. package/lib/lib/core.js.map +1 -1
  42. package/lib/lib/std.d.ts +1 -0
  43. package/package.json +1 -1
  44. package/src/interaction/elementPointMove.ts +659 -0
  45. package/src/interaction/event.ts +1 -7
  46. package/src/interaction/index.ts +1 -0
  47. package/src/interaction/tooltip.ts +11 -3
  48. package/src/interaction/treemapDrillDown.ts +1 -5
  49. package/src/interaction/utils.ts +69 -5
  50. package/src/lib/core.ts +2 -0
@@ -17,6 +17,7 @@ import {
17
17
  createDatumof,
18
18
  selectElementByData,
19
19
  bboxOf,
20
+ maybeRoot,
20
21
  } from './utils';
21
22
  import { dataOf } from './event';
22
23
 
@@ -422,6 +423,13 @@ function hasSeries(markState): boolean {
422
423
  );
423
424
  }
424
425
 
426
+ function findElement(node: DisplayObject) {
427
+ return maybeRoot(node, (node) => {
428
+ if (!node.classList) return false;
429
+ return node.classList.includes('element');
430
+ });
431
+ }
432
+
425
433
  /**
426
434
  * Show tooltip for series item.
427
435
  */
@@ -798,13 +806,13 @@ export function tooltip(
798
806
  }: Record<string, any>,
799
807
  ) {
800
808
  const elements = elementsof(root);
801
- const elementSet = new Set(elements);
802
809
  const keyGroup = group(elements, groupKey);
803
810
 
804
811
  const pointermove = throttle(
805
812
  (event) => {
806
- const { target: element } = event;
807
- if (!elementSet.has(element)) {
813
+ const { target } = event;
814
+ const element = findElement(target);
815
+ if (!element) {
808
816
  hideTooltip({ root, single, emitter, event });
809
817
  return;
810
818
  }
@@ -7,11 +7,7 @@ import { PLOT_CLASS_NAME } from '../runtime';
7
7
  import { select } from '../utils/selection';
8
8
  import { treeDataTransform } from '../utils/treeDataTransform';
9
9
  import { legendClearSetState } from './legendFilter';
10
-
11
- // Get element.
12
- const getElements = (plot) => {
13
- return plot.querySelectorAll('.element');
14
- };
10
+ import { getElements } from './utils';
15
11
 
16
12
  function selectPlotArea(root: DisplayObject): DisplayObject {
17
13
  return select(root).select(`.${PLOT_CLASS_NAME}`).node();
@@ -1,7 +1,9 @@
1
- import { DisplayObject, Path } from '@antv/g';
1
+ import { DisplayObject, Path, AABB } from '@antv/g';
2
2
  import { path as d3Path } from 'd3-path';
3
3
  import { sort } from 'd3-array';
4
4
  import { Vector2 } from '@antv/coord';
5
+ import { filter } from '@antv/util';
6
+ import type { PathArray } from '@antv/util';
5
7
  import { G2Element, select } from '../utils/selection';
6
8
  import { mapObject } from '../utils/array';
7
9
  import {
@@ -42,10 +44,15 @@ export function selectPlotArea(root: DisplayObject): DisplayObject {
42
44
  return select(root).select(`.${PLOT_CLASS_NAME}`).node();
43
45
  }
44
46
 
45
- export function bboxOf(node) {
46
- if (node.nodeName !== 'rect') return node.getRenderBounds();
47
- const { x, y, width, height } = node.style;
48
- return { min: [x, y], max: [x + width, y + height] };
47
+ export function bboxOf(element: DisplayObject) {
48
+ // The geometry bounds of a group is empty, so return the render bounds.
49
+ if (element.tagName === 'g') return element.getRenderBounds();
50
+
51
+ // Compute the geometry bounds related to the parent.
52
+ const bounds = element.getGeometryBounds();
53
+ const aabb = new AABB();
54
+ aabb.setFromTransformedAABB(bounds, element.getWorldTransform());
55
+ return aabb;
49
56
  }
50
57
 
51
58
  export function mousePosition(target, event) {
@@ -468,3 +475,60 @@ export function selectElementByData(elements, data, datum) {
468
475
  Object.entries(data).every(([key, value]) => datum(d)[key] === value),
469
476
  );
470
477
  }
478
+
479
+ export function getPointsR(point: number[], nextPoint: number[]) {
480
+ return Math.sqrt(
481
+ Math.pow(point[0] - nextPoint[0], 2) + Math.pow(point[1] - nextPoint[1], 2),
482
+ );
483
+ }
484
+
485
+ // Points create path.
486
+ export function getPointsPath(points: number[][], isClose = false) {
487
+ const path = filter(points, (d) => !!d).map((d, i) => {
488
+ return [i === 0 ? 'M' : 'L', ...d];
489
+ }) as PathArray;
490
+
491
+ if (isClose) {
492
+ path.push(['Z']);
493
+ }
494
+ return path;
495
+ }
496
+
497
+ // Get element.
498
+ export function getElements(plot) {
499
+ return plot.querySelectorAll('.element');
500
+ }
501
+
502
+ // Get Theta coordinate round path.
503
+ export function getThetaPath(
504
+ center: number[],
505
+ points: number[][],
506
+ isBig = 0,
507
+ ): PathArray {
508
+ const path = [['M', ...points[1]]];
509
+ const innerRadius = getPointsR(center, points[1]);
510
+ const outerRadius = getPointsR(center, points[0]);
511
+
512
+ if (innerRadius === 0) {
513
+ path.push(
514
+ ['L', ...points[3]],
515
+ ['A', outerRadius, outerRadius, 0, isBig, 1, ...points[0]],
516
+ ['Z'],
517
+ );
518
+ } else {
519
+ path.push(
520
+ ['A', innerRadius, innerRadius, 0, isBig, 0, ...points[2]],
521
+ ['L', ...points[3]],
522
+ ['A', outerRadius, outerRadius, 0, isBig, 1, ...points[0]],
523
+ ['Z'],
524
+ );
525
+ }
526
+ return path as PathArray;
527
+ }
528
+
529
+ export function maybeRoot(node, rootOf) {
530
+ if (rootOf(node)) return node;
531
+ let root = node.parent;
532
+ while (root && !rootOf(root)) root = root.parent;
533
+ return root;
534
+ }
package/src/lib/core.ts CHANGED
@@ -101,6 +101,7 @@ import {
101
101
  Poptip,
102
102
  ScrollbarFilter,
103
103
  TreemapDrillDown,
104
+ ElementPointMove,
104
105
  } from '../interaction';
105
106
  import {
106
107
  SpaceLayer,
@@ -301,6 +302,7 @@ export function corelib() {
301
302
  'interaction.scrollbarFilter': ScrollbarFilter,
302
303
  'interaction.poptip': Poptip,
303
304
  'interaction.treemapDrillDown': TreemapDrillDown,
305
+ 'interaction.elementPointMove': ElementPointMove,
304
306
  'composition.spaceLayer': SpaceLayer,
305
307
  'composition.spaceFlex': SpaceFlex,
306
308
  'composition.facetRect': FacetRect,