@antv/g2 5.1.15-beta.2 → 5.1.15-beta.3

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 (106) hide show
  1. package/dist/g2.lite.min.js +1 -1
  2. package/dist/g2.min.js +1 -1
  3. package/esm/animation/growInX.js +4 -2
  4. package/esm/animation/growInX.js.map +1 -1
  5. package/esm/animation/growInY.js +4 -2
  6. package/esm/animation/growInY.js.map +1 -1
  7. package/esm/animation/waveIn.js +2 -5
  8. package/esm/animation/waveIn.js.map +1 -1
  9. package/esm/index.d.ts +2 -0
  10. package/esm/interaction/brushAxisHighlight.js +4 -3
  11. package/esm/interaction/brushAxisHighlight.js.map +1 -1
  12. package/esm/interaction/brushHighlight.js +4 -5
  13. package/esm/interaction/brushHighlight.js.map +1 -1
  14. package/esm/interaction/elementPointMove.d.ts +9 -0
  15. package/esm/interaction/elementPointMove.js +506 -0
  16. package/esm/interaction/elementPointMove.js.map +1 -0
  17. package/esm/interaction/event.js +1 -8
  18. package/esm/interaction/event.js.map +1 -1
  19. package/esm/interaction/index.d.ts +1 -0
  20. package/esm/interaction/index.js +1 -0
  21. package/esm/interaction/index.js.map +1 -1
  22. package/esm/interaction/tooltip.js +11 -4
  23. package/esm/interaction/tooltip.js.map +1 -1
  24. package/esm/interaction/treemapDrillDown.js +1 -4
  25. package/esm/interaction/treemapDrillDown.js.map +1 -1
  26. package/esm/interaction/utils.d.ts +8 -2
  27. package/esm/interaction/utils.js +49 -7
  28. package/esm/interaction/utils.js.map +1 -1
  29. package/esm/lib/core.d.ts +2 -1
  30. package/esm/lib/core.js +2 -1
  31. package/esm/lib/core.js.map +1 -1
  32. package/esm/lib/std.d.ts +1 -0
  33. package/esm/mark/point.js +2 -1
  34. package/esm/mark/point.js.map +1 -1
  35. package/esm/runtime/scale.js +3 -3
  36. package/esm/runtime/scale.js.map +1 -1
  37. package/esm/shape/index.d.ts +1 -0
  38. package/esm/shape/index.js +1 -0
  39. package/esm/shape/index.js.map +1 -1
  40. package/esm/shape/point/circle.d.ts +6 -0
  41. package/esm/shape/point/circle.js +52 -0
  42. package/esm/shape/point/circle.js.map +1 -0
  43. package/esm/shape/point/color.d.ts +2 -0
  44. package/esm/shape/point/color.js +1 -1
  45. package/esm/shape/point/color.js.map +1 -1
  46. package/lib/animation/growInX.js +4 -2
  47. package/lib/animation/growInX.js.map +1 -1
  48. package/lib/animation/growInY.js +4 -2
  49. package/lib/animation/growInY.js.map +1 -1
  50. package/lib/animation/waveIn.js +2 -5
  51. package/lib/animation/waveIn.js.map +1 -1
  52. package/lib/index.d.ts +2 -0
  53. package/lib/interaction/brushAxisHighlight.js +4 -3
  54. package/lib/interaction/brushAxisHighlight.js.map +1 -1
  55. package/lib/interaction/brushHighlight.js +4 -5
  56. package/lib/interaction/brushHighlight.js.map +1 -1
  57. package/lib/interaction/elementPointMove.d.ts +9 -0
  58. package/lib/interaction/elementPointMove.js +510 -0
  59. package/lib/interaction/elementPointMove.js.map +1 -0
  60. package/lib/interaction/event.js +4 -11
  61. package/lib/interaction/event.js.map +1 -1
  62. package/lib/interaction/index.d.ts +1 -0
  63. package/lib/interaction/index.js +3 -1
  64. package/lib/interaction/index.js.map +1 -1
  65. package/lib/interaction/tooltip.js +10 -3
  66. package/lib/interaction/tooltip.js.map +1 -1
  67. package/lib/interaction/treemapDrillDown.js +2 -5
  68. package/lib/interaction/treemapDrillDown.js.map +1 -1
  69. package/lib/interaction/utils.d.ts +8 -2
  70. package/lib/interaction/utils.js +54 -7
  71. package/lib/interaction/utils.js.map +1 -1
  72. package/lib/lib/core.d.ts +2 -1
  73. package/lib/lib/core.js +1 -0
  74. package/lib/lib/core.js.map +1 -1
  75. package/lib/lib/std.d.ts +1 -0
  76. package/lib/mark/point.js +1 -0
  77. package/lib/mark/point.js.map +1 -1
  78. package/lib/runtime/scale.js +3 -3
  79. package/lib/runtime/scale.js.map +1 -1
  80. package/lib/shape/index.d.ts +1 -0
  81. package/lib/shape/index.js +4 -2
  82. package/lib/shape/index.js.map +1 -1
  83. package/lib/shape/point/circle.d.ts +6 -0
  84. package/lib/shape/point/circle.js +56 -0
  85. package/lib/shape/point/circle.js.map +1 -0
  86. package/lib/shape/point/color.d.ts +2 -0
  87. package/lib/shape/point/color.js +2 -1
  88. package/lib/shape/point/color.js.map +1 -1
  89. package/package.json +12 -12
  90. package/src/animation/growInX.ts +9 -2
  91. package/src/animation/growInY.ts +9 -2
  92. package/src/animation/waveIn.ts +2 -5
  93. package/src/interaction/brushAxisHighlight.ts +4 -4
  94. package/src/interaction/brushHighlight.ts +8 -5
  95. package/src/interaction/elementPointMove.ts +659 -0
  96. package/src/interaction/event.ts +1 -7
  97. package/src/interaction/index.ts +1 -0
  98. package/src/interaction/tooltip.ts +11 -3
  99. package/src/interaction/treemapDrillDown.ts +1 -5
  100. package/src/interaction/utils.ts +68 -7
  101. package/src/lib/core.ts +2 -0
  102. package/src/mark/point.ts +2 -0
  103. package/src/runtime/scale.ts +3 -3
  104. package/src/shape/index.ts +1 -0
  105. package/src/shape/point/circle.ts +56 -0
  106. package/src/shape/point/color.ts +1 -1
@@ -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,13 +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') {
47
- return node.getBounds();
48
- // }
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();
49
50
 
50
- // const { x = 0, y = 0, width, height } = node.style;
51
- // return { min: [x, y], max: [x + width, y + height] };
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;
52
56
  }
53
57
 
54
58
  export function mousePosition(target, event) {
@@ -471,3 +475,60 @@ export function selectElementByData(elements, data, datum) {
471
475
  Object.entries(data).every(([key, value]) => datum(d)[key] === value),
472
476
  );
473
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,
package/src/mark/point.ts CHANGED
@@ -20,6 +20,7 @@ import {
20
20
  PointShape,
21
21
  PointTick,
22
22
  PointTriangle,
23
+ PointCircle,
23
24
  } from '../shape';
24
25
  import { MaybeZeroX, MaybeZeroY, MaybeSize } from '../transform';
25
26
  import {
@@ -50,6 +51,7 @@ const shape = {
50
51
  line: PointLine,
51
52
  tick: PointTick,
52
53
  triangleDown: PointTriangleDown,
54
+ circle: PointCircle,
53
55
  };
54
56
 
55
57
  export type PointOptions = Omit<PointMark, 'type'>;
@@ -360,13 +360,13 @@ function inferScaleRange(
360
360
  case 'sqrt': {
361
361
  const colors = categoricalColors(values, options, domain, theme, library);
362
362
  const [r0, r1] = inferRangeQ(name, colors);
363
- return [rangeMin || r0, rangeMax || r1];
363
+ return [rangeMin ?? r0, rangeMax ?? r1];
364
364
  }
365
365
  case 'band':
366
366
  case 'point': {
367
367
  const min = name === 'size' ? 5 : 0;
368
368
  const max = name === 'size' ? 10 : 1;
369
- return [rangeMin || min, rangeMax || max];
369
+ return [rangeMin ?? min, rangeMax ?? max];
370
370
  }
371
371
  case 'ordinal': {
372
372
  return categoricalColors(values, options, domain, theme, library);
@@ -565,7 +565,7 @@ function inferDomainC(values: Primitive[][]) {
565
565
  }
566
566
 
567
567
  function inferDomainO(values: Primitive[][]) {
568
- return inferDomainC(values).sort();
568
+ return values.flat().sort();
569
569
  }
570
570
 
571
571
  function inferDomainS(values: Primitive[][]) {
@@ -29,6 +29,7 @@ export { Square as PointSquare } from './point/square';
29
29
  export { Tick as PointTick } from './point/tick';
30
30
  export { Triangle as PointTriangle } from './point/triangle';
31
31
  export { TriangleDown as PointTriangleDown } from './point/triangleDown';
32
+ export { Circle as PointCircle } from './point/circle';
32
33
  export { Vector as VectorShape } from './vector/vector';
33
34
  export { Text as TextShape } from './text/text';
34
35
  export { Badge as TextBadge } from './text/badge';
@@ -0,0 +1,56 @@
1
+ import { ShapeComponent as SC } from '../../runtime';
2
+ import { select } from '../../utils/selection';
3
+ import { applyStyle, getOrigin, toOpacityKey } from '../utils';
4
+ import { getRadius } from './color';
5
+
6
+ export type PointOptions = Record<string, any>;
7
+
8
+ type ColorOptions = {
9
+ colorAttribute: 'fill' | 'stroke';
10
+ mode?: 'fixed' | 'auto' | 'normal';
11
+ [key: string]: any;
12
+ };
13
+
14
+ /**
15
+ * Render point in different coordinate.
16
+ */
17
+ const Color: SC<ColorOptions> = (options, context) => {
18
+ // Render border only when colorAttribute is stroke.
19
+ const { colorAttribute, mode = 'auto', ...style } = options;
20
+
21
+ const { coordinate, document } = context;
22
+ return (points, value, defaults) => {
23
+ const { lineWidth, color: defaultColor } = defaults;
24
+ const finalLineWidth = style.stroke ? lineWidth || 1 : lineWidth;
25
+ const { color = defaultColor, transform, opacity } = value;
26
+ const [cx, cy] = getOrigin(points);
27
+ const r = getRadius(mode, points, value, coordinate);
28
+ const finalRadius = r || style.r || defaults.r;
29
+ return select(document.createElement('circle', {}))
30
+ .call(applyStyle, defaults)
31
+ .style('fill', 'transparent')
32
+ .style('cx', cx)
33
+ .style('cy', cy)
34
+ .style('r', finalRadius)
35
+ .style('lineWidth', finalLineWidth)
36
+ .style('transform', transform)
37
+ .style('transformOrigin', `${cx} ${cy}`)
38
+ .style('stroke', color)
39
+ .style(toOpacityKey(options), opacity)
40
+ .style(colorAttribute, color)
41
+ .call(applyStyle, style)
42
+ .node();
43
+ };
44
+ };
45
+
46
+ /**
47
+ * ●
48
+ */
49
+ export const Circle: SC<PointOptions> = (options, context) => {
50
+ return Color({ colorAttribute: 'fill', ...options }, context);
51
+ };
52
+
53
+ Circle.props = {
54
+ defaultMarker: 'circle',
55
+ ...Color.props,
56
+ };
@@ -12,7 +12,7 @@ export type ColorOptions = {
12
12
  [key: string]: any;
13
13
  };
14
14
 
15
- function getRadius(
15
+ export function getRadius(
16
16
  mode: ColorOptions['mode'],
17
17
  points: Vector2[],
18
18
  value: Record<string, any>,