@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.
- package/dist/g2.lite.min.js +1 -1
- package/dist/g2.min.js +1 -1
- package/esm/animation/growInX.js +4 -2
- package/esm/animation/growInX.js.map +1 -1
- package/esm/animation/growInY.js +4 -2
- package/esm/animation/growInY.js.map +1 -1
- package/esm/animation/waveIn.js +2 -5
- package/esm/animation/waveIn.js.map +1 -1
- package/esm/index.d.ts +2 -0
- package/esm/interaction/brushAxisHighlight.js +4 -3
- package/esm/interaction/brushAxisHighlight.js.map +1 -1
- package/esm/interaction/brushHighlight.js +4 -5
- package/esm/interaction/brushHighlight.js.map +1 -1
- package/esm/interaction/elementPointMove.d.ts +9 -0
- package/esm/interaction/elementPointMove.js +506 -0
- package/esm/interaction/elementPointMove.js.map +1 -0
- package/esm/interaction/event.js +1 -8
- package/esm/interaction/event.js.map +1 -1
- package/esm/interaction/index.d.ts +1 -0
- package/esm/interaction/index.js +1 -0
- package/esm/interaction/index.js.map +1 -1
- package/esm/interaction/tooltip.js +11 -4
- package/esm/interaction/tooltip.js.map +1 -1
- package/esm/interaction/treemapDrillDown.js +1 -4
- package/esm/interaction/treemapDrillDown.js.map +1 -1
- package/esm/interaction/utils.d.ts +8 -2
- package/esm/interaction/utils.js +49 -7
- package/esm/interaction/utils.js.map +1 -1
- package/esm/lib/core.d.ts +2 -1
- 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/mark/point.js +2 -1
- package/esm/mark/point.js.map +1 -1
- package/esm/runtime/scale.js +3 -3
- package/esm/runtime/scale.js.map +1 -1
- package/esm/shape/index.d.ts +1 -0
- package/esm/shape/index.js +1 -0
- package/esm/shape/index.js.map +1 -1
- package/esm/shape/point/circle.d.ts +6 -0
- package/esm/shape/point/circle.js +52 -0
- package/esm/shape/point/circle.js.map +1 -0
- package/esm/shape/point/color.d.ts +2 -0
- package/esm/shape/point/color.js +1 -1
- package/esm/shape/point/color.js.map +1 -1
- package/lib/animation/growInX.js +4 -2
- package/lib/animation/growInX.js.map +1 -1
- package/lib/animation/growInY.js +4 -2
- package/lib/animation/growInY.js.map +1 -1
- package/lib/animation/waveIn.js +2 -5
- package/lib/animation/waveIn.js.map +1 -1
- package/lib/index.d.ts +2 -0
- package/lib/interaction/brushAxisHighlight.js +4 -3
- package/lib/interaction/brushAxisHighlight.js.map +1 -1
- package/lib/interaction/brushHighlight.js +4 -5
- package/lib/interaction/brushHighlight.js.map +1 -1
- package/lib/interaction/elementPointMove.d.ts +9 -0
- package/lib/interaction/elementPointMove.js +510 -0
- package/lib/interaction/elementPointMove.js.map +1 -0
- package/lib/interaction/event.js +4 -11
- package/lib/interaction/event.js.map +1 -1
- package/lib/interaction/index.d.ts +1 -0
- package/lib/interaction/index.js +3 -1
- package/lib/interaction/index.js.map +1 -1
- package/lib/interaction/tooltip.js +10 -3
- package/lib/interaction/tooltip.js.map +1 -1
- package/lib/interaction/treemapDrillDown.js +2 -5
- package/lib/interaction/treemapDrillDown.js.map +1 -1
- package/lib/interaction/utils.d.ts +8 -2
- package/lib/interaction/utils.js +54 -7
- package/lib/interaction/utils.js.map +1 -1
- package/lib/lib/core.d.ts +2 -1
- 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/mark/point.js +1 -0
- package/lib/mark/point.js.map +1 -1
- package/lib/runtime/scale.js +3 -3
- package/lib/runtime/scale.js.map +1 -1
- package/lib/shape/index.d.ts +1 -0
- package/lib/shape/index.js +4 -2
- package/lib/shape/index.js.map +1 -1
- package/lib/shape/point/circle.d.ts +6 -0
- package/lib/shape/point/circle.js +56 -0
- package/lib/shape/point/circle.js.map +1 -0
- package/lib/shape/point/color.d.ts +2 -0
- package/lib/shape/point/color.js +2 -1
- package/lib/shape/point/color.js.map +1 -1
- package/package.json +12 -12
- package/src/animation/growInX.ts +9 -2
- package/src/animation/growInY.ts +9 -2
- package/src/animation/waveIn.ts +2 -5
- package/src/interaction/brushAxisHighlight.ts +4 -4
- package/src/interaction/brushHighlight.ts +8 -5
- package/src/interaction/elementPointMove.ts +659 -0
- package/src/interaction/event.ts +1 -7
- package/src/interaction/index.ts +1 -0
- package/src/interaction/tooltip.ts +11 -3
- package/src/interaction/treemapDrillDown.ts +1 -5
- package/src/interaction/utils.ts +68 -7
- package/src/lib/core.ts +2 -0
- package/src/mark/point.ts +2 -0
- package/src/runtime/scale.ts +3 -3
- package/src/shape/index.ts +1 -0
- package/src/shape/point/circle.ts +56 -0
- 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
|
|
807
|
-
|
|
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();
|
package/src/interaction/utils.ts
CHANGED
|
@@ -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(
|
|
46
|
-
//
|
|
47
|
-
return
|
|
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
|
-
//
|
|
51
|
-
|
|
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'>;
|
package/src/runtime/scale.ts
CHANGED
|
@@ -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
|
|
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
|
|
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
|
|
568
|
+
return values.flat().sort();
|
|
569
569
|
}
|
|
570
570
|
|
|
571
571
|
function inferDomainS(values: Primitive[][]) {
|
package/src/shape/index.ts
CHANGED
|
@@ -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
|
+
};
|