@antv/g2 5.0.6 → 5.0.7
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 +4 -4
- package/dist/g2.min.js +4 -4
- package/esm/animation/morphing.js +4 -0
- package/esm/animation/morphing.js.map +1 -1
- package/esm/api/chart.d.ts +4 -7
- package/esm/api/chart.js +16 -88
- package/esm/api/chart.js.map +1 -1
- package/esm/api/utils.d.ts +10 -0
- package/esm/api/utils.js +71 -0
- package/esm/api/utils.js.map +1 -0
- package/esm/component/axis.js +15 -17
- package/esm/component/axis.js.map +1 -1
- package/esm/component/axisX.js +3 -1
- package/esm/component/axisX.js.map +1 -1
- package/esm/component/axisY.js +1 -1
- package/esm/component/axisY.js.map +1 -1
- package/esm/component/constant.js +6 -0
- package/esm/component/constant.js.map +1 -1
- package/esm/component/legendCategory.js +8 -5
- package/esm/component/legendCategory.js.map +1 -1
- package/esm/component/legendContinuous.js +91 -33
- package/esm/component/legendContinuous.js.map +1 -1
- package/esm/component/utils.d.ts +9 -5
- package/esm/component/utils.js +14 -14
- package/esm/component/utils.js.map +1 -1
- package/esm/interaction/brushFilter.js +2 -6
- package/esm/interaction/brushFilter.js.map +1 -1
- package/esm/interaction/brushHighlight.d.ts +3 -2
- package/esm/interaction/brushHighlight.js +197 -26
- package/esm/interaction/brushHighlight.js.map +1 -1
- package/esm/interaction/brushXHighlight.js +1 -1
- package/esm/interaction/brushXHighlight.js.map +1 -1
- package/esm/interaction/brushYHighlight.js +1 -1
- package/esm/interaction/brushYHighlight.js.map +1 -1
- package/esm/interaction/event.d.ts +1 -0
- package/esm/interaction/event.js +14 -12
- package/esm/interaction/event.js.map +1 -1
- package/esm/interaction/tooltip.d.ts +4 -4
- package/esm/interaction/tooltip.js +103 -31
- package/esm/interaction/tooltip.js.map +1 -1
- package/esm/mark/gauge.d.ts +7 -0
- package/esm/mark/gauge.js +4 -6
- package/esm/mark/gauge.js.map +1 -1
- package/esm/runtime/plot.js +9 -6
- package/esm/runtime/plot.js.map +1 -1
- package/esm/runtime/scale.js +2 -2
- package/esm/runtime/scale.js.map +1 -1
- package/esm/runtime/transform.js +4 -1
- package/esm/runtime/transform.js.map +1 -1
- package/esm/runtime/types/component.d.ts +1 -0
- package/esm/shape/area/area.js +1 -1
- package/esm/shape/area/area.js.map +1 -1
- package/esm/shape/area/curve.js +1 -1
- package/esm/shape/area/curve.js.map +1 -1
- package/esm/shape/connector/connector.js +1 -1
- package/esm/shape/line/curve.js +1 -1
- package/esm/shape/line/curve.js.map +1 -1
- package/esm/shape/text/advance.d.ts +1 -1
- package/esm/shape/text/advance.js +1 -1
- package/esm/shape/text/advance.js.map +1 -1
- package/esm/shape/text/badge.js +1 -1
- package/esm/shape/utils.js +1 -1
- package/esm/shape/utils.js.map +1 -1
- package/esm/spec/interaction.d.ts +3 -1
- package/esm/theme/classic.js +3 -0
- package/esm/theme/classic.js.map +1 -1
- package/esm/theme/classicDark.js +1 -0
- package/esm/theme/classicDark.js.map +1 -1
- package/esm/transform/filter.js +6 -2
- package/esm/transform/filter.js.map +1 -1
- package/esm/{shape → utils}/createElement.d.ts +1 -1
- package/esm/{shape → utils}/createElement.js.map +1 -1
- package/esm/utils/helper.d.ts +3 -0
- package/esm/utils/helper.js +3 -0
- package/esm/utils/helper.js.map +1 -1
- package/lib/animation/morphing.js +4 -0
- package/lib/animation/morphing.js.map +1 -1
- package/lib/api/chart.d.ts +4 -7
- package/lib/api/chart.js +21 -95
- package/lib/api/chart.js.map +1 -1
- package/lib/api/utils.d.ts +10 -0
- package/lib/api/utils.js +80 -0
- package/lib/api/utils.js.map +1 -0
- package/lib/component/axis.js +15 -17
- package/lib/component/axis.js.map +1 -1
- package/lib/component/axisX.js +3 -1
- package/lib/component/axisX.js.map +1 -1
- package/lib/component/axisY.js +1 -1
- package/lib/component/axisY.js.map +1 -1
- package/lib/component/constant.js +6 -0
- package/lib/component/constant.js.map +1 -1
- package/lib/component/legendCategory.js +7 -4
- package/lib/component/legendCategory.js.map +1 -1
- package/lib/component/legendContinuous.js +90 -32
- package/lib/component/legendContinuous.js.map +1 -1
- package/lib/component/utils.d.ts +9 -5
- package/lib/component/utils.js +16 -15
- package/lib/component/utils.js.map +1 -1
- package/lib/interaction/brushFilter.js +2 -6
- package/lib/interaction/brushFilter.js.map +1 -1
- package/lib/interaction/brushHighlight.d.ts +3 -2
- package/lib/interaction/brushHighlight.js +196 -25
- package/lib/interaction/brushHighlight.js.map +1 -1
- package/lib/interaction/brushXHighlight.js +1 -1
- package/lib/interaction/brushXHighlight.js.map +1 -1
- package/lib/interaction/brushYHighlight.js +1 -1
- package/lib/interaction/brushYHighlight.js.map +1 -1
- package/lib/interaction/event.d.ts +1 -0
- package/lib/interaction/event.js +15 -12
- package/lib/interaction/event.js.map +1 -1
- package/lib/interaction/tooltip.d.ts +4 -4
- package/lib/interaction/tooltip.js +102 -30
- package/lib/interaction/tooltip.js.map +1 -1
- package/lib/mark/gauge.d.ts +7 -0
- package/lib/mark/gauge.js +4 -6
- package/lib/mark/gauge.js.map +1 -1
- package/lib/runtime/plot.js +9 -6
- package/lib/runtime/plot.js.map +1 -1
- package/lib/runtime/scale.js +2 -2
- package/lib/runtime/scale.js.map +1 -1
- package/lib/runtime/transform.js +4 -1
- package/lib/runtime/transform.js.map +1 -1
- package/lib/runtime/types/component.d.ts +1 -0
- package/lib/shape/area/area.js +1 -1
- package/lib/shape/area/area.js.map +1 -1
- package/lib/shape/area/curve.js +1 -1
- package/lib/shape/area/curve.js.map +1 -1
- package/lib/shape/connector/connector.js +1 -1
- package/lib/shape/line/curve.js +1 -1
- package/lib/shape/line/curve.js.map +1 -1
- package/lib/shape/text/advance.d.ts +1 -1
- package/lib/shape/text/advance.js +1 -1
- package/lib/shape/text/advance.js.map +1 -1
- package/lib/shape/text/badge.js +1 -1
- package/lib/shape/utils.js +1 -1
- package/lib/shape/utils.js.map +1 -1
- package/lib/spec/interaction.d.ts +3 -1
- package/lib/theme/classic.js +3 -0
- package/lib/theme/classic.js.map +1 -1
- package/lib/theme/classicDark.js +1 -0
- package/lib/theme/classicDark.js.map +1 -1
- package/lib/transform/filter.js +6 -2
- package/lib/transform/filter.js.map +1 -1
- package/lib/{shape → utils}/createElement.d.ts +1 -1
- package/lib/{shape → utils}/createElement.js.map +1 -1
- package/lib/utils/helper.d.ts +3 -0
- package/lib/utils/helper.js +5 -1
- package/lib/utils/helper.js.map +1 -1
- package/package.json +3 -2
- package/src/animation/morphing.ts +5 -0
- package/src/api/chart.ts +23 -111
- package/src/api/utils.ts +79 -0
- package/src/component/axis.ts +20 -18
- package/src/component/axisX.ts +3 -1
- package/src/component/axisY.ts +2 -1
- package/src/component/constant.ts +6 -0
- package/src/component/legendCategory.ts +19 -6
- package/src/component/legendContinuous.ts +185 -74
- package/src/component/utils.ts +14 -3
- package/src/interaction/brushFilter.ts +8 -6
- package/src/interaction/brushHighlight.ts +255 -18
- package/src/interaction/brushXHighlight.ts +1 -0
- package/src/interaction/brushYHighlight.ts +1 -0
- package/src/interaction/event.ts +19 -13
- package/src/interaction/tooltip.ts +154 -25
- package/src/mark/gauge.ts +13 -7
- package/src/runtime/plot.ts +7 -5
- package/src/runtime/scale.ts +2 -2
- package/src/runtime/transform.ts +2 -1
- package/src/runtime/types/component.ts +1 -0
- package/src/shape/area/area.ts +1 -1
- package/src/shape/area/curve.ts +1 -1
- package/src/shape/connector/connector.ts +1 -1
- package/src/shape/line/curve.ts +1 -1
- package/src/shape/text/advance.ts +1 -1
- package/src/shape/text/badge.ts +1 -1
- package/src/shape/utils.ts +1 -1
- package/src/spec/interaction.ts +3 -2
- package/src/theme/classic.ts +3 -0
- package/src/theme/classicDark.ts +1 -0
- package/src/transform/filter.ts +6 -2
- package/src/{shape → utils}/createElement.ts +1 -1
- package/src/utils/helper.ts +12 -1
- /package/esm/{shape → utils}/createElement.js +0 -0
- /package/lib/{shape → utils}/createElement.js +0 -0
|
@@ -6,38 +6,71 @@ import { Constant, Identity } from '@antv/scale';
|
|
|
6
6
|
import { defined, subObject } from '../utils/helper';
|
|
7
7
|
import { isTranspose, isPolar } from '../utils/coordinate';
|
|
8
8
|
import { angle, sub } from '../utils/vector';
|
|
9
|
+
import { invert } from '../utils/scale';
|
|
10
|
+
import { BBox } from '../runtime';
|
|
9
11
|
import {
|
|
10
12
|
selectG2Elements,
|
|
11
13
|
createXKey,
|
|
12
14
|
selectPlotArea,
|
|
13
15
|
mousePosition,
|
|
14
16
|
selectFacetG2Elements,
|
|
17
|
+
createDatumof,
|
|
15
18
|
} from './utils';
|
|
16
|
-
|
|
17
|
-
|
|
19
|
+
import { dataOf } from './event';
|
|
20
|
+
|
|
21
|
+
function getContainer(
|
|
22
|
+
group: IElement,
|
|
23
|
+
mount: string | HTMLElement,
|
|
24
|
+
): HTMLElement {
|
|
25
|
+
if (mount)
|
|
26
|
+
return typeof mount === 'string' ? document.querySelector(mount) : mount;
|
|
18
27
|
// @ts-ignore
|
|
19
28
|
return group.getRootNode().defaultView.getConfig().container;
|
|
20
29
|
}
|
|
21
30
|
|
|
22
|
-
function
|
|
31
|
+
function getBounding(root): BBox {
|
|
23
32
|
const bbox = root.getBounds();
|
|
24
33
|
const {
|
|
25
|
-
min: [
|
|
26
|
-
max: [
|
|
34
|
+
min: [x1, y1],
|
|
35
|
+
max: [x2, y2],
|
|
27
36
|
} = bbox;
|
|
37
|
+
return {
|
|
38
|
+
x: x1,
|
|
39
|
+
y: y1,
|
|
40
|
+
width: x2 - x1,
|
|
41
|
+
height: y2 - y1,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function getContainerOffset(
|
|
46
|
+
container1: HTMLElement,
|
|
47
|
+
container2: HTMLElement,
|
|
48
|
+
): { x: number; y: number } {
|
|
49
|
+
const r1 = container1.getBoundingClientRect();
|
|
50
|
+
const r2 = container2.getBoundingClientRect();
|
|
51
|
+
return {
|
|
52
|
+
x: r1.x - r2.x,
|
|
53
|
+
y: r1.y - r2.y,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function createTooltip(
|
|
58
|
+
container: HTMLElement,
|
|
59
|
+
x0,
|
|
60
|
+
y0,
|
|
61
|
+
position,
|
|
62
|
+
enterable,
|
|
63
|
+
bounding,
|
|
64
|
+
containerOffset,
|
|
65
|
+
) {
|
|
28
66
|
const tooltipElement = new TooltipComponent({
|
|
29
67
|
className: 'tooltip',
|
|
30
68
|
style: {
|
|
31
69
|
x: x0,
|
|
32
70
|
y: y0,
|
|
33
|
-
container:
|
|
71
|
+
container: containerOffset,
|
|
34
72
|
data: [],
|
|
35
|
-
bounding
|
|
36
|
-
x,
|
|
37
|
-
y,
|
|
38
|
-
width: x1 - x,
|
|
39
|
-
height: y1 - y,
|
|
40
|
-
},
|
|
73
|
+
bounding,
|
|
41
74
|
position,
|
|
42
75
|
enterable,
|
|
43
76
|
title: '',
|
|
@@ -52,8 +85,6 @@ function createTooltip(root, x0, y0, position, enterable) {
|
|
|
52
85
|
},
|
|
53
86
|
},
|
|
54
87
|
});
|
|
55
|
-
// @ts-ignore
|
|
56
|
-
const container = getContainer(root);
|
|
57
88
|
container.appendChild(tooltipElement.HTMLTooltipElement);
|
|
58
89
|
return tooltipElement;
|
|
59
90
|
}
|
|
@@ -68,11 +99,25 @@ function showTooltip({
|
|
|
68
99
|
single,
|
|
69
100
|
position = 'right-bottom',
|
|
70
101
|
enterable = false,
|
|
102
|
+
mount,
|
|
103
|
+
bounding,
|
|
71
104
|
}) {
|
|
72
105
|
// All the views share the same tooltip.
|
|
73
|
-
const
|
|
74
|
-
const
|
|
75
|
-
|
|
106
|
+
const canvasContainer = root.getRootNode().defaultView.getConfig().container;
|
|
107
|
+
const container = single ? getContainer(root, mount) : root;
|
|
108
|
+
const b = bounding || getBounding(root);
|
|
109
|
+
const containerOffset = getContainerOffset(canvasContainer, container);
|
|
110
|
+
const {
|
|
111
|
+
tooltipElement = createTooltip(
|
|
112
|
+
container,
|
|
113
|
+
x,
|
|
114
|
+
y,
|
|
115
|
+
position,
|
|
116
|
+
enterable,
|
|
117
|
+
b,
|
|
118
|
+
containerOffset,
|
|
119
|
+
),
|
|
120
|
+
} = container;
|
|
76
121
|
const { items, title = '' } = data;
|
|
77
122
|
tooltipElement.update({
|
|
78
123
|
x,
|
|
@@ -88,10 +133,15 @@ function showTooltip({
|
|
|
88
133
|
container.tooltipElement = tooltipElement;
|
|
89
134
|
}
|
|
90
135
|
|
|
91
|
-
function hideTooltip(root, single) {
|
|
92
|
-
const container = single ? getContainer(root) : root;
|
|
136
|
+
function hideTooltip({ root, single, emitter, nativeEvent = true, mount }) {
|
|
137
|
+
const container = single ? getContainer(root, mount) : root;
|
|
93
138
|
const { tooltipElement } = container;
|
|
94
|
-
if (tooltipElement)
|
|
139
|
+
if (tooltipElement) {
|
|
140
|
+
tooltipElement.hide();
|
|
141
|
+
if (nativeEvent) {
|
|
142
|
+
emitter.emit('tooltip:hide', { nativeEvent });
|
|
143
|
+
}
|
|
144
|
+
}
|
|
95
145
|
}
|
|
96
146
|
|
|
97
147
|
function destroyTooltip(root) {
|
|
@@ -300,6 +350,7 @@ export function seriesTooltip(
|
|
|
300
350
|
crosshairs,
|
|
301
351
|
render,
|
|
302
352
|
groupName,
|
|
353
|
+
emitter,
|
|
303
354
|
wait = 50,
|
|
304
355
|
leading = true,
|
|
305
356
|
trailing = false,
|
|
@@ -309,6 +360,8 @@ export function seriesTooltip(
|
|
|
309
360
|
single = true,
|
|
310
361
|
position,
|
|
311
362
|
enterable,
|
|
363
|
+
mount,
|
|
364
|
+
bounding,
|
|
312
365
|
style: _style = {},
|
|
313
366
|
...rest
|
|
314
367
|
}: Record<string, any>,
|
|
@@ -468,6 +521,8 @@ export function seriesTooltip(
|
|
|
468
521
|
single,
|
|
469
522
|
position,
|
|
470
523
|
enterable,
|
|
524
|
+
mount,
|
|
525
|
+
bounding,
|
|
471
526
|
});
|
|
472
527
|
}
|
|
473
528
|
|
|
@@ -483,16 +538,41 @@ export function seriesTooltip(
|
|
|
483
538
|
polar,
|
|
484
539
|
});
|
|
485
540
|
}
|
|
541
|
+
|
|
542
|
+
emitter.emit('tooltip:show', {
|
|
543
|
+
...event,
|
|
544
|
+
nativeEvent: true,
|
|
545
|
+
data: { data: { x: invert(scale.x, abstractX(focus), true) } },
|
|
546
|
+
});
|
|
486
547
|
},
|
|
487
548
|
wait,
|
|
488
549
|
{ leading, trailing },
|
|
489
550
|
) as (...args: any[]) => void;
|
|
490
551
|
|
|
491
552
|
const hide = () => {
|
|
492
|
-
hideTooltip(root, single);
|
|
553
|
+
hideTooltip({ root, single, emitter, mount });
|
|
493
554
|
if (crosshairs) hideRuleY(root);
|
|
494
555
|
};
|
|
495
556
|
|
|
557
|
+
const onTooltipShow = ({ nativeEvent, data }) => {
|
|
558
|
+
if (nativeEvent) return;
|
|
559
|
+
const { x } = data.data;
|
|
560
|
+
const { x: scaleX } = scale;
|
|
561
|
+
const x1 = scaleX.map(x);
|
|
562
|
+
const [x2, y2] = coordinate.map([x1, 0.5]);
|
|
563
|
+
const {
|
|
564
|
+
min: [minX, minY],
|
|
565
|
+
} = root.getRenderBounds();
|
|
566
|
+
update({ offsetX: x2 + minX, offsetY: y2 + minY });
|
|
567
|
+
};
|
|
568
|
+
|
|
569
|
+
const onTooltipHide = () => {
|
|
570
|
+
hideTooltip({ root, single, emitter, nativeEvent: false, mount });
|
|
571
|
+
};
|
|
572
|
+
|
|
573
|
+
emitter.on('tooltip:show', onTooltipShow);
|
|
574
|
+
emitter.on('tooltip:hide', onTooltipHide);
|
|
575
|
+
|
|
496
576
|
root.addEventListener('pointerenter', update);
|
|
497
577
|
root.addEventListener('pointermove', update);
|
|
498
578
|
root.addEventListener('pointerleave', hide);
|
|
@@ -501,6 +581,8 @@ export function seriesTooltip(
|
|
|
501
581
|
root.removeEventListener('pointerenter', update);
|
|
502
582
|
root.removeEventListener('pointermove', update);
|
|
503
583
|
root.removeEventListener('pointerleave', hide);
|
|
584
|
+
emitter.off('tooltip:show', onTooltipShow);
|
|
585
|
+
emitter.off('tooltip:hide', onTooltipHide);
|
|
504
586
|
destroyTooltip(root);
|
|
505
587
|
if (crosshairs) hideRuleY(root);
|
|
506
588
|
};
|
|
@@ -518,6 +600,7 @@ export function tooltip(
|
|
|
518
600
|
groupName,
|
|
519
601
|
sort: sortFunction,
|
|
520
602
|
filter: filterFunction,
|
|
603
|
+
emitter,
|
|
521
604
|
wait = 50,
|
|
522
605
|
leading = true,
|
|
523
606
|
trailing = false,
|
|
@@ -525,6 +608,10 @@ export function tooltip(
|
|
|
525
608
|
single = true,
|
|
526
609
|
position,
|
|
527
610
|
enterable,
|
|
611
|
+
datum,
|
|
612
|
+
view,
|
|
613
|
+
mount,
|
|
614
|
+
bounding,
|
|
528
615
|
}: Record<string, any>,
|
|
529
616
|
) {
|
|
530
617
|
const elements = elementsof(root);
|
|
@@ -535,7 +622,7 @@ export function tooltip(
|
|
|
535
622
|
(event) => {
|
|
536
623
|
const { target: element } = event;
|
|
537
624
|
if (!elementSet.has(element)) {
|
|
538
|
-
hideTooltip(root, single);
|
|
625
|
+
hideTooltip({ root, single, emitter, mount });
|
|
539
626
|
return;
|
|
540
627
|
}
|
|
541
628
|
const k = groupKey(element);
|
|
@@ -554,7 +641,7 @@ export function tooltip(
|
|
|
554
641
|
}
|
|
555
642
|
|
|
556
643
|
if (isEmptyTooltipData(data)) {
|
|
557
|
-
hideTooltip(root, single);
|
|
644
|
+
hideTooltip({ root, single, emitter, mount });
|
|
558
645
|
return;
|
|
559
646
|
}
|
|
560
647
|
|
|
@@ -569,6 +656,16 @@ export function tooltip(
|
|
|
569
656
|
single,
|
|
570
657
|
position,
|
|
571
658
|
enterable,
|
|
659
|
+
mount,
|
|
660
|
+
bounding,
|
|
661
|
+
});
|
|
662
|
+
|
|
663
|
+
emitter.emit('tooltip:show', {
|
|
664
|
+
...event,
|
|
665
|
+
nativeEvent: true,
|
|
666
|
+
data: {
|
|
667
|
+
data: dataOf(element, view),
|
|
668
|
+
},
|
|
572
669
|
});
|
|
573
670
|
},
|
|
574
671
|
wait,
|
|
@@ -578,9 +675,34 @@ export function tooltip(
|
|
|
578
675
|
const pointerout = (event) => {
|
|
579
676
|
const { target: element } = event;
|
|
580
677
|
if (!elementSet.has(element)) return;
|
|
581
|
-
hideTooltip(root, single);
|
|
678
|
+
hideTooltip({ root, single, emitter, mount });
|
|
582
679
|
};
|
|
583
680
|
|
|
681
|
+
const onTooltipShow = ({ nativeEvent, data }) => {
|
|
682
|
+
if (nativeEvent) return;
|
|
683
|
+
const element = elements.find((d) =>
|
|
684
|
+
Object.entries(data.data).every(
|
|
685
|
+
([key, value]) => datum(d)[key] === value,
|
|
686
|
+
),
|
|
687
|
+
);
|
|
688
|
+
if (!element) return;
|
|
689
|
+
const bbox = element.getBBox();
|
|
690
|
+
const { x, y, width, height } = bbox;
|
|
691
|
+
pointerover({
|
|
692
|
+
target: element,
|
|
693
|
+
offsetX: x + width / 2,
|
|
694
|
+
offsetY: y + height / 2,
|
|
695
|
+
});
|
|
696
|
+
};
|
|
697
|
+
|
|
698
|
+
const onTooltipHide = ({ nativeEvent }: any = {}) => {
|
|
699
|
+
if (nativeEvent) return;
|
|
700
|
+
hideTooltip({ root, single, emitter, nativeEvent: false, mount });
|
|
701
|
+
};
|
|
702
|
+
|
|
703
|
+
emitter.on('tooltip:show', onTooltipShow);
|
|
704
|
+
emitter.on('tooltip:hide', onTooltipHide);
|
|
705
|
+
|
|
584
706
|
root.addEventListener('pointerover', pointerover);
|
|
585
707
|
root.addEventListener('pointermove', pointerover);
|
|
586
708
|
root.addEventListener('pointerout', pointerout);
|
|
@@ -589,6 +711,8 @@ export function tooltip(
|
|
|
589
711
|
root.removeEventListener('pointerover', pointerover);
|
|
590
712
|
root.removeEventListener('pointermove', pointerover);
|
|
591
713
|
root.removeEventListener('pointerout', pointerout);
|
|
714
|
+
emitter.off('tooltip:show', onTooltipShow);
|
|
715
|
+
emitter.off('tooltip:hide', onTooltipHide);
|
|
592
716
|
destroyTooltip(root);
|
|
593
717
|
};
|
|
594
718
|
}
|
|
@@ -603,7 +727,7 @@ export function Tooltip(options) {
|
|
|
603
727
|
facet = false,
|
|
604
728
|
...rest
|
|
605
729
|
} = options;
|
|
606
|
-
return (target, viewInstances) => {
|
|
730
|
+
return (target, viewInstances, emitter) => {
|
|
607
731
|
const { container, view } = target;
|
|
608
732
|
const { scale, markState, coordinate } = view;
|
|
609
733
|
// Get default value from mark states.
|
|
@@ -621,6 +745,7 @@ export function Tooltip(options) {
|
|
|
621
745
|
coordinate,
|
|
622
746
|
crosshairs: maybeValue(crosshairs, defaultShowCrosshairs),
|
|
623
747
|
item,
|
|
748
|
+
emitter,
|
|
624
749
|
});
|
|
625
750
|
}
|
|
626
751
|
|
|
@@ -649,16 +774,20 @@ export function Tooltip(options) {
|
|
|
649
774
|
item,
|
|
650
775
|
startX,
|
|
651
776
|
startY,
|
|
777
|
+
emitter,
|
|
652
778
|
});
|
|
653
779
|
}
|
|
654
780
|
|
|
655
781
|
return tooltip(plotArea, {
|
|
656
782
|
...rest,
|
|
783
|
+
datum: createDatumof(view),
|
|
657
784
|
elements: selectG2Elements,
|
|
658
785
|
scale,
|
|
659
786
|
coordinate,
|
|
660
787
|
groupKey: shared ? createXKey(view) : undefined,
|
|
661
788
|
item,
|
|
789
|
+
emitter,
|
|
790
|
+
view,
|
|
662
791
|
});
|
|
663
792
|
};
|
|
664
793
|
}
|
package/src/mark/gauge.ts
CHANGED
|
@@ -10,20 +10,27 @@ import { Radial } from '../coordinate';
|
|
|
10
10
|
import { applyStyle, getOrigin } from '../shape/utils';
|
|
11
11
|
import { select } from '../utils/selection';
|
|
12
12
|
|
|
13
|
+
export type GaugeData = {
|
|
14
|
+
target?: number;
|
|
15
|
+
total?: number;
|
|
16
|
+
percent?: number;
|
|
17
|
+
name?: string;
|
|
18
|
+
thresholds?: number[];
|
|
19
|
+
};
|
|
20
|
+
|
|
13
21
|
export type GaugeOptions = Omit<GaugeMark, 'type'>;
|
|
14
22
|
|
|
15
|
-
function dataTransform(data, scale) {
|
|
16
|
-
const { name = 'score', target, total, percent } = data;
|
|
23
|
+
function dataTransform(data: GaugeData, scale) {
|
|
24
|
+
const { name = 'score', target, total, percent, thresholds = [] } = data;
|
|
17
25
|
const _target = percent || target;
|
|
18
26
|
const _total = percent ? 1 : total;
|
|
19
|
-
const { color } = scale;
|
|
20
27
|
const newScale = {
|
|
21
28
|
y: {
|
|
22
29
|
domain: [0, _total],
|
|
23
30
|
},
|
|
24
31
|
...scale,
|
|
25
32
|
};
|
|
26
|
-
if (!
|
|
33
|
+
if (!thresholds.length) {
|
|
27
34
|
return {
|
|
28
35
|
targetData: [{ x: name, y: _target, color: 'target' }],
|
|
29
36
|
totalData: [
|
|
@@ -35,12 +42,11 @@ function dataTransform(data, scale) {
|
|
|
35
42
|
scale: newScale,
|
|
36
43
|
};
|
|
37
44
|
}
|
|
38
|
-
const { domain = [] } = color;
|
|
39
45
|
return {
|
|
40
46
|
targetData: [{ x: name, y: _target, color: 'target' }],
|
|
41
|
-
totalData:
|
|
47
|
+
totalData: thresholds.map((d, i) => ({
|
|
42
48
|
x: name,
|
|
43
|
-
y: i >= 1 ? d -
|
|
49
|
+
y: i >= 1 ? d - thresholds[i - 1] : d,
|
|
44
50
|
color: i,
|
|
45
51
|
})),
|
|
46
52
|
target: _target,
|
package/src/runtime/plot.ts
CHANGED
|
@@ -324,8 +324,7 @@ function updateTooltip(selection, options, view, library, context) {
|
|
|
324
324
|
// Instances for tooltip.
|
|
325
325
|
const container = selection.node();
|
|
326
326
|
const nameInteraction = container['nameInteraction'];
|
|
327
|
-
const
|
|
328
|
-
const tooltipOptions = inferInteraction(interaction).find(
|
|
327
|
+
const tooltipOptions = inferInteraction(options).find(
|
|
329
328
|
(d) => d.type === 'tooltip',
|
|
330
329
|
);
|
|
331
330
|
|
|
@@ -824,7 +823,10 @@ async function plotView(
|
|
|
824
823
|
maybeFacetElement(this, parent, origin);
|
|
825
824
|
const node = shapeFunction(data, index);
|
|
826
825
|
const animation = updateFunction(data, [this], [node]);
|
|
827
|
-
if (animation === null)
|
|
826
|
+
if (animation === null) {
|
|
827
|
+
if (this.nodeName === node.nodeName) copyAttributes(this, node);
|
|
828
|
+
else this.parentNode.replaceChild(node, this);
|
|
829
|
+
}
|
|
828
830
|
return animation;
|
|
829
831
|
});
|
|
830
832
|
}),
|
|
@@ -1211,10 +1213,10 @@ function createMarkShapeFunction(
|
|
|
1211
1213
|
const point2d = data.map((d) => d.points);
|
|
1212
1214
|
const { theme, coordinate } = view;
|
|
1213
1215
|
const { type: markType, style = {} } = mark;
|
|
1214
|
-
return (data
|
|
1216
|
+
return (data) => {
|
|
1215
1217
|
const { shape: styleShape = defaultShape } = style;
|
|
1216
1218
|
const { shape = styleShape, points, seriesIndex, index: i, ...v } = data;
|
|
1217
|
-
const value = { ...v, shape, mark: markType, defaultShape, index };
|
|
1219
|
+
const value = { ...v, shape, mark: markType, defaultShape, index: i };
|
|
1218
1220
|
|
|
1219
1221
|
// Get data-driven style.
|
|
1220
1222
|
// If it is a series shape, such as area and line,
|
package/src/runtime/scale.ts
CHANGED
|
@@ -200,7 +200,7 @@ function inferScaleDomain(
|
|
|
200
200
|
case 'quantize':
|
|
201
201
|
case 'threshold': {
|
|
202
202
|
const [d0, d1] = inferDomainQ(values, options);
|
|
203
|
-
return [domainMin
|
|
203
|
+
return [domainMin ?? d0, domainMax ?? d1];
|
|
204
204
|
}
|
|
205
205
|
case 'band':
|
|
206
206
|
case 'ordinal':
|
|
@@ -210,7 +210,7 @@ function inferScaleDomain(
|
|
|
210
210
|
return inferDomainO(values);
|
|
211
211
|
case 'sequential': {
|
|
212
212
|
const [d0, d1] = inferDomainS(values);
|
|
213
|
-
return [domainMin
|
|
213
|
+
return [domainMin ?? d0, domainMax ?? d1];
|
|
214
214
|
}
|
|
215
215
|
default:
|
|
216
216
|
return [];
|
package/src/runtime/transform.ts
CHANGED
|
@@ -268,7 +268,8 @@ export function addGuideToScale(
|
|
|
268
268
|
size: { guide: normalize(legend, 'size') },
|
|
269
269
|
shape: { guide: normalize(legend, 'shape') },
|
|
270
270
|
// fixme: opacity is conflict with DisplayObject.opacity
|
|
271
|
-
//
|
|
271
|
+
// to be comfirm.
|
|
272
|
+
opacity: { guide: normalize(legend, 'opacity') },
|
|
272
273
|
},
|
|
273
274
|
});
|
|
274
275
|
return [I, mark];
|
|
@@ -112,6 +112,7 @@ export type Scale = {
|
|
|
112
112
|
getFormatter?: () => (x: any) => string;
|
|
113
113
|
getOptions: () => Record<string, any>;
|
|
114
114
|
update(options: Record<string, any>): void;
|
|
115
|
+
clone: () => Scale;
|
|
115
116
|
};
|
|
116
117
|
export type ScaleComponent<O = Record<string, unknown>> = G2BaseComponent<
|
|
117
118
|
Scale,
|
package/src/shape/area/area.ts
CHANGED
package/src/shape/area/curve.ts
CHANGED
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
getTransform,
|
|
12
12
|
} from '../utils';
|
|
13
13
|
import { subObject } from '../../utils/helper';
|
|
14
|
-
import { createElement } from '
|
|
14
|
+
import { createElement } from '../../utils/createElement';
|
|
15
15
|
|
|
16
16
|
const DoubleArea = createElement((g) => {
|
|
17
17
|
const { areaPath, connectPath, areaStyle, connectStyle } = g.attributes;
|
|
@@ -4,7 +4,7 @@ import { PathStyleProps } from '@antv/g';
|
|
|
4
4
|
import { Marker } from '@antv/gui';
|
|
5
5
|
import { line as d3line } from 'd3-shape';
|
|
6
6
|
import { ShapeComponent as SC, Vector2, WithPrefix } from '../../runtime';
|
|
7
|
-
import { createElement } from '../../
|
|
7
|
+
import { createElement } from '../../utils/createElement';
|
|
8
8
|
import { isTranspose } from '../../utils/coordinate';
|
|
9
9
|
import { subObject } from '../../utils/helper';
|
|
10
10
|
import { select } from '../../utils/selection';
|
package/src/shape/line/curve.ts
CHANGED
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
getShapeTheme,
|
|
11
11
|
getTransform,
|
|
12
12
|
} from '../utils';
|
|
13
|
-
import { createElement } from '
|
|
13
|
+
import { createElement } from '../../utils/createElement';
|
|
14
14
|
import { subObject } from '../../utils/helper';
|
|
15
15
|
import { angleWithQuadrant, dist, sub } from '../../utils/vector';
|
|
16
16
|
|
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
import { Marker } from '@antv/gui';
|
|
11
11
|
import { line } from 'd3-shape';
|
|
12
12
|
import { WithPrefix } from '../../runtime';
|
|
13
|
-
import { createElement } from '
|
|
13
|
+
import { createElement } from '../../utils/createElement';
|
|
14
14
|
import { applyStyle } from '../utils';
|
|
15
15
|
import { subObject } from '../../utils/helper';
|
|
16
16
|
import { select } from '../../utils/selection';
|
package/src/shape/text/badge.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { TextStyleProps, DisplayObject } from '@antv/g';
|
|
2
2
|
import { Marker } from '@antv/gui';
|
|
3
3
|
import { ShapeComponent as SC, WithPrefix } from '../../runtime';
|
|
4
|
-
import { createElement } from '../../
|
|
4
|
+
import { createElement } from '../../utils/createElement';
|
|
5
5
|
import { subObject } from '../../utils/helper';
|
|
6
6
|
import { select } from '../../utils/selection';
|
|
7
7
|
import { applyStyle, getShapeTheme } from '../../shape/utils';
|
package/src/shape/utils.ts
CHANGED
|
@@ -218,7 +218,7 @@ export function getConnectStyle(
|
|
|
218
218
|
}
|
|
219
219
|
|
|
220
220
|
export function toOpacityKey(options) {
|
|
221
|
-
const { opacityAttribute =
|
|
221
|
+
const { colorAttribute, opacityAttribute = colorAttribute } = options;
|
|
222
222
|
return `${opacityAttribute}Opacity`;
|
|
223
223
|
}
|
|
224
224
|
|
package/src/spec/interaction.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import type { TooltipStyleProps } from '@antv/gui';
|
|
2
|
-
import { InteractionComponent } from '../runtime';
|
|
2
|
+
import { BBox, InteractionComponent } from '../runtime';
|
|
3
3
|
import { FisheyeCoordinate } from './coordinateTransform';
|
|
4
4
|
import { TooltipItemValue } from './component';
|
|
5
|
-
import { AtheisticChanelTypes } from './mark';
|
|
6
5
|
|
|
7
6
|
export type Interaction =
|
|
8
7
|
| ElementHighlightInteraction
|
|
@@ -176,6 +175,8 @@ export type TooltipInteraction = {
|
|
|
176
175
|
crosshairs?: boolean;
|
|
177
176
|
groupName?: boolean;
|
|
178
177
|
position?: TooltipStyleProps['position'];
|
|
178
|
+
bounding?: BBox;
|
|
179
|
+
mount?: string | HTMLElement;
|
|
179
180
|
// enterable?: boolean;
|
|
180
181
|
sort?: (d: TooltipItemValue) => any;
|
|
181
182
|
filter?: (d: TooltipItemValue) => any;
|
package/src/theme/classic.ts
CHANGED
|
@@ -259,6 +259,7 @@ export const Classic: TC<ClassicOptions> = (options) => {
|
|
|
259
259
|
gridDirection: 'negative',
|
|
260
260
|
labelDirection: 'positive',
|
|
261
261
|
labelSpacing: 12,
|
|
262
|
+
labelAutoRotate: true,
|
|
262
263
|
tickDirection: 'positive',
|
|
263
264
|
titlePosition: 'bottom',
|
|
264
265
|
titleSpacing: 10,
|
|
@@ -280,6 +281,7 @@ export const Classic: TC<ClassicOptions> = (options) => {
|
|
|
280
281
|
gridDirection: 'positive',
|
|
281
282
|
labelDirection: 'negative',
|
|
282
283
|
labelSpacing: 4,
|
|
284
|
+
labelAutoRotate: false,
|
|
283
285
|
tickDirection: 'negative',
|
|
284
286
|
titlePosition: 'right',
|
|
285
287
|
titleSpacing: 0,
|
|
@@ -348,6 +350,7 @@ export const Classic: TC<ClassicOptions> = (options) => {
|
|
|
348
350
|
labelFontWeight: 'normal',
|
|
349
351
|
labelSpacing: 8,
|
|
350
352
|
tick: true,
|
|
353
|
+
// title: false,
|
|
351
354
|
// [todo] legend rail
|
|
352
355
|
},
|
|
353
356
|
label: {
|
package/src/theme/classicDark.ts
CHANGED
package/src/transform/filter.ts
CHANGED
|
@@ -11,7 +11,7 @@ export type FilterOptions = Omit<FilterTransform, 'type'>;
|
|
|
11
11
|
*/
|
|
12
12
|
export const Filter: TC<FilterOptions> = (options = {}) => {
|
|
13
13
|
return (I, mark) => {
|
|
14
|
-
const { encode } = mark;
|
|
14
|
+
const { encode, data } = mark;
|
|
15
15
|
const filters = Object.entries(options)
|
|
16
16
|
.map(([key, value]) => {
|
|
17
17
|
const [V] = columnOf(encode, key);
|
|
@@ -43,7 +43,11 @@ export const Filter: TC<FilterOptions> = (options = {}) => {
|
|
|
43
43
|
});
|
|
44
44
|
return [
|
|
45
45
|
newIndex,
|
|
46
|
-
deepMix({}, mark, {
|
|
46
|
+
deepMix({}, mark, {
|
|
47
|
+
encode: Object.fromEntries(newEncodes),
|
|
48
|
+
// Filter data for tooltip item.
|
|
49
|
+
data: FI.map((i) => data[i]),
|
|
50
|
+
}),
|
|
47
51
|
];
|
|
48
52
|
};
|
|
49
53
|
};
|
|
@@ -6,7 +6,7 @@ export type ElementDescriptor = {
|
|
|
6
6
|
|
|
7
7
|
export function createElement<T = Record<string, any>>(
|
|
8
8
|
descriptor: ElementDescriptor | ElementDescriptor['render'],
|
|
9
|
-
): new () => DisplayObject {
|
|
9
|
+
): new (T?) => DisplayObject {
|
|
10
10
|
const render =
|
|
11
11
|
typeof descriptor === 'function' ? descriptor : descriptor.render;
|
|
12
12
|
return class extends CustomElement<T> {
|
package/src/utils/helper.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { DisplayObject } from '@antv/g';
|
|
2
|
-
import { lowerFirst,
|
|
2
|
+
import { lowerFirst, upperFirst } from '@antv/util';
|
|
3
3
|
|
|
4
4
|
export function identity<T>(x: T): T {
|
|
5
5
|
return x;
|
|
@@ -116,6 +116,17 @@ export function filterPrefixObject(
|
|
|
116
116
|
);
|
|
117
117
|
}
|
|
118
118
|
|
|
119
|
+
export function omitPrefixObject(
|
|
120
|
+
obj: Record<string, any>,
|
|
121
|
+
...prefixes: string[]
|
|
122
|
+
) {
|
|
123
|
+
return Object.fromEntries(
|
|
124
|
+
Object.entries(obj).filter(([key]) =>
|
|
125
|
+
prefixes.every((prefix) => !key.startsWith(prefix)),
|
|
126
|
+
),
|
|
127
|
+
);
|
|
128
|
+
}
|
|
129
|
+
|
|
119
130
|
export function maybePercentage(x: number | string, size: number) {
|
|
120
131
|
if (x === undefined) return null;
|
|
121
132
|
if (typeof x === 'number') return x;
|
|
File without changes
|
|
File without changes
|