@antv/g2 5.0.5 → 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 +7 -8
- package/esm/api/chart.js +34 -92
- 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.d.ts +5 -1
- package/esm/interaction/brushFilter.js +26 -23
- package/esm/interaction/brushFilter.js.map +1 -1
- package/esm/interaction/brushHighlight.d.ts +10 -3
- package/esm/interaction/brushHighlight.js +242 -30
- package/esm/interaction/brushHighlight.js.map +1 -1
- package/esm/interaction/brushXHighlight.d.ts +2 -1
- package/esm/interaction/brushXHighlight.js +1 -1
- package/esm/interaction/brushXHighlight.js.map +1 -1
- package/esm/interaction/brushYHighlight.d.ts +2 -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/esm/utils/scale.d.ts +2 -0
- package/esm/utils/scale.js +21 -0
- package/esm/utils/scale.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 +7 -8
- package/lib/api/chart.js +39 -99
- 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.d.ts +5 -1
- package/lib/interaction/brushFilter.js +25 -22
- package/lib/interaction/brushFilter.js.map +1 -1
- package/lib/interaction/brushHighlight.d.ts +10 -3
- package/lib/interaction/brushHighlight.js +241 -29
- package/lib/interaction/brushHighlight.js.map +1 -1
- package/lib/interaction/brushXHighlight.d.ts +2 -1
- package/lib/interaction/brushXHighlight.js +1 -1
- package/lib/interaction/brushXHighlight.js.map +1 -1
- package/lib/interaction/brushYHighlight.d.ts +2 -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/lib/utils/scale.d.ts +2 -0
- package/lib/utils/scale.js +24 -1
- package/lib/utils/scale.js.map +1 -1
- package/package.json +7 -6
- package/src/animation/morphing.ts +5 -0
- package/src/api/chart.ts +45 -116
- 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 +37 -22
- package/src/interaction/brushHighlight.ts +309 -23
- 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/src/utils/scale.ts +23 -0
- /package/esm/{shape → utils}/createElement.js +0 -0
- /package/lib/{shape → utils}/createElement.js +0 -0
|
@@ -1,17 +1,22 @@
|
|
|
1
|
+
import { parseColor } from '@antv/g';
|
|
1
2
|
import { Continuous } from '@antv/gui';
|
|
2
3
|
import { Quantile, Quantize, Threshold } from '@antv/scale';
|
|
3
4
|
import { format } from 'd3-format';
|
|
4
5
|
import type {
|
|
5
6
|
FlexLayout,
|
|
7
|
+
G2Theme,
|
|
6
8
|
GuideComponentComponent as GCC,
|
|
9
|
+
GuideComponentOrientation as GCO,
|
|
7
10
|
GuideComponentPosition as GCP,
|
|
8
11
|
Scale,
|
|
9
12
|
} from '../runtime';
|
|
13
|
+
import { lastOf } from '../utils/array';
|
|
10
14
|
import {
|
|
11
|
-
adaptor,
|
|
12
15
|
G2Layout,
|
|
16
|
+
adaptor,
|
|
13
17
|
inferComponentLayout,
|
|
14
18
|
inferComponentShape,
|
|
19
|
+
isHorizontal,
|
|
15
20
|
scaleOf,
|
|
16
21
|
titleContent,
|
|
17
22
|
} from './utils';
|
|
@@ -23,68 +28,171 @@ export type LegendContinuousOptions = {
|
|
|
23
28
|
[key: string]: any;
|
|
24
29
|
};
|
|
25
30
|
|
|
26
|
-
|
|
27
|
-
|
|
31
|
+
type Shape = {
|
|
32
|
+
orientation: string;
|
|
33
|
+
width: number;
|
|
34
|
+
height: number;
|
|
35
|
+
length: number;
|
|
36
|
+
size: number;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
type Config = {
|
|
40
|
+
orientation: string;
|
|
41
|
+
width: number;
|
|
42
|
+
height: number;
|
|
43
|
+
color: string[];
|
|
44
|
+
data: any[];
|
|
45
|
+
labelFilter?: (datum: any, index: number) => boolean;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
function calculateFinalSize(size: number, defaultSize: number): number {
|
|
49
|
+
return Math.min(size, defaultSize);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function updateShapeDimensions(
|
|
53
|
+
shape: Shape,
|
|
54
|
+
finalSize: number,
|
|
55
|
+
orientation: Exclude<GCO, number>,
|
|
56
|
+
): Shape {
|
|
57
|
+
shape.size = finalSize;
|
|
58
|
+
if (isHorizontal(orientation)) {
|
|
59
|
+
shape.height = finalSize;
|
|
60
|
+
} else {
|
|
61
|
+
shape.width = finalSize;
|
|
62
|
+
}
|
|
63
|
+
return shape;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function inferContinuousShape(
|
|
28
67
|
value: Record<string, any>,
|
|
29
68
|
options: LegendContinuousOptions,
|
|
30
69
|
component: GCC,
|
|
31
|
-
) {
|
|
32
|
-
const
|
|
33
|
-
const
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
options,
|
|
38
|
-
component,
|
|
70
|
+
): Shape {
|
|
71
|
+
const { size } = options;
|
|
72
|
+
const shape = inferComponentShape(value, options, component);
|
|
73
|
+
const finalSize = calculateFinalSize(
|
|
74
|
+
size,
|
|
75
|
+
LegendContinuous.props.defaultLegendSize,
|
|
39
76
|
);
|
|
77
|
+
return updateShapeDimensions(shape, finalSize, shape.orientation);
|
|
78
|
+
}
|
|
40
79
|
|
|
41
|
-
|
|
80
|
+
function getFormatter(max: number) {
|
|
81
|
+
return (value: number) => ({
|
|
82
|
+
value: value / max,
|
|
83
|
+
label: String(value),
|
|
84
|
+
});
|
|
85
|
+
}
|
|
42
86
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
value: index,
|
|
59
|
-
label: value,
|
|
60
|
-
}));
|
|
61
|
-
return {
|
|
62
|
-
data,
|
|
63
|
-
...shape,
|
|
64
|
-
color: range,
|
|
65
|
-
labelFilter: (datum, index) => {
|
|
66
|
-
return index > 0 && index < data.length - 1;
|
|
67
|
-
},
|
|
68
|
-
};
|
|
69
|
-
}
|
|
87
|
+
function getQuantizeOrQuantileConfig(
|
|
88
|
+
shape: Shape,
|
|
89
|
+
colorScale: Threshold,
|
|
90
|
+
min: number,
|
|
91
|
+
max: number,
|
|
92
|
+
range: string[],
|
|
93
|
+
): Config {
|
|
94
|
+
const thresholds = (colorScale as any).thresholds as number[];
|
|
95
|
+
const formatter = getFormatter(max);
|
|
96
|
+
return {
|
|
97
|
+
...shape,
|
|
98
|
+
color: range,
|
|
99
|
+
data: [min, ...thresholds, max].map(formatter),
|
|
100
|
+
};
|
|
101
|
+
}
|
|
70
102
|
|
|
71
|
-
|
|
72
|
-
|
|
103
|
+
function getThresholdConfig(
|
|
104
|
+
shape: Shape,
|
|
105
|
+
colorScale: Threshold,
|
|
106
|
+
range: string[],
|
|
107
|
+
): Config {
|
|
108
|
+
const thresholds = (colorScale as any).thresholds as number[];
|
|
109
|
+
const data = [-Infinity, ...thresholds, Infinity].map((value, index) => ({
|
|
110
|
+
value: index,
|
|
111
|
+
label: value,
|
|
112
|
+
}));
|
|
73
113
|
return {
|
|
74
114
|
...shape,
|
|
75
|
-
data
|
|
115
|
+
data,
|
|
116
|
+
color: range,
|
|
117
|
+
labelFilter: (datum, index) => {
|
|
118
|
+
return index > 0 && index < data.length - 1;
|
|
119
|
+
},
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function rangeOf(scale: Scale) {
|
|
124
|
+
const { domain } = scale.getOptions();
|
|
125
|
+
const [min, max] = [domain[0], lastOf(domain)];
|
|
126
|
+
return [min, max];
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* if color scale is not defined, create a constant color scale based on default color
|
|
131
|
+
* @param scale
|
|
132
|
+
* @param theme
|
|
133
|
+
*/
|
|
134
|
+
function createColorScale(scale: Scale, theme: G2Theme): Scale {
|
|
135
|
+
const { defaultColor } = theme;
|
|
136
|
+
const options = scale.getOptions();
|
|
137
|
+
const newScale = scale.clone();
|
|
138
|
+
newScale.update({ ...options, range: [parseColor(defaultColor).toString()] });
|
|
139
|
+
return newScale;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
function getLinearConfig(
|
|
143
|
+
shape: Shape,
|
|
144
|
+
colorScale: Scale,
|
|
145
|
+
sizeScale: Scale,
|
|
146
|
+
opacityScale: Scale,
|
|
147
|
+
theme: G2Theme,
|
|
148
|
+
): Config {
|
|
149
|
+
const { length } = shape;
|
|
150
|
+
const scale =
|
|
151
|
+
colorScale || createColorScale(sizeScale || opacityScale, theme);
|
|
152
|
+
const [min, max] = rangeOf(scale);
|
|
153
|
+
|
|
154
|
+
return {
|
|
155
|
+
...shape,
|
|
156
|
+
data: scale.getTicks().map((value) => ({ value })),
|
|
76
157
|
color: new Array(length).fill(0).map((d, i) => {
|
|
77
158
|
const value = ((max - min) / (length - 1)) * i + min;
|
|
78
|
-
const color =
|
|
159
|
+
const color = scale.map(value);
|
|
79
160
|
const opacity = opacityScale ? opacityScale.map(value) : 1;
|
|
80
161
|
return color.replace(
|
|
81
|
-
/rgb[a]*\(([\d]{1,3})
|
|
162
|
+
/rgb[a]*\(([\d]{1,3}) *, *([\d]{1,3}) *, *([\d]{1,3})[\S\s]*\)/,
|
|
82
163
|
(match, p1, p2, p3) => `rgba(${p1}, ${p2}, ${p3}, ${opacity})`,
|
|
83
164
|
);
|
|
84
165
|
}),
|
|
85
166
|
};
|
|
86
167
|
}
|
|
87
168
|
|
|
169
|
+
function inferContinuousConfig(
|
|
170
|
+
scales: Scale[],
|
|
171
|
+
value: Record<string, any>,
|
|
172
|
+
options: LegendContinuousOptions,
|
|
173
|
+
component: GCC,
|
|
174
|
+
theme: G2Theme,
|
|
175
|
+
): Config {
|
|
176
|
+
const colorScale = scaleOf(scales, 'color');
|
|
177
|
+
const shape = inferContinuousShape(value, options, component);
|
|
178
|
+
|
|
179
|
+
if (colorScale instanceof Threshold) {
|
|
180
|
+
const { range } = colorScale.getOptions();
|
|
181
|
+
const [min, max] = rangeOf(colorScale);
|
|
182
|
+
// for quantize, quantile scale
|
|
183
|
+
if (colorScale instanceof Quantize || colorScale instanceof Quantile) {
|
|
184
|
+
return getQuantizeOrQuantileConfig(shape, colorScale, min, max, range);
|
|
185
|
+
}
|
|
186
|
+
// for threshold
|
|
187
|
+
return getThresholdConfig(shape, colorScale, range);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
// for linear, pow, sqrt, log, time, utc scale
|
|
191
|
+
const sizeScale = scaleOf(scales, 'size');
|
|
192
|
+
const opacityScale = scaleOf(scales, 'opacity');
|
|
193
|
+
return getLinearConfig(shape, colorScale, sizeScale, opacityScale, theme);
|
|
194
|
+
}
|
|
195
|
+
|
|
88
196
|
/**
|
|
89
197
|
* Guide Component for continuous color scale.
|
|
90
198
|
* @todo Custom style.
|
|
@@ -101,14 +209,40 @@ export const LegendContinuous: GCC<LegendContinuousOptions> = (options) => {
|
|
|
101
209
|
style,
|
|
102
210
|
...rest
|
|
103
211
|
} = options;
|
|
212
|
+
|
|
104
213
|
return ({ scales, value, theme }) => {
|
|
105
214
|
const { bbox } = value;
|
|
106
215
|
const { x, y, width, height } = bbox;
|
|
216
|
+
const finalLayout = inferComponentLayout(position, layout);
|
|
107
217
|
|
|
108
|
-
const
|
|
109
|
-
|
|
110
|
-
|
|
218
|
+
const { continuousLegend: legendTheme = {} } = theme;
|
|
219
|
+
const finalStyle = adaptor(
|
|
220
|
+
Object.assign(
|
|
221
|
+
{},
|
|
222
|
+
legendTheme,
|
|
223
|
+
{
|
|
224
|
+
titleText: titleContent(title),
|
|
225
|
+
titleFontSize: 12,
|
|
226
|
+
handle: false,
|
|
227
|
+
indicator: false,
|
|
228
|
+
labelAlign: 'value',
|
|
229
|
+
labelFormatter:
|
|
230
|
+
typeof labelFormatter === 'string'
|
|
231
|
+
? (d) => format(labelFormatter)(d.label)
|
|
232
|
+
: labelFormatter,
|
|
233
|
+
...inferContinuousConfig(
|
|
234
|
+
scales,
|
|
235
|
+
value,
|
|
236
|
+
options,
|
|
237
|
+
LegendContinuous,
|
|
238
|
+
theme,
|
|
239
|
+
),
|
|
240
|
+
...style,
|
|
241
|
+
},
|
|
242
|
+
rest,
|
|
243
|
+
),
|
|
111
244
|
);
|
|
245
|
+
|
|
112
246
|
const layoutWrapper = new G2Layout({
|
|
113
247
|
style: {
|
|
114
248
|
x,
|
|
@@ -116,38 +250,14 @@ export const LegendContinuous: GCC<LegendContinuousOptions> = (options) => {
|
|
|
116
250
|
width,
|
|
117
251
|
height,
|
|
118
252
|
...finalLayout,
|
|
253
|
+
// @ts-ignore
|
|
254
|
+
subOptions: finalStyle,
|
|
119
255
|
},
|
|
120
256
|
});
|
|
121
257
|
|
|
122
|
-
const { continuousLegend: legendTheme = {} } = theme;
|
|
123
|
-
|
|
124
258
|
layoutWrapper.appendChild(
|
|
125
259
|
new Continuous({
|
|
126
|
-
style:
|
|
127
|
-
Object.assign(
|
|
128
|
-
{},
|
|
129
|
-
legendTheme,
|
|
130
|
-
{
|
|
131
|
-
titleText: titleContent(title),
|
|
132
|
-
titleFontSize: 12,
|
|
133
|
-
handle: false,
|
|
134
|
-
indicator: false,
|
|
135
|
-
labelAlign: 'value',
|
|
136
|
-
labelFormatter:
|
|
137
|
-
typeof labelFormatter === 'string'
|
|
138
|
-
? (d) => format(labelFormatter)(d.label)
|
|
139
|
-
: labelFormatter,
|
|
140
|
-
...inferContinuousConfig(
|
|
141
|
-
scales,
|
|
142
|
-
value,
|
|
143
|
-
options,
|
|
144
|
-
LegendContinuous,
|
|
145
|
-
),
|
|
146
|
-
...style,
|
|
147
|
-
},
|
|
148
|
-
rest,
|
|
149
|
-
),
|
|
150
|
-
),
|
|
260
|
+
style: finalStyle,
|
|
151
261
|
}),
|
|
152
262
|
);
|
|
153
263
|
|
|
@@ -161,4 +271,5 @@ LegendContinuous.props = {
|
|
|
161
271
|
defaultOrder: 1,
|
|
162
272
|
defaultSize: 60,
|
|
163
273
|
defaultLength: 300,
|
|
274
|
+
defaultLegendSize: 60,
|
|
164
275
|
};
|
package/src/component/utils.ts
CHANGED
|
@@ -83,10 +83,21 @@ export function inferComponentLayout(
|
|
|
83
83
|
}
|
|
84
84
|
|
|
85
85
|
export class G2Layout extends Layout {
|
|
86
|
+
get child() {
|
|
87
|
+
return this.children?.[0] as any;
|
|
88
|
+
}
|
|
89
|
+
|
|
86
90
|
update(options: any) {
|
|
87
91
|
this.attr(options);
|
|
88
|
-
const {
|
|
89
|
-
|
|
92
|
+
const { subOptions } = options;
|
|
93
|
+
this.child?.update(subOptions);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export class LegendCategoryLayout extends G2Layout {
|
|
98
|
+
update(options: any) {
|
|
99
|
+
const { subOptions } = options;
|
|
100
|
+
this.child?.update(subOptions);
|
|
90
101
|
}
|
|
91
102
|
}
|
|
92
103
|
|
|
@@ -122,7 +133,7 @@ export function inferComponentShape(
|
|
|
122
133
|
const length = userDefinedLength || defaultLength || bboxLength;
|
|
123
134
|
const orientation = isHorizontal ? 'horizontal' : 'vertical';
|
|
124
135
|
const [width, height] = isHorizontal ? [length, size] : [size, length];
|
|
125
|
-
return { orientation, width, height, size, length };
|
|
136
|
+
return { orientation, width, height, size, length } as const;
|
|
126
137
|
}
|
|
127
138
|
|
|
128
139
|
export function domainOf(scales: Scale[]): any[] {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { deepMix } from '@antv/util';
|
|
2
2
|
import { subObject } from '../utils/helper';
|
|
3
|
-
import {
|
|
3
|
+
import { selectionOf } from '../utils/scale';
|
|
4
4
|
import { brush as createBrush } from './brushHighlight';
|
|
5
5
|
import { selectPlotArea } from './utils';
|
|
6
6
|
|
|
@@ -26,6 +26,10 @@ export function brushFilter(
|
|
|
26
26
|
brushRegion,
|
|
27
27
|
extent: optionalExtent,
|
|
28
28
|
reverse,
|
|
29
|
+
emitter,
|
|
30
|
+
scale,
|
|
31
|
+
coordinate,
|
|
32
|
+
selection,
|
|
29
33
|
series = false,
|
|
30
34
|
...rest
|
|
31
35
|
},
|
|
@@ -49,17 +53,29 @@ export function brushFilter(
|
|
|
49
53
|
|
|
50
54
|
// Filter when brush created.
|
|
51
55
|
function brushcreated(x, y, x1, y1, event) {
|
|
52
|
-
|
|
56
|
+
event.nativeEvent = true;
|
|
57
|
+
filter(selection(x, y, x1, y1), event);
|
|
53
58
|
brush.remove();
|
|
54
59
|
}
|
|
55
60
|
|
|
56
61
|
// Reset when dblclick.
|
|
57
62
|
function click(e) {
|
|
58
|
-
if (isDblclick(e))
|
|
63
|
+
if (isDblclick(e)) {
|
|
64
|
+
e.nativeEvent = true;
|
|
65
|
+
reset(e);
|
|
66
|
+
}
|
|
59
67
|
}
|
|
60
68
|
|
|
69
|
+
const onFilter = ({ nativeEvent, data }) => {
|
|
70
|
+
if (nativeEvent) return;
|
|
71
|
+
const { selection } = data;
|
|
72
|
+
filter(selection, { nativeEvent: false });
|
|
73
|
+
};
|
|
74
|
+
emitter.on('brush:filter', onFilter);
|
|
75
|
+
|
|
61
76
|
return () => {
|
|
62
77
|
brush.destroy();
|
|
78
|
+
emitter.off('brush:filter', onFilter);
|
|
63
79
|
root.removeEventListener('click', click);
|
|
64
80
|
};
|
|
65
81
|
}
|
|
@@ -80,27 +96,21 @@ export function BrushFilter({ hideX = true, hideY = true, ...rest }) {
|
|
|
80
96
|
let filtering = false;
|
|
81
97
|
let newView = view;
|
|
82
98
|
|
|
99
|
+
const { scale, coordinate } = view;
|
|
83
100
|
return brushFilter(plotArea, {
|
|
84
101
|
brushRegion: (x, y, x1, y1) => [x, y, x1, y1],
|
|
85
|
-
|
|
102
|
+
selection: (x, y, x1, y1) => {
|
|
103
|
+
const { scale, coordinate } = newView;
|
|
104
|
+
return selectionOf(x, y, x1, y1, scale, coordinate);
|
|
105
|
+
},
|
|
106
|
+
filter: async (selection, event) => {
|
|
86
107
|
// Avoid redundant filter.
|
|
87
108
|
if (filtering) return;
|
|
88
109
|
filtering = true;
|
|
89
110
|
|
|
90
|
-
// Invert visual range to abstract domain.
|
|
91
|
-
const { scale, coordinate } = newView;
|
|
92
|
-
const { x: scaleX, y: scaleY } = scale;
|
|
93
|
-
const abstractDomain = (point, start) => {
|
|
94
|
-
const [x, y] = coordinate.invert(point);
|
|
95
|
-
return [invert(scaleX, x, start), invert(scaleY, y, start)];
|
|
96
|
-
};
|
|
97
|
-
const p0 = abstractDomain([x, y], true);
|
|
98
|
-
const p1 = abstractDomain([x1, y1], false);
|
|
99
|
-
|
|
100
111
|
// Update the domain of x and y scale to filter data.
|
|
112
|
+
const [domainX, domainY] = selection;
|
|
101
113
|
const { marks } = viewOptions;
|
|
102
|
-
const domainX = domainOf(scaleX, [p0[0], p1[0]]);
|
|
103
|
-
const domainY = domainOf(scaleY, [p0[1], p1[1]]);
|
|
104
114
|
const newMarks = marks.map((mark) =>
|
|
105
115
|
deepMix(
|
|
106
116
|
{
|
|
@@ -121,9 +131,10 @@ export function BrushFilter({ hideX = true, hideY = true, ...rest }) {
|
|
|
121
131
|
);
|
|
122
132
|
|
|
123
133
|
// Emit event.
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
134
|
+
emitter.emit('brush:filter', {
|
|
135
|
+
...event,
|
|
136
|
+
data: { selection: [domainX, domainY] },
|
|
137
|
+
});
|
|
127
138
|
|
|
128
139
|
// Rerender and update view.
|
|
129
140
|
const newOptions = {
|
|
@@ -144,15 +155,19 @@ export function BrushFilter({ hideX = true, hideY = true, ...rest }) {
|
|
|
144
155
|
const { x: scaleX, y: scaleY } = scale;
|
|
145
156
|
const domainX = scaleX.getOptions().domain;
|
|
146
157
|
const domainY = scaleY.getOptions().domain;
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
158
|
+
emitter.emit('brush:filter', {
|
|
159
|
+
...event,
|
|
160
|
+
data: { selection: [domainX, domainY] },
|
|
161
|
+
});
|
|
150
162
|
|
|
151
163
|
filtered = false;
|
|
152
164
|
newView = view;
|
|
153
165
|
update(viewOptions);
|
|
154
166
|
},
|
|
155
167
|
extent: undefined,
|
|
168
|
+
emitter,
|
|
169
|
+
scale,
|
|
170
|
+
coordinate,
|
|
156
171
|
...defaultOptions,
|
|
157
172
|
...rest,
|
|
158
173
|
});
|