@antv/g2 5.0.0-beta.6 → 5.0.0-beta.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 +3 -3
- package/dist/g2.min.js +3 -3
- package/esm/api/chart.d.ts +2 -2
- package/esm/api/chart.js +2 -3
- package/esm/api/chart.js.map +1 -1
- package/esm/api/composition/base.d.ts +4 -0
- package/esm/api/composition/base.js +16 -0
- package/esm/api/composition/base.js.map +1 -0
- package/esm/api/composition/facetCircle.d.ts +2 -3
- package/esm/api/composition/facetCircle.js +2 -2
- package/esm/api/composition/facetCircle.js.map +1 -1
- package/esm/api/composition/facetRect.d.ts +2 -3
- package/esm/api/composition/facetRect.js +2 -2
- package/esm/api/composition/facetRect.js.map +1 -1
- package/esm/api/composition/geoPath.d.ts +2 -3
- package/esm/api/composition/geoPath.js +2 -2
- package/esm/api/composition/geoPath.js.map +1 -1
- package/esm/api/composition/geoView.d.ts +2 -3
- package/esm/api/composition/geoView.js +2 -2
- package/esm/api/composition/geoView.js.map +1 -1
- package/esm/api/composition/index.d.ts +2 -1
- package/esm/api/composition/index.js +2 -1
- package/esm/api/composition/index.js.map +1 -1
- package/esm/api/composition/repeatMatrix.d.ts +2 -3
- package/esm/api/composition/repeatMatrix.js +2 -2
- package/esm/api/composition/repeatMatrix.js.map +1 -1
- package/esm/api/composition/spaceFlex.d.ts +2 -3
- package/esm/api/composition/spaceFlex.js +2 -2
- package/esm/api/composition/spaceFlex.js.map +1 -1
- package/esm/api/composition/spaceLayer.d.ts +2 -3
- package/esm/api/composition/spaceLayer.js +2 -2
- package/esm/api/composition/spaceLayer.js.map +1 -1
- package/esm/api/composition/timingKeyframe.d.ts +2 -3
- package/esm/api/composition/timingKeyframe.js +2 -2
- package/esm/api/composition/timingKeyframe.js.map +1 -1
- package/esm/api/composition/view.d.ts +3 -3
- package/esm/api/composition/view.js +4 -4
- package/esm/api/composition/view.js.map +1 -1
- package/esm/api/mark/mark.d.ts +34 -28
- package/esm/api/mark/mark.js +38 -26
- package/esm/api/mark/mark.js.map +1 -1
- package/esm/api/node.d.ts +2 -1
- package/esm/api/node.js +8 -9
- package/esm/api/node.js.map +1 -1
- package/esm/component/slider.js +3 -13
- package/esm/component/slider.js.map +1 -1
- package/esm/geo/{d3-projection.d.ts → d3Projection.d.ts} +0 -0
- package/esm/geo/{d3-projection.js → d3Projection.js} +1 -1
- package/esm/geo/d3Projection.js.map +1 -0
- package/esm/geo/geoView.js +1 -1
- package/esm/geo/geoView.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/native/brushFilter.d.ts +3 -1
- package/esm/interaction/native/brushFilter.js +7 -32
- package/esm/interaction/native/brushFilter.js.map +1 -1
- package/esm/interaction/native/brushXFilter.js +1 -1
- package/esm/interaction/native/brushXFilter.js.map +1 -1
- package/esm/interaction/native/brushYFilter.js +1 -1
- package/esm/interaction/native/brushYFilter.js.map +1 -1
- package/esm/interaction/native/elementHighlight.js +1 -0
- package/esm/interaction/native/elementHighlight.js.map +1 -1
- package/esm/interaction/native/elementSelect.js +1 -0
- package/esm/interaction/native/elementSelect.js.map +1 -1
- package/esm/interaction/native/sliderFilter.d.ts +5 -0
- package/esm/interaction/native/sliderFilter.js +87 -0
- package/esm/interaction/native/sliderFilter.js.map +1 -0
- package/esm/interaction/native/tooltip.js +11 -0
- package/esm/interaction/native/tooltip.js.map +1 -1
- package/esm/label-transform/overlapDodgeY.js +8 -0
- package/esm/label-transform/overlapDodgeY.js.map +1 -1
- package/esm/runtime/component.d.ts +1 -1
- package/esm/runtime/component.js +5 -3
- package/esm/runtime/component.js.map +1 -1
- package/esm/runtime/plot.d.ts +1 -1
- package/esm/runtime/plot.js +65 -26
- package/esm/runtime/plot.js.map +1 -1
- package/esm/runtime/scale.d.ts +2 -1
- package/esm/runtime/scale.js +7 -0
- package/esm/runtime/scale.js.map +1 -1
- package/esm/spec/geometry.d.ts +1 -0
- package/esm/spec/interaction.d.ts +8 -2
- package/esm/spec/transform.d.ts +2 -2
- package/esm/stdlib/index.js +2 -2
- package/esm/stdlib/index.js.map +1 -1
- package/esm/transform/select.js +1 -13
- package/esm/transform/select.js.map +1 -1
- package/esm/transform/selectX.js +1 -1
- package/esm/transform/selectX.js.map +1 -1
- package/esm/transform/selectY.js +1 -1
- package/esm/transform/selectY.js.map +1 -1
- package/esm/utils/scale.d.ts +2 -0
- package/esm/utils/scale.js +30 -0
- package/esm/utils/scale.js.map +1 -0
- package/lib/api/chart.d.ts +2 -2
- package/lib/api/chart.js +1 -2
- package/lib/api/chart.js.map +1 -1
- package/lib/api/composition/base.d.ts +4 -0
- package/lib/api/composition/base.js +19 -0
- package/lib/api/composition/base.js.map +1 -0
- package/lib/api/composition/facetCircle.d.ts +2 -3
- package/lib/api/composition/facetCircle.js +2 -2
- package/lib/api/composition/facetCircle.js.map +1 -1
- package/lib/api/composition/facetRect.d.ts +2 -3
- package/lib/api/composition/facetRect.js +2 -2
- package/lib/api/composition/facetRect.js.map +1 -1
- package/lib/api/composition/geoPath.d.ts +2 -3
- package/lib/api/composition/geoPath.js +2 -2
- package/lib/api/composition/geoPath.js.map +1 -1
- package/lib/api/composition/geoView.d.ts +2 -3
- package/lib/api/composition/geoView.js +2 -2
- package/lib/api/composition/geoView.js.map +1 -1
- package/lib/api/composition/index.d.ts +2 -1
- package/lib/api/composition/index.js +3 -1
- package/lib/api/composition/index.js.map +1 -1
- package/lib/api/composition/repeatMatrix.d.ts +2 -3
- package/lib/api/composition/repeatMatrix.js +2 -2
- package/lib/api/composition/repeatMatrix.js.map +1 -1
- package/lib/api/composition/spaceFlex.d.ts +2 -3
- package/lib/api/composition/spaceFlex.js +2 -2
- package/lib/api/composition/spaceFlex.js.map +1 -1
- package/lib/api/composition/spaceLayer.d.ts +2 -3
- package/lib/api/composition/spaceLayer.js +2 -2
- package/lib/api/composition/spaceLayer.js.map +1 -1
- package/lib/api/composition/timingKeyframe.d.ts +2 -3
- package/lib/api/composition/timingKeyframe.js +2 -2
- package/lib/api/composition/timingKeyframe.js.map +1 -1
- package/lib/api/composition/view.d.ts +3 -3
- package/lib/api/composition/view.js +4 -4
- package/lib/api/composition/view.js.map +1 -1
- package/lib/api/mark/mark.d.ts +34 -28
- package/lib/api/mark/mark.js +40 -27
- package/lib/api/mark/mark.js.map +1 -1
- package/lib/api/node.d.ts +2 -1
- package/lib/api/node.js +8 -9
- package/lib/api/node.js.map +1 -1
- package/lib/component/slider.js +3 -13
- package/lib/component/slider.js.map +1 -1
- package/lib/geo/{d3-projection.d.ts → d3Projection.d.ts} +0 -0
- package/lib/geo/{d3-projection.js → d3Projection.js} +1 -1
- package/lib/geo/d3Projection.js.map +1 -0
- package/lib/geo/geoView.js +1 -1
- package/lib/geo/geoView.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/native/brushFilter.d.ts +3 -1
- package/lib/interaction/native/brushFilter.js +10 -35
- package/lib/interaction/native/brushFilter.js.map +1 -1
- package/lib/interaction/native/brushXFilter.js +1 -1
- package/lib/interaction/native/brushXFilter.js.map +1 -1
- package/lib/interaction/native/brushYFilter.js +1 -1
- package/lib/interaction/native/brushYFilter.js.map +1 -1
- package/lib/interaction/native/elementHighlight.js +1 -0
- package/lib/interaction/native/elementHighlight.js.map +1 -1
- package/lib/interaction/native/elementSelect.js +1 -0
- package/lib/interaction/native/elementSelect.js.map +1 -1
- package/lib/interaction/native/sliderFilter.d.ts +5 -0
- package/lib/interaction/native/sliderFilter.js +91 -0
- package/lib/interaction/native/sliderFilter.js.map +1 -0
- package/lib/interaction/native/tooltip.js +11 -0
- package/lib/interaction/native/tooltip.js.map +1 -1
- package/lib/label-transform/overlapDodgeY.js +8 -0
- package/lib/label-transform/overlapDodgeY.js.map +1 -1
- package/lib/runtime/component.d.ts +1 -1
- package/lib/runtime/component.js +4 -2
- package/lib/runtime/component.js.map +1 -1
- package/lib/runtime/plot.d.ts +1 -1
- package/lib/runtime/plot.js +62 -23
- package/lib/runtime/plot.js.map +1 -1
- package/lib/runtime/scale.d.ts +2 -1
- package/lib/runtime/scale.js +9 -1
- package/lib/runtime/scale.js.map +1 -1
- package/lib/spec/geometry.d.ts +1 -0
- package/lib/spec/interaction.d.ts +8 -2
- package/lib/spec/transform.d.ts +2 -2
- package/lib/stdlib/index.js +1 -1
- package/lib/stdlib/index.js.map +1 -1
- package/lib/transform/select.js +1 -13
- package/lib/transform/select.js.map +1 -1
- package/lib/transform/selectX.js +1 -1
- package/lib/transform/selectX.js.map +1 -1
- package/lib/transform/selectY.js +1 -1
- package/lib/transform/selectY.js.map +1 -1
- package/lib/utils/scale.d.ts +2 -0
- package/lib/utils/scale.js +35 -0
- package/lib/utils/scale.js.map +1 -0
- package/package.json +1 -1
- package/src/api/chart.ts +2 -2
- package/src/api/composition/base.ts +11 -0
- package/src/api/composition/facetCircle.ts +2 -3
- package/src/api/composition/facetRect.ts +2 -3
- package/src/api/composition/geoPath.ts +2 -3
- package/src/api/composition/geoView.ts +2 -3
- package/src/api/composition/index.ts +2 -0
- package/src/api/composition/repeatMatrix.ts +2 -3
- package/src/api/composition/spaceFlex.ts +2 -3
- package/src/api/composition/spaceLayer.ts +2 -3
- package/src/api/composition/timingKeyframe.ts +2 -3
- package/src/api/composition/view.ts +6 -4
- package/src/api/mark/mark.ts +47 -27
- package/src/api/node.ts +9 -11
- package/src/component/slider.ts +3 -12
- package/src/geo/{d3-projection.ts → d3Projection.ts} +0 -0
- package/src/geo/geoView.ts +1 -1
- package/src/interaction/index.ts +1 -0
- package/src/interaction/native/brushFilter.ts +18 -38
- package/src/interaction/native/brushXFilter.ts +1 -0
- package/src/interaction/native/brushYFilter.ts +1 -0
- package/src/interaction/native/elementHighlight.ts +1 -0
- package/src/interaction/native/elementSelect.ts +1 -0
- package/src/interaction/native/sliderFilter.ts +112 -0
- package/src/interaction/native/tooltip.ts +11 -0
- package/src/label-transform/overlapDodgeY.ts +8 -1
- package/src/runtime/component.ts +18 -25
- package/src/runtime/plot.ts +120 -72
- package/src/runtime/scale.ts +14 -0
- package/src/spec/geometry.ts +1 -0
- package/src/spec/interaction.ts +10 -1
- package/src/spec/transform.ts +3 -1
- package/src/stdlib/index.ts +2 -0
- package/src/transform/select.ts +1 -2
- package/src/transform/selectX.ts +1 -1
- package/src/transform/selectY.ts +1 -1
- package/src/utils/scale.ts +31 -0
- package/esm/geo/d3-projection.js.map +0 -1
- package/lib/geo/d3-projection.js.map +0 -1
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { deepMix } from '@antv/util';
|
|
2
|
-
import { bisectLeft, sort } from 'd3-array';
|
|
3
2
|
import { subObject } from '../../utils/helper';
|
|
4
|
-
import {
|
|
3
|
+
import { invert, domainOf } from '../../utils/scale';
|
|
5
4
|
import { brush as createBrush } from './brushHighlight';
|
|
5
|
+
import { selectPlotArea } from './utils';
|
|
6
6
|
|
|
7
7
|
// Mock dblclick events.
|
|
8
8
|
function dblclick(interval = 300) {
|
|
@@ -64,37 +64,7 @@ export function brushFilter(
|
|
|
64
64
|
};
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
-
function
|
|
68
|
-
return scale.getBandWidth;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
function constrain(x, lo, hi) {
|
|
72
|
-
return Math.min(hi, Math.max(lo, x));
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
function invert(scale, x, start) {
|
|
76
|
-
if (!isOrdinalScale(scale)) return scale.invert(x);
|
|
77
|
-
const { adjustedRange } = scale;
|
|
78
|
-
const { domain } = scale.getOptions();
|
|
79
|
-
const offset = start ? -1 : 0;
|
|
80
|
-
const step = scale.getStep();
|
|
81
|
-
const range = start ? adjustedRange : adjustedRange.map((d) => d + step);
|
|
82
|
-
// R[i0 - 1] < x <= R[i0]
|
|
83
|
-
const i0 = bisectLeft(range, x);
|
|
84
|
-
const i1 = constrain(i0 + offset, 0, domain.length - 1);
|
|
85
|
-
return domain[i1];
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
function domainOf(scale, values) {
|
|
89
|
-
if (!isOrdinalScale(scale)) return sort(values);
|
|
90
|
-
const { domain } = scale.getOptions();
|
|
91
|
-
const [v1, v2] = values;
|
|
92
|
-
const start = domain.indexOf(v1);
|
|
93
|
-
const end = domain.indexOf(v2);
|
|
94
|
-
return domain.slice(start, end + 1);
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
export function BrushFilter({ ...rest }) {
|
|
67
|
+
export function BrushFilter({ hideX = true, hideY = true, ...rest }) {
|
|
98
68
|
return (target, viewInstances) => {
|
|
99
69
|
const { container, view, options: viewOptions, update } = target;
|
|
100
70
|
const plotArea = selectPlotArea(container);
|
|
@@ -130,12 +100,22 @@ export function BrushFilter({ ...rest }) {
|
|
|
130
100
|
// Update the domain of x and y scale to filter data.
|
|
131
101
|
const { marks } = viewOptions;
|
|
132
102
|
const newMarks = marks.map((mark) =>
|
|
133
|
-
deepMix(
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
103
|
+
deepMix(
|
|
104
|
+
{
|
|
105
|
+
// Hide label to keep smooth transition.
|
|
106
|
+
axis: {
|
|
107
|
+
...(hideX && { x: { labelTransforms: [{ type: 'hide' }] } }),
|
|
108
|
+
...(hideY && { y: { labelTransforms: [{ type: 'hide' }] } }),
|
|
109
|
+
},
|
|
110
|
+
},
|
|
111
|
+
mark,
|
|
112
|
+
{
|
|
113
|
+
scale: {
|
|
114
|
+
x: { domain: domainOf(scaleX, [p0[0], p1[0]]) },
|
|
115
|
+
y: { domain: domainOf(scaleY, [p0[1], p1[1]]) },
|
|
116
|
+
},
|
|
137
117
|
},
|
|
138
|
-
|
|
118
|
+
),
|
|
139
119
|
);
|
|
140
120
|
|
|
141
121
|
// Rerender and update view.
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { deepMix, throttle } from '@antv/util';
|
|
2
|
+
import { invert, domainOf } from '../../utils/scale';
|
|
3
|
+
|
|
4
|
+
export const SLIDER_CLASS_NAME = 'slider';
|
|
5
|
+
|
|
6
|
+
function filterDataByDomain(options, scaleOptions) {
|
|
7
|
+
const { marks } = options;
|
|
8
|
+
const newMarks = marks.map((mark) =>
|
|
9
|
+
deepMix(
|
|
10
|
+
{
|
|
11
|
+
// Hide label to keep smooth transition.
|
|
12
|
+
axis: {
|
|
13
|
+
x: { labelTransforms: [{ type: 'hide' }] },
|
|
14
|
+
y: { labelTransforms: [{ type: 'hide' }] },
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
mark,
|
|
18
|
+
{
|
|
19
|
+
scale: scaleOptions,
|
|
20
|
+
// Don't rerender sliders.
|
|
21
|
+
slider: {
|
|
22
|
+
...(mark.slider.x && { x: { preserve: true } }),
|
|
23
|
+
...(mark.slider.y && { y: { preserve: true } }),
|
|
24
|
+
},
|
|
25
|
+
animate: false,
|
|
26
|
+
},
|
|
27
|
+
),
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
// Rerender and update view.
|
|
31
|
+
return {
|
|
32
|
+
...options,
|
|
33
|
+
marks: newMarks,
|
|
34
|
+
clip: true, // Clip shapes out of plot area.
|
|
35
|
+
animate: false,
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function abstractValue(values, scale) {
|
|
40
|
+
const [x, x1] = values;
|
|
41
|
+
const d0 = invert(scale, x, true);
|
|
42
|
+
const d1 = invert(scale, x1, false);
|
|
43
|
+
return domainOf(scale, [d0, d1]);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* @todo Support click to reset after fix click and dragend conflict.
|
|
48
|
+
*/
|
|
49
|
+
export function SliderFilter({
|
|
50
|
+
wait = 50,
|
|
51
|
+
leading = true,
|
|
52
|
+
trailing = false,
|
|
53
|
+
}: any) {
|
|
54
|
+
return (context) => {
|
|
55
|
+
const { container, view, options, update } = context;
|
|
56
|
+
const sliders = container.getElementsByClassName(SLIDER_CLASS_NAME);
|
|
57
|
+
if (!sliders.length) return;
|
|
58
|
+
|
|
59
|
+
let filtering = false;
|
|
60
|
+
const { scale } = view;
|
|
61
|
+
const { x: scaleX, y: scaleY } = scale;
|
|
62
|
+
|
|
63
|
+
const sliderHandler = new Map();
|
|
64
|
+
|
|
65
|
+
// Store current domain of x and y scale.
|
|
66
|
+
const channelDomain = {
|
|
67
|
+
x: scaleX.getOptions().domain,
|
|
68
|
+
y: scaleY.getOptions().domain,
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
for (const slider of sliders) {
|
|
72
|
+
const { orient } = slider.attributes;
|
|
73
|
+
|
|
74
|
+
const onValueChange = throttle(
|
|
75
|
+
async (event) => {
|
|
76
|
+
const { value: values } = event.detail;
|
|
77
|
+
if (filtering) return;
|
|
78
|
+
filtering = true;
|
|
79
|
+
|
|
80
|
+
// Update domain of the current channel.
|
|
81
|
+
const channel0 = orient === 'vertical' ? 'y' : 'x';
|
|
82
|
+
const scale0 = scale[channel0];
|
|
83
|
+
const domain0 = abstractValue(values, scale0);
|
|
84
|
+
channelDomain[channel0] = domain0;
|
|
85
|
+
|
|
86
|
+
// Get domain of the other channel.
|
|
87
|
+
const channel1 = orient === 'vertical' ? 'x' : 'y';
|
|
88
|
+
const domain1 = channelDomain[channel1];
|
|
89
|
+
|
|
90
|
+
// Filter data.
|
|
91
|
+
const newOptions = filterDataByDomain(options, {
|
|
92
|
+
[channel0]: { domain: domain0 },
|
|
93
|
+
[channel1]: { domain: domain1 },
|
|
94
|
+
});
|
|
95
|
+
await update(newOptions);
|
|
96
|
+
filtering = false;
|
|
97
|
+
},
|
|
98
|
+
wait,
|
|
99
|
+
{ leading, trailing },
|
|
100
|
+
);
|
|
101
|
+
|
|
102
|
+
slider.addEventListener('valuechange', onValueChange);
|
|
103
|
+
sliderHandler.set(slider, onValueChange);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
return () => {
|
|
107
|
+
for (const [slider, handler] of sliderHandler) {
|
|
108
|
+
slider.removeEventListener('valuechange', handler);
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
};
|
|
112
|
+
}
|
|
@@ -72,6 +72,14 @@ function hideTooltip(root) {
|
|
|
72
72
|
if (tooltipElement) tooltipElement.hide();
|
|
73
73
|
}
|
|
74
74
|
|
|
75
|
+
function destroyTooltip(root) {
|
|
76
|
+
const { tooltipElement } = root;
|
|
77
|
+
if (tooltipElement) {
|
|
78
|
+
tooltipElement.destroy();
|
|
79
|
+
root.tooltipElement = undefined;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
75
83
|
function filterDefined(obj) {
|
|
76
84
|
return Object.fromEntries(
|
|
77
85
|
Object.entries(obj).filter(([, value]) => defined(value)),
|
|
@@ -384,6 +392,8 @@ export function seriesTooltip(
|
|
|
384
392
|
root.removeEventListener('pointerover', update);
|
|
385
393
|
root.removeEventListener('pointerout', update);
|
|
386
394
|
root.removeEventListener('pointerleave', hide);
|
|
395
|
+
destroyTooltip(root);
|
|
396
|
+
if (crosshairs) hideRuleY(root);
|
|
387
397
|
};
|
|
388
398
|
}
|
|
389
399
|
|
|
@@ -437,6 +447,7 @@ export function tooltip(
|
|
|
437
447
|
root.removeEventListener('pointerover', pointerover);
|
|
438
448
|
root.removeEventListener('pointermove', pointerover);
|
|
439
449
|
root.removeEventListener('pointerout', pointerout);
|
|
450
|
+
destroyTooltip(root);
|
|
440
451
|
};
|
|
441
452
|
}
|
|
442
453
|
|
|
@@ -2,6 +2,7 @@ import { DisplayObject } from '@antv/g';
|
|
|
2
2
|
import { ascending } from 'd3-array';
|
|
3
3
|
import { OverlapDodgeYTransform } from '../spec';
|
|
4
4
|
import { LabelTransformComponent as LLC } from '../runtime';
|
|
5
|
+
import { defined } from '../utils/helper';
|
|
5
6
|
|
|
6
7
|
export type OverlapDodgeYOptions = Omit<OverlapDodgeYTransform, 'type'>;
|
|
7
8
|
|
|
@@ -16,13 +17,19 @@ function useMap<K, V>() {
|
|
|
16
17
|
return [get, set] as const;
|
|
17
18
|
}
|
|
18
19
|
|
|
20
|
+
/**
|
|
21
|
+
* @todo fixme
|
|
22
|
+
*/
|
|
19
23
|
function getBoundsWithoutConnector(shape: DisplayObject) {
|
|
24
|
+
// Remove this line when @antv/g fixed
|
|
25
|
+
// https://github.com/antvis/G/pull/1269#pullrequestreview-1251209956
|
|
26
|
+
if (!defined(shape.style.stroke)) shape.style.stroke = '';
|
|
27
|
+
|
|
20
28
|
const node = shape.cloneNode(true);
|
|
21
29
|
const connectorShape = node.getElementById('connector');
|
|
22
30
|
connectorShape && node.removeChild(connectorShape);
|
|
23
31
|
const { min, max } = node.getRenderBounds();
|
|
24
32
|
node.destroy();
|
|
25
|
-
|
|
26
33
|
return { min, max };
|
|
27
34
|
}
|
|
28
35
|
|
package/src/runtime/component.ts
CHANGED
|
@@ -1,31 +1,25 @@
|
|
|
1
1
|
import { Coordinate } from '@antv/coord';
|
|
2
|
-
import { deepMix } from '@antv/util';
|
|
3
2
|
import {
|
|
4
|
-
|
|
5
|
-
G2CoordinateOptions,
|
|
6
|
-
G2Library,
|
|
7
|
-
G2GuideComponentOptions,
|
|
8
|
-
G2View,
|
|
9
|
-
G2TitleOptions,
|
|
10
|
-
} from './types/options';
|
|
11
|
-
import {
|
|
12
|
-
GuideComponentComponent,
|
|
13
|
-
GuideComponent,
|
|
14
|
-
ScaleComponent,
|
|
15
|
-
Scale,
|
|
16
|
-
} from './types/component';
|
|
17
|
-
import { G2Theme, GuideComponentPosition } from './types/common';
|
|
18
|
-
import {
|
|
19
|
-
isPolar,
|
|
20
|
-
isTranspose,
|
|
3
|
+
isHelix,
|
|
21
4
|
isParallel,
|
|
5
|
+
isPolar,
|
|
6
|
+
isRadial,
|
|
22
7
|
isReflect,
|
|
23
8
|
isReflectY,
|
|
24
9
|
isTheta,
|
|
25
|
-
|
|
26
|
-
isRadial,
|
|
10
|
+
isTranspose,
|
|
27
11
|
} from './coordinate';
|
|
28
12
|
import { useLibrary } from './library';
|
|
13
|
+
import { useRelationScale } from './scale';
|
|
14
|
+
import { G2Theme, GuideComponentPosition } from './types/common';
|
|
15
|
+
import { GuideComponent, GuideComponentComponent } from './types/component';
|
|
16
|
+
import {
|
|
17
|
+
G2CoordinateOptions,
|
|
18
|
+
G2GuideComponentOptions,
|
|
19
|
+
G2Library,
|
|
20
|
+
G2ScaleOptions,
|
|
21
|
+
G2View,
|
|
22
|
+
} from './types/options';
|
|
29
23
|
|
|
30
24
|
export function inferComponent(
|
|
31
25
|
scales: G2ScaleOptions[],
|
|
@@ -104,17 +98,16 @@ export function renderComponent(
|
|
|
104
98
|
theme: G2Theme,
|
|
105
99
|
library: G2Library,
|
|
106
100
|
) {
|
|
107
|
-
const [useScale] = useLibrary<G2ScaleOptions, ScaleComponent, Scale>(
|
|
108
|
-
'scale',
|
|
109
|
-
library,
|
|
110
|
-
);
|
|
111
101
|
const [useGuideComponent] = useLibrary<
|
|
112
102
|
G2GuideComponentOptions,
|
|
113
103
|
GuideComponentComponent,
|
|
114
104
|
GuideComponent
|
|
115
105
|
>('component', library);
|
|
116
106
|
const { scale: scaleDescriptor, bbox, ...options } = component;
|
|
117
|
-
const scale = scaleDescriptor
|
|
107
|
+
const scale = scaleDescriptor
|
|
108
|
+
? useRelationScale(scaleDescriptor, library)
|
|
109
|
+
: null;
|
|
110
|
+
|
|
118
111
|
const { field, domain } = scaleDescriptor || {};
|
|
119
112
|
const value = { field, domain, bbox };
|
|
120
113
|
const render = useGuideComponent(options);
|
package/src/runtime/plot.ts
CHANGED
|
@@ -1,76 +1,81 @@
|
|
|
1
|
+
import { Vector2 } from '@antv/coord';
|
|
1
2
|
import { DisplayObject, IAnimation as GAnimation, Rect } from '@antv/g';
|
|
2
3
|
import { deepMix, upperFirst } from '@antv/util';
|
|
3
|
-
import { format } from 'd3-format';
|
|
4
|
-
import { Vector2 } from '@antv/coord';
|
|
5
4
|
import { group } from 'd3-array';
|
|
5
|
+
import { format } from 'd3-format';
|
|
6
6
|
import { mapObject } from '../utils/array';
|
|
7
|
+
import { CHART_LIFE_CIRCLE, emitEvent } from '../utils/event';
|
|
7
8
|
import {
|
|
8
|
-
copyAttributes,
|
|
9
|
-
error,
|
|
10
|
-
defined,
|
|
11
|
-
useMemo,
|
|
12
9
|
appendTransform,
|
|
13
10
|
compose,
|
|
11
|
+
copyAttributes,
|
|
12
|
+
defined,
|
|
13
|
+
error,
|
|
14
14
|
maybeSubObject,
|
|
15
15
|
subObject,
|
|
16
|
+
useMemo,
|
|
16
17
|
} from '../utils/helper';
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
18
|
+
import { G2Element, select, Selection } from '../utils/selection';
|
|
19
|
+
import { inferComponent, renderComponent } from './component';
|
|
19
20
|
import {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
} from './types/options';
|
|
21
|
+
AREA_CLASS_NAME,
|
|
22
|
+
COMPONENT_CLASS_NAME,
|
|
23
|
+
ELEMENT_CLASS_NAME,
|
|
24
|
+
LABEL_CLASS_NAME,
|
|
25
|
+
LABEL_LAYER_CLASS_NAME,
|
|
26
|
+
MAIN_LAYER_CLASS_NAME,
|
|
27
|
+
PLOT_CLASS_NAME,
|
|
28
|
+
VIEW_CLASS_NAME,
|
|
29
|
+
} from './constant';
|
|
30
|
+
import { createCoordinate } from './coordinate';
|
|
31
|
+
import { computeLayout, placeComponents } from './layout';
|
|
32
|
+
import { useLibrary } from './library';
|
|
33
|
+
import { initializeMark } from './mark';
|
|
34
34
|
import {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
AnimationComponent,
|
|
42
|
-
Animation,
|
|
43
|
-
CompositionComponent,
|
|
44
|
-
Composition,
|
|
45
|
-
InteractionComponent,
|
|
46
|
-
Interaction,
|
|
47
|
-
LabelTransformComponent,
|
|
48
|
-
LabelTransform,
|
|
49
|
-
} from './types/component';
|
|
50
|
-
import { MarkComponent, Mark, CompositeMark, SingleMark } from './types/mark';
|
|
35
|
+
applyScale,
|
|
36
|
+
inferScale,
|
|
37
|
+
syncFacetsScales,
|
|
38
|
+
useRelationScale,
|
|
39
|
+
} from './scale';
|
|
40
|
+
import { applyDataTransform } from './transform';
|
|
51
41
|
import {
|
|
52
|
-
G2ViewDescriptor,
|
|
53
42
|
G2MarkState,
|
|
43
|
+
G2ViewDescriptor,
|
|
54
44
|
G2ViewInstance,
|
|
55
45
|
Primitive,
|
|
56
46
|
} from './types/common';
|
|
57
|
-
import { useLibrary } from './library';
|
|
58
|
-
import { initializeMark } from './mark';
|
|
59
|
-
import { inferComponent, renderComponent } from './component';
|
|
60
|
-
import { computeLayout, placeComponents } from './layout';
|
|
61
|
-
import { createCoordinate } from './coordinate';
|
|
62
|
-
import { applyScale, syncFacetsScales, useRelation, inferScale } from './scale';
|
|
63
|
-
import { applyDataTransform } from './transform';
|
|
64
47
|
import {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
48
|
+
Animation,
|
|
49
|
+
AnimationComponent,
|
|
50
|
+
Composition,
|
|
51
|
+
CompositionComponent,
|
|
52
|
+
Interaction,
|
|
53
|
+
InteractionComponent,
|
|
54
|
+
LabelTransform,
|
|
55
|
+
LabelTransformComponent,
|
|
56
|
+
Scale,
|
|
57
|
+
ScaleComponent,
|
|
58
|
+
Shape,
|
|
59
|
+
ShapeComponent,
|
|
60
|
+
Theme,
|
|
61
|
+
ThemeComponent,
|
|
62
|
+
} from './types/component';
|
|
63
|
+
import { CompositeMark, Mark, MarkComponent, SingleMark } from './types/mark';
|
|
64
|
+
import {
|
|
65
|
+
G2AnimationOptions,
|
|
66
|
+
G2CompositionOptions,
|
|
67
|
+
G2Context,
|
|
68
|
+
G2InteractionOptions,
|
|
69
|
+
G2LabelTransformOptions,
|
|
70
|
+
G2Library,
|
|
71
|
+
G2Mark,
|
|
72
|
+
G2MarkOptions,
|
|
73
|
+
G2ScaleOptions,
|
|
74
|
+
G2ShapeOptions,
|
|
75
|
+
G2ThemeOptions,
|
|
76
|
+
G2View,
|
|
77
|
+
G2ViewTree,
|
|
78
|
+
} from './types/options';
|
|
74
79
|
|
|
75
80
|
export async function plot<T extends G2ViewTree>(
|
|
76
81
|
options: T,
|
|
@@ -164,7 +169,8 @@ export async function plot<T extends G2ViewTree>(
|
|
|
164
169
|
emitEvent(on, CHART_LIFE_CIRCLE.BEFORE_PAINT);
|
|
165
170
|
|
|
166
171
|
// Plot chart.
|
|
167
|
-
const
|
|
172
|
+
const enterContainer = new Map<G2ViewDescriptor, DisplayObject>();
|
|
173
|
+
const updateContainer = new Map<G2ViewDescriptor, DisplayObject>();
|
|
168
174
|
const transitions: GAnimation[] = [];
|
|
169
175
|
selection
|
|
170
176
|
.selectAll(className(VIEW_CLASS_NAME))
|
|
@@ -178,29 +184,68 @@ export async function plot<T extends G2ViewTree>(
|
|
|
178
184
|
.call(applyTranslate)
|
|
179
185
|
.each(function (view) {
|
|
180
186
|
plotView(view, select(this), transitions, library);
|
|
181
|
-
|
|
187
|
+
enterContainer.set(view, this);
|
|
182
188
|
}),
|
|
183
189
|
(update) =>
|
|
184
190
|
update.call(applyTranslate).each(function (view) {
|
|
185
191
|
plotView(view, select(this), transitions, library);
|
|
192
|
+
updateContainer.set(view, this);
|
|
186
193
|
}),
|
|
187
|
-
(exit) =>
|
|
194
|
+
(exit) =>
|
|
195
|
+
exit
|
|
196
|
+
.each(function () {
|
|
197
|
+
// Remove existed interactions.
|
|
198
|
+
const interactions = this['nameInteraction'].values();
|
|
199
|
+
for (const interaction of interactions) {
|
|
200
|
+
interaction.destroy();
|
|
201
|
+
}
|
|
202
|
+
})
|
|
203
|
+
.remove(),
|
|
188
204
|
);
|
|
189
205
|
|
|
190
|
-
// Apply
|
|
191
|
-
const
|
|
192
|
-
|
|
206
|
+
// Apply interactions.
|
|
207
|
+
const viewInstanceof = (
|
|
208
|
+
viewContainer: Map<G2ViewDescriptor, DisplayObject>,
|
|
209
|
+
) => {
|
|
210
|
+
return Array.from(viewContainer.entries()).map(([view, container]) => ({
|
|
193
211
|
view,
|
|
194
212
|
container,
|
|
195
213
|
options: viewNode.get(view),
|
|
196
214
|
update: createUpdateView(select(container), library, context),
|
|
197
|
-
})
|
|
198
|
-
|
|
199
|
-
|
|
215
|
+
}));
|
|
216
|
+
};
|
|
217
|
+
|
|
218
|
+
// Interactions for enter views.
|
|
219
|
+
const enterViewInstances = viewInstanceof(enterContainer);
|
|
220
|
+
for (const target of enterViewInstances) {
|
|
200
221
|
const { options } = target;
|
|
222
|
+
|
|
223
|
+
// A Map index interaction by interaction name.
|
|
224
|
+
const nameInteraction = new Map();
|
|
225
|
+
target.container['nameInteraction'] = nameInteraction;
|
|
226
|
+
|
|
227
|
+
// Apply interactions.
|
|
201
228
|
for (const option of inferInteraction(options)) {
|
|
202
229
|
const interaction = useInteraction(option);
|
|
203
|
-
interaction(target,
|
|
230
|
+
const destroy = interaction(target, enterViewInstances);
|
|
231
|
+
nameInteraction.set(option.type, { destroy });
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
// Interactions for update views.
|
|
236
|
+
const updateViewInstances = viewInstanceof(updateContainer);
|
|
237
|
+
for (const target of updateViewInstances) {
|
|
238
|
+
const { options, container } = target;
|
|
239
|
+
const nameInteraction = container['nameInteraction'];
|
|
240
|
+
for (const option of inferInteraction(options)) {
|
|
241
|
+
// Remove interaction for existed views.
|
|
242
|
+
const prevInteraction = nameInteraction.get(option.type);
|
|
243
|
+
if (prevInteraction) prevInteraction.destroy();
|
|
244
|
+
|
|
245
|
+
// Apply new interaction.
|
|
246
|
+
const interaction = useInteraction(option);
|
|
247
|
+
const destroy = interaction(target, updateViewInstances);
|
|
248
|
+
nameInteraction.set(options.type, { destroy });
|
|
204
249
|
}
|
|
205
250
|
}
|
|
206
251
|
|
|
@@ -424,13 +469,9 @@ function initializeState(
|
|
|
424
469
|
const scale = Object.fromEntries(
|
|
425
470
|
channels.map(({ name, scale }) => [name, scale]),
|
|
426
471
|
);
|
|
427
|
-
|
|
428
472
|
// Transform abstract value to visual value by scales.
|
|
429
473
|
const markScaleInstance = mapObject(scale, (options) => {
|
|
430
|
-
|
|
431
|
-
const [conditionalize] = useRelation(relations);
|
|
432
|
-
const scale = useScale(options);
|
|
433
|
-
return conditionalize(scale);
|
|
474
|
+
return useRelationScale(options, library);
|
|
434
475
|
});
|
|
435
476
|
Object.assign(scaleInstance, markScaleInstance);
|
|
436
477
|
const value = applyScale(channels, markScaleInstance);
|
|
@@ -564,6 +605,8 @@ async function plotView(
|
|
|
564
605
|
),
|
|
565
606
|
(update) =>
|
|
566
607
|
update.each(function (options) {
|
|
608
|
+
const { preserve = false } = options;
|
|
609
|
+
if (preserve) return;
|
|
567
610
|
const newComponent = renderComponent(
|
|
568
611
|
options,
|
|
569
612
|
coordinate,
|
|
@@ -1219,8 +1262,13 @@ function updateLayers(selection: Selection, marks: G2Mark[]) {
|
|
|
1219
1262
|
.attr('className', MAIN_LAYER_CLASS_NAME)
|
|
1220
1263
|
.attr('id', (d) => d.key)
|
|
1221
1264
|
.style('facet', facet)
|
|
1222
|
-
.style('fill', 'transparent')
|
|
1223
|
-
|
|
1265
|
+
.style('fill', 'transparent')
|
|
1266
|
+
.style('zIndex', (d) => d.zIndex ?? 0),
|
|
1267
|
+
(update) =>
|
|
1268
|
+
update
|
|
1269
|
+
.style('facet', facet)
|
|
1270
|
+
.style('fill', 'transparent')
|
|
1271
|
+
.style('zIndex', (d) => d.zIndex ?? 0),
|
|
1224
1272
|
(exit) => exit.remove(),
|
|
1225
1273
|
);
|
|
1226
1274
|
|
package/src/runtime/scale.ts
CHANGED
|
@@ -103,6 +103,20 @@ export function useRelation(
|
|
|
103
103
|
return [conditionalize, deconditionalize];
|
|
104
104
|
}
|
|
105
105
|
|
|
106
|
+
export function useRelationScale(
|
|
107
|
+
options: Record<string, any>,
|
|
108
|
+
library: G2Library,
|
|
109
|
+
) {
|
|
110
|
+
const [useScale] = useLibrary<G2ScaleOptions, ScaleComponent, Scale>(
|
|
111
|
+
'scale',
|
|
112
|
+
library,
|
|
113
|
+
);
|
|
114
|
+
const { relations } = options;
|
|
115
|
+
const [conditionalize] = useRelation(relations);
|
|
116
|
+
const scale = useScale(options);
|
|
117
|
+
return conditionalize(scale);
|
|
118
|
+
}
|
|
119
|
+
|
|
106
120
|
export function syncFacetsScales(states: Map<G2Mark, G2MarkState>[]): void {
|
|
107
121
|
const scales = states
|
|
108
122
|
.flatMap((d) => Array.from(d.values()))
|
package/src/spec/geometry.ts
CHANGED
package/src/spec/interaction.ts
CHANGED
|
@@ -21,7 +21,8 @@ export type Interaction =
|
|
|
21
21
|
| BrushAxisHighlightInteraction
|
|
22
22
|
| BrushFilter
|
|
23
23
|
| BrushYFilter
|
|
24
|
-
| BrushXFilter
|
|
24
|
+
| BrushXFilter
|
|
25
|
+
| SliderFilter;
|
|
25
26
|
// | ElementListHighlightInteraction
|
|
26
27
|
// | LegendActiveInteraction
|
|
27
28
|
// | LegendHighlightInteraction
|
|
@@ -50,6 +51,7 @@ export type InteractionTypes =
|
|
|
50
51
|
| 'brushFilter'
|
|
51
52
|
| 'brushXFilter'
|
|
52
53
|
| 'brushYFilter'
|
|
54
|
+
| 'sliderFilter'
|
|
53
55
|
| InteractionComponent;
|
|
54
56
|
// | 'elementListHighlight'
|
|
55
57
|
// | 'legendActive'
|
|
@@ -164,6 +166,13 @@ export type ChartIndex = {
|
|
|
164
166
|
trailing?: boolean;
|
|
165
167
|
} & Record<`${'rule' | 'label'}${any}`, any>;
|
|
166
168
|
|
|
169
|
+
export type SliderFilter = {
|
|
170
|
+
type?: 'sliderFilter';
|
|
171
|
+
wait?: number;
|
|
172
|
+
leading?: boolean;
|
|
173
|
+
trailing?: boolean;
|
|
174
|
+
};
|
|
175
|
+
|
|
167
176
|
export type ElementListHighlightInteraction = {
|
|
168
177
|
type?: 'elementListHighlight';
|
|
169
178
|
};
|
package/src/spec/transform.ts
CHANGED
|
@@ -140,7 +140,9 @@ export type Selector =
|
|
|
140
140
|
export type SelectTransform = {
|
|
141
141
|
type?: 'select';
|
|
142
142
|
groupBy?: string | string[];
|
|
143
|
-
|
|
143
|
+
channel?: ChannelTypes;
|
|
144
|
+
selector?: Selector;
|
|
145
|
+
};
|
|
144
146
|
|
|
145
147
|
export type SelectXTransform = {
|
|
146
148
|
type?: 'selectX';
|