@antv/g2 5.0.3 → 5.0.5
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 +7 -5
- package/esm/api/chart.js +39 -25
- package/esm/api/chart.js.map +1 -1
- package/esm/api/composition/base.d.ts +1 -0
- package/esm/api/composition/base.js +2 -2
- package/esm/api/composition/base.js.map +1 -1
- package/esm/component/axis.d.ts +5 -2
- package/esm/component/axis.js +30 -19
- package/esm/component/axis.js.map +1 -1
- package/esm/component/constant.d.ts +14 -0
- package/esm/component/constant.js +235 -0
- package/esm/component/constant.js.map +1 -0
- package/esm/component/legendContinuousBlockSize.js +2 -1
- package/esm/component/legendContinuousBlockSize.js.map +1 -1
- package/esm/component/legendContinuousSize.js +14 -5
- package/esm/component/legendContinuousSize.js.map +1 -1
- package/esm/component/slider.js +8 -5
- package/esm/component/slider.js.map +1 -1
- package/esm/interaction/brushFilter.d.ts +1 -1
- package/esm/interaction/brushFilter.js +22 -8
- package/esm/interaction/brushFilter.js.map +1 -1
- package/esm/interaction/brushHighlight.js +1 -1
- package/esm/interaction/brushHighlight.js.map +1 -1
- package/esm/interaction/brushXFilter.d.ts +1 -1
- package/esm/interaction/brushYFilter.d.ts +1 -1
- package/esm/interaction/legendFilter.js +6 -3
- package/esm/interaction/legendFilter.js.map +1 -1
- package/esm/interaction/sliderFilter.js +16 -7
- package/esm/interaction/sliderFilter.js.map +1 -1
- package/esm/interaction/tooltip.js +38 -17
- package/esm/interaction/tooltip.js.map +1 -1
- package/esm/runtime/component.js +2 -92
- package/esm/runtime/component.js.map +1 -1
- package/esm/runtime/plot.js +4 -2
- package/esm/runtime/plot.js.map +1 -1
- package/esm/runtime/render.js +3 -1
- package/esm/runtime/render.js.map +1 -1
- package/esm/runtime/transform.js +5 -7
- package/esm/runtime/transform.js.map +1 -1
- package/esm/shape/label/label.js +3 -2
- package/esm/shape/label/label.js.map +1 -1
- package/esm/shape/lineXY/line.d.ts +22 -1
- package/esm/shape/lineXY/line.js +12 -1
- package/esm/shape/lineXY/line.js.map +1 -1
- package/esm/shape/link/link.d.ts +2 -1
- package/esm/shape/link/link.js +5 -41
- package/esm/shape/link/link.js.map +1 -1
- package/esm/shape/text/advance.js +2 -4
- package/esm/shape/text/advance.js.map +1 -1
- package/esm/shape/utils.d.ts +4 -0
- package/esm/shape/utils.js.map +1 -1
- package/esm/shape/vector/vector.d.ts +1 -0
- package/esm/shape/vector/vector.js +12 -8
- package/esm/shape/vector/vector.js.map +1 -1
- package/esm/transform/sort.js +13 -3
- package/esm/transform/sort.js.map +1 -1
- package/esm/utils/size.d.ts +0 -10
- package/esm/utils/size.js +0 -23
- package/esm/utils/size.js.map +1 -1
- package/lib/api/chart.d.ts +7 -5
- package/lib/api/chart.js +38 -24
- package/lib/api/chart.js.map +1 -1
- package/lib/api/composition/base.d.ts +1 -0
- package/lib/api/composition/base.js +2 -2
- package/lib/api/composition/base.js.map +1 -1
- package/lib/component/axis.d.ts +5 -2
- package/lib/component/axis.js +30 -19
- package/lib/component/axis.js.map +1 -1
- package/lib/component/constant.d.ts +14 -0
- package/lib/component/constant.js +238 -0
- package/lib/component/constant.js.map +1 -0
- package/lib/component/legendContinuousBlockSize.js +2 -1
- package/lib/component/legendContinuousBlockSize.js.map +1 -1
- package/lib/component/legendContinuousSize.js +14 -5
- package/lib/component/legendContinuousSize.js.map +1 -1
- package/lib/component/slider.js +8 -5
- package/lib/component/slider.js.map +1 -1
- package/lib/interaction/brushFilter.d.ts +1 -1
- package/lib/interaction/brushFilter.js +22 -8
- package/lib/interaction/brushFilter.js.map +1 -1
- package/lib/interaction/brushHighlight.js +1 -1
- package/lib/interaction/brushHighlight.js.map +1 -1
- package/lib/interaction/brushXFilter.d.ts +1 -1
- package/lib/interaction/brushYFilter.d.ts +1 -1
- package/lib/interaction/legendFilter.js +6 -3
- package/lib/interaction/legendFilter.js.map +1 -1
- package/lib/interaction/sliderFilter.js +16 -7
- package/lib/interaction/sliderFilter.js.map +1 -1
- package/lib/interaction/tooltip.js +37 -16
- package/lib/interaction/tooltip.js.map +1 -1
- package/lib/runtime/component.js +2 -92
- package/lib/runtime/component.js.map +1 -1
- package/lib/runtime/plot.js +4 -2
- package/lib/runtime/plot.js.map +1 -1
- package/lib/runtime/render.js +3 -1
- package/lib/runtime/render.js.map +1 -1
- package/lib/runtime/transform.js +5 -7
- package/lib/runtime/transform.js.map +1 -1
- package/lib/shape/label/label.js +3 -2
- package/lib/shape/label/label.js.map +1 -1
- package/lib/shape/lineXY/line.d.ts +22 -1
- package/lib/shape/lineXY/line.js +12 -1
- package/lib/shape/lineXY/line.js.map +1 -1
- package/lib/shape/link/link.d.ts +2 -1
- package/lib/shape/link/link.js +5 -41
- package/lib/shape/link/link.js.map +1 -1
- package/lib/shape/text/advance.js +2 -4
- package/lib/shape/text/advance.js.map +1 -1
- package/lib/shape/utils.d.ts +4 -0
- package/lib/shape/utils.js.map +1 -1
- package/lib/shape/vector/vector.d.ts +1 -0
- package/lib/shape/vector/vector.js +12 -8
- package/lib/shape/vector/vector.js.map +1 -1
- package/lib/transform/sort.js +13 -3
- package/lib/transform/sort.js.map +1 -1
- package/lib/utils/size.d.ts +0 -10
- package/lib/utils/size.js +1 -25
- package/lib/utils/size.js.map +1 -1
- package/package.json +2 -2
- package/src/api/chart.ts +49 -42
- package/src/api/composition/base.ts +4 -2
- package/src/component/axis.ts +55 -23
- package/src/component/constant.ts +237 -0
- package/src/component/legendContinuousBlockSize.ts +2 -3
- package/src/component/legendContinuousSize.ts +21 -12
- package/src/component/slider.ts +10 -5
- package/src/interaction/brushFilter.ts +25 -8
- package/src/interaction/brushHighlight.ts +1 -1
- package/src/interaction/legendFilter.ts +6 -3
- package/src/interaction/sliderFilter.ts +21 -7
- package/src/interaction/tooltip.ts +64 -28
- package/src/runtime/component.ts +2 -98
- package/src/runtime/plot.ts +4 -1
- package/src/runtime/render.ts +3 -1
- package/src/runtime/transform.ts +5 -7
- package/src/shape/label/label.ts +13 -2
- package/src/shape/lineXY/line.ts +45 -2
- package/src/shape/link/link.ts +6 -38
- package/src/shape/text/advance.ts +11 -2
- package/src/shape/utils.ts +4 -0
- package/src/shape/vector/vector.ts +12 -9
- package/src/transform/sort.ts +12 -3
- package/src/utils/size.ts +0 -31
- package/CHANGELOG.md +0 -38
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
// [legend type, [channels, scale type][][]]
|
|
2
|
+
type InferStrategy = [string, [string, string][][]];
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @examples
|
|
6
|
+
* ✅
|
|
7
|
+
* color - `discrete`, shape - `constant`
|
|
8
|
+
* legendCategory.rule[27] is matched
|
|
9
|
+
*
|
|
10
|
+
* ❎
|
|
11
|
+
* shape - `discrete`, size - `constant`
|
|
12
|
+
* There are no rules to match
|
|
13
|
+
*
|
|
14
|
+
*/
|
|
15
|
+
export const LEGEND_INFER_STRATEGIES: InferStrategy[] = [
|
|
16
|
+
[
|
|
17
|
+
'legendCategory',
|
|
18
|
+
[
|
|
19
|
+
[
|
|
20
|
+
['color', 'discrete'],
|
|
21
|
+
['opacity', 'discrete'],
|
|
22
|
+
['shape', 'discrete'],
|
|
23
|
+
['size', 'constant'],
|
|
24
|
+
],
|
|
25
|
+
[
|
|
26
|
+
['color', 'discrete'],
|
|
27
|
+
['opacity', 'constant'],
|
|
28
|
+
['shape', 'discrete'],
|
|
29
|
+
['size', 'constant'],
|
|
30
|
+
],
|
|
31
|
+
[
|
|
32
|
+
['color', 'discrete'],
|
|
33
|
+
['opacity', 'discrete'],
|
|
34
|
+
['shape', 'constant'],
|
|
35
|
+
['size', 'constant'],
|
|
36
|
+
],
|
|
37
|
+
[
|
|
38
|
+
['color', 'discrete'],
|
|
39
|
+
['opacity', 'constant'],
|
|
40
|
+
['shape', 'constant'],
|
|
41
|
+
['size', 'constant'],
|
|
42
|
+
],
|
|
43
|
+
[
|
|
44
|
+
['color', 'constant'],
|
|
45
|
+
['opacity', 'discrete'],
|
|
46
|
+
['shape', 'discrete'],
|
|
47
|
+
['size', 'constant'],
|
|
48
|
+
],
|
|
49
|
+
[
|
|
50
|
+
['color', 'constant'],
|
|
51
|
+
['opacity', 'constant'],
|
|
52
|
+
['shape', 'discrete'],
|
|
53
|
+
['size', 'constant'],
|
|
54
|
+
],
|
|
55
|
+
[
|
|
56
|
+
['color', 'constant'],
|
|
57
|
+
['opacity', 'discrete'],
|
|
58
|
+
['shape', 'constant'],
|
|
59
|
+
['size', 'constant'],
|
|
60
|
+
],
|
|
61
|
+
[
|
|
62
|
+
['color', 'discrete'],
|
|
63
|
+
['shape', 'discrete'],
|
|
64
|
+
['size', 'constant'],
|
|
65
|
+
],
|
|
66
|
+
[
|
|
67
|
+
['color', 'discrete'],
|
|
68
|
+
['opacity', 'discrete'],
|
|
69
|
+
['shape', 'discrete'],
|
|
70
|
+
],
|
|
71
|
+
[
|
|
72
|
+
['color', 'discrete'],
|
|
73
|
+
['opacity', 'discrete'],
|
|
74
|
+
['size', 'constant'],
|
|
75
|
+
],
|
|
76
|
+
[
|
|
77
|
+
['color', 'discrete'],
|
|
78
|
+
['opacity', 'constant'],
|
|
79
|
+
['shape', 'discrete'],
|
|
80
|
+
],
|
|
81
|
+
[
|
|
82
|
+
['color', 'discrete'],
|
|
83
|
+
['opacity', 'constant'],
|
|
84
|
+
['size', 'constant'],
|
|
85
|
+
],
|
|
86
|
+
[
|
|
87
|
+
['color', 'discrete'],
|
|
88
|
+
['shape', 'constant'],
|
|
89
|
+
['size', 'constant'],
|
|
90
|
+
],
|
|
91
|
+
[
|
|
92
|
+
['color', 'discrete'],
|
|
93
|
+
['opacity', 'discrete'],
|
|
94
|
+
['shape', 'constant'],
|
|
95
|
+
],
|
|
96
|
+
[
|
|
97
|
+
['color', 'discrete'],
|
|
98
|
+
['opacity', 'constant'],
|
|
99
|
+
['shape', 'constant'],
|
|
100
|
+
],
|
|
101
|
+
[
|
|
102
|
+
['color', 'constant'],
|
|
103
|
+
['shape', 'discrete'],
|
|
104
|
+
['size', 'constant'],
|
|
105
|
+
],
|
|
106
|
+
[
|
|
107
|
+
['color', 'constant'],
|
|
108
|
+
['opacity', 'discrete'],
|
|
109
|
+
['shape', 'discrete'],
|
|
110
|
+
],
|
|
111
|
+
[
|
|
112
|
+
['color', 'constant'],
|
|
113
|
+
['opacity', 'discrete'],
|
|
114
|
+
['size', 'constant'],
|
|
115
|
+
],
|
|
116
|
+
[
|
|
117
|
+
['color', 'constant'],
|
|
118
|
+
['opacity', 'constant'],
|
|
119
|
+
['shape', 'discrete'],
|
|
120
|
+
],
|
|
121
|
+
// [
|
|
122
|
+
// ['color', 'constant'],
|
|
123
|
+
// ['opacity', 'constant'],
|
|
124
|
+
// ['size', 'constant'],
|
|
125
|
+
// ],
|
|
126
|
+
// [
|
|
127
|
+
// ['color', 'constant'],
|
|
128
|
+
// ['shape', 'constant'],
|
|
129
|
+
// ['size', 'constant'],
|
|
130
|
+
// ],
|
|
131
|
+
[
|
|
132
|
+
['color', 'constant'],
|
|
133
|
+
['opacity', 'discrete'],
|
|
134
|
+
['shape', 'constant'],
|
|
135
|
+
],
|
|
136
|
+
[
|
|
137
|
+
['color', 'discrete'],
|
|
138
|
+
['shape', 'discrete'],
|
|
139
|
+
],
|
|
140
|
+
[
|
|
141
|
+
['color', 'discrete'],
|
|
142
|
+
['size', 'constant'],
|
|
143
|
+
],
|
|
144
|
+
[
|
|
145
|
+
['color', 'discrete'],
|
|
146
|
+
['opacity', 'discrete'],
|
|
147
|
+
],
|
|
148
|
+
[
|
|
149
|
+
['color', 'discrete'],
|
|
150
|
+
['opacity', 'constant'],
|
|
151
|
+
],
|
|
152
|
+
[
|
|
153
|
+
['color', 'discrete'],
|
|
154
|
+
['shape', 'constant'],
|
|
155
|
+
],
|
|
156
|
+
[
|
|
157
|
+
['color', 'constant'],
|
|
158
|
+
['shape', 'discrete'],
|
|
159
|
+
],
|
|
160
|
+
[
|
|
161
|
+
['color', 'constant'],
|
|
162
|
+
['size', 'constant'],
|
|
163
|
+
],
|
|
164
|
+
[
|
|
165
|
+
['color', 'constant'],
|
|
166
|
+
['opacity', 'discrete'],
|
|
167
|
+
],
|
|
168
|
+
// [
|
|
169
|
+
// ['color', 'constant'],
|
|
170
|
+
// ['opacity', 'constant'],
|
|
171
|
+
// ],
|
|
172
|
+
// [
|
|
173
|
+
// ['color', 'constant'],
|
|
174
|
+
// ['shape', 'constant'],
|
|
175
|
+
// ],
|
|
176
|
+
[['color', 'discrete']],
|
|
177
|
+
// [['color', 'constant']],
|
|
178
|
+
],
|
|
179
|
+
],
|
|
180
|
+
[
|
|
181
|
+
'legendContinuousSize',
|
|
182
|
+
[
|
|
183
|
+
[
|
|
184
|
+
['color', 'continuous'],
|
|
185
|
+
['opacity', 'continuous'],
|
|
186
|
+
['size', 'continuous'],
|
|
187
|
+
],
|
|
188
|
+
[
|
|
189
|
+
['color', 'constant'],
|
|
190
|
+
['opacity', 'continuous'],
|
|
191
|
+
['size', 'continuous'],
|
|
192
|
+
],
|
|
193
|
+
[
|
|
194
|
+
['color', 'continuous'],
|
|
195
|
+
['size', 'continuous'],
|
|
196
|
+
],
|
|
197
|
+
[
|
|
198
|
+
['color', 'constant'],
|
|
199
|
+
['size', 'continuous'],
|
|
200
|
+
],
|
|
201
|
+
],
|
|
202
|
+
],
|
|
203
|
+
[
|
|
204
|
+
'legendContinuousBlockSize',
|
|
205
|
+
[
|
|
206
|
+
[
|
|
207
|
+
['color', 'distribution'],
|
|
208
|
+
['opacity', 'distribution'],
|
|
209
|
+
['size', 'distribution'],
|
|
210
|
+
],
|
|
211
|
+
[
|
|
212
|
+
['color', 'distribution'],
|
|
213
|
+
['size', 'distribution'],
|
|
214
|
+
],
|
|
215
|
+
],
|
|
216
|
+
],
|
|
217
|
+
[
|
|
218
|
+
'legendContinuousBlock',
|
|
219
|
+
[
|
|
220
|
+
[
|
|
221
|
+
['color', 'distribution'],
|
|
222
|
+
['opacity', 'continuous'],
|
|
223
|
+
],
|
|
224
|
+
[['color', 'distribution']],
|
|
225
|
+
],
|
|
226
|
+
],
|
|
227
|
+
[
|
|
228
|
+
'legendContinuous',
|
|
229
|
+
[
|
|
230
|
+
[
|
|
231
|
+
['color', 'continuous'],
|
|
232
|
+
['opacity', 'continuous'],
|
|
233
|
+
],
|
|
234
|
+
[['color', 'continuous']],
|
|
235
|
+
],
|
|
236
|
+
],
|
|
237
|
+
];
|
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
import { GuideComponentComponent as GCC } from '../runtime';
|
|
2
2
|
import { LegendContinuous, LegendContinuousOptions } from './legendContinuous';
|
|
3
|
+
import { LegendContinuousSize } from './legendContinuousSize';
|
|
3
4
|
|
|
4
5
|
export type LegendContinuousBlockSizeOptions = LegendContinuousOptions;
|
|
5
6
|
|
|
6
7
|
export const LegendContinuousBlockSize: GCC<
|
|
7
8
|
LegendContinuousBlockSizeOptions
|
|
8
9
|
> = (options) => {
|
|
9
|
-
return
|
|
10
|
-
Object.assign({}, { type: 'size', block: true, tick: false }, options),
|
|
11
|
-
);
|
|
10
|
+
return LegendContinuousSize(Object.assign({}, { block: true }, options));
|
|
12
11
|
};
|
|
13
12
|
|
|
14
13
|
LegendContinuousBlockSize.props = {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { GuideComponentComponent as GCC } from '../runtime';
|
|
2
|
+
import { scaleOf } from './utils';
|
|
2
3
|
import { LegendContinuous, LegendContinuousOptions } from './legendContinuous';
|
|
3
4
|
|
|
4
5
|
export type LegendContinuousSizeOptions = LegendContinuousOptions;
|
|
@@ -6,18 +7,26 @@ export type LegendContinuousSizeOptions = LegendContinuousOptions;
|
|
|
6
7
|
export const LegendContinuousSize: GCC<LegendContinuousSizeOptions> = (
|
|
7
8
|
options,
|
|
8
9
|
) => {
|
|
9
|
-
return
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
10
|
+
return (context) => {
|
|
11
|
+
const { scales } = context;
|
|
12
|
+
const sizeScale = scaleOf(scales, 'size');
|
|
13
|
+
return LegendContinuous(
|
|
14
|
+
Object.assign(
|
|
15
|
+
{},
|
|
16
|
+
{
|
|
17
|
+
type: 'size',
|
|
18
|
+
tick: false,
|
|
19
|
+
data: sizeScale.getOptions().domain.map((value, index) => ({
|
|
20
|
+
value,
|
|
21
|
+
label: String(value),
|
|
22
|
+
})),
|
|
23
|
+
labelFilter: (datum, index, data) =>
|
|
24
|
+
index === 0 || index === data.length - 1,
|
|
25
|
+
},
|
|
26
|
+
options,
|
|
27
|
+
),
|
|
28
|
+
)(context);
|
|
29
|
+
};
|
|
21
30
|
};
|
|
22
31
|
|
|
23
32
|
LegendContinuousSize.props = {
|
package/src/component/slider.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Slider as SliderComponent } from '@antv/gui';
|
|
2
2
|
import { format } from 'd3-format';
|
|
3
|
+
import { isTranspose } from '../utils/coordinate';
|
|
3
4
|
import { GuideComponentComponent as GCC } from '../runtime';
|
|
4
5
|
import { invert } from '../utils/scale';
|
|
5
6
|
|
|
@@ -13,9 +14,10 @@ export type SliderOptions = {
|
|
|
13
14
|
*/
|
|
14
15
|
export const Slider: GCC<SliderOptions> = (options) => {
|
|
15
16
|
// do not pass size.
|
|
16
|
-
const { orientation, labelFormatter, size, style, ...rest } =
|
|
17
|
+
const { orientation, labelFormatter, size, style, position, ...rest } =
|
|
18
|
+
options;
|
|
17
19
|
|
|
18
|
-
return ({ scales: [scale], value, theme }) => {
|
|
20
|
+
return ({ scales: [scale], value, theme, coordinate }) => {
|
|
19
21
|
const { bbox } = value;
|
|
20
22
|
const { x, y, width, height } = bbox;
|
|
21
23
|
const { slider: sliderTheme = {} } = theme;
|
|
@@ -25,17 +27,20 @@ export const Slider: GCC<SliderOptions> = (options) => {
|
|
|
25
27
|
? format(labelFormatter)
|
|
26
28
|
: labelFormatter;
|
|
27
29
|
|
|
30
|
+
const isHorizontal = orientation === 'horizontal';
|
|
31
|
+
const reverse = isTranspose(coordinate) && isHorizontal;
|
|
32
|
+
|
|
28
33
|
return new SliderComponent({
|
|
29
34
|
className: 'slider',
|
|
30
35
|
style: Object.assign({}, sliderTheme, {
|
|
31
36
|
x,
|
|
32
37
|
y,
|
|
33
|
-
trackLength:
|
|
38
|
+
trackLength: isHorizontal ? width : height,
|
|
34
39
|
orientation,
|
|
35
40
|
formatter: (v) => {
|
|
36
41
|
const f = formatter || defaultFormatter;
|
|
37
|
-
|
|
38
|
-
const tick = invert(scale,
|
|
42
|
+
const v1 = reverse ? 1 - v : v;
|
|
43
|
+
const tick = invert(scale, v1, true);
|
|
39
44
|
return f(tick);
|
|
40
45
|
},
|
|
41
46
|
...style,
|
|
@@ -48,14 +48,14 @@ export function brushFilter(
|
|
|
48
48
|
root.addEventListener('click', click);
|
|
49
49
|
|
|
50
50
|
// Filter when brush created.
|
|
51
|
-
function brushcreated(x, y, x1, y1) {
|
|
52
|
-
filter(x, y, x1, y1);
|
|
51
|
+
function brushcreated(x, y, x1, y1, event) {
|
|
52
|
+
filter(x, y, x1, y1, event);
|
|
53
53
|
brush.remove();
|
|
54
54
|
}
|
|
55
55
|
|
|
56
56
|
// Reset when dblclick.
|
|
57
57
|
function click(e) {
|
|
58
|
-
if (isDblclick(e)) reset();
|
|
58
|
+
if (isDblclick(e)) reset(e);
|
|
59
59
|
}
|
|
60
60
|
|
|
61
61
|
return () => {
|
|
@@ -65,7 +65,7 @@ export function brushFilter(
|
|
|
65
65
|
}
|
|
66
66
|
|
|
67
67
|
export function BrushFilter({ hideX = true, hideY = true, ...rest }) {
|
|
68
|
-
return (target, viewInstances) => {
|
|
68
|
+
return (target, viewInstances, emitter) => {
|
|
69
69
|
const { container, view, options: viewOptions, update } = target;
|
|
70
70
|
const plotArea = selectPlotArea(container);
|
|
71
71
|
const defaultOptions = {
|
|
@@ -82,7 +82,7 @@ export function BrushFilter({ hideX = true, hideY = true, ...rest }) {
|
|
|
82
82
|
|
|
83
83
|
return brushFilter(plotArea, {
|
|
84
84
|
brushRegion: (x, y, x1, y1) => [x, y, x1, y1],
|
|
85
|
-
filter: async (x, y, x1, y1) => {
|
|
85
|
+
filter: async (x, y, x1, y1, event) => {
|
|
86
86
|
// Avoid redundant filter.
|
|
87
87
|
if (filtering) return;
|
|
88
88
|
filtering = true;
|
|
@@ -99,6 +99,8 @@ export function BrushFilter({ hideX = true, hideY = true, ...rest }) {
|
|
|
99
99
|
|
|
100
100
|
// Update the domain of x and y scale to filter data.
|
|
101
101
|
const { marks } = viewOptions;
|
|
102
|
+
const domainX = domainOf(scaleX, [p0[0], p1[0]]);
|
|
103
|
+
const domainY = domainOf(scaleY, [p0[1], p1[1]]);
|
|
102
104
|
const newMarks = marks.map((mark) =>
|
|
103
105
|
deepMix(
|
|
104
106
|
{
|
|
@@ -111,13 +113,18 @@ export function BrushFilter({ hideX = true, hideY = true, ...rest }) {
|
|
|
111
113
|
mark,
|
|
112
114
|
{
|
|
113
115
|
scale: {
|
|
114
|
-
x: { domain:
|
|
115
|
-
y: { domain:
|
|
116
|
+
x: { domain: domainX },
|
|
117
|
+
y: { domain: domainY },
|
|
116
118
|
},
|
|
117
119
|
},
|
|
118
120
|
),
|
|
119
121
|
);
|
|
120
122
|
|
|
123
|
+
// Emit event.
|
|
124
|
+
event.data = event.data || {};
|
|
125
|
+
event.data.selection = [domainX, domainY];
|
|
126
|
+
emitter.emit('brush:filter', event);
|
|
127
|
+
|
|
121
128
|
// Rerender and update view.
|
|
122
129
|
const newOptions = {
|
|
123
130
|
...viewOptions,
|
|
@@ -129,8 +136,18 @@ export function BrushFilter({ hideX = true, hideY = true, ...rest }) {
|
|
|
129
136
|
filtering = false;
|
|
130
137
|
filtered = true;
|
|
131
138
|
},
|
|
132
|
-
reset: () => {
|
|
139
|
+
reset: (event) => {
|
|
133
140
|
if (filtering || !filtered) return;
|
|
141
|
+
|
|
142
|
+
// Emit event.
|
|
143
|
+
const { scale } = view;
|
|
144
|
+
const { x: scaleX, y: scaleY } = scale;
|
|
145
|
+
const domainX = scaleX.getOptions().domain;
|
|
146
|
+
const domainY = scaleY.getOptions().domain;
|
|
147
|
+
event.data = event.data || {};
|
|
148
|
+
event.data.selection = [domainX, domainY];
|
|
149
|
+
emitter.emit('brush:filter', event);
|
|
150
|
+
|
|
134
151
|
filtered = false;
|
|
135
152
|
newView = view;
|
|
136
153
|
update(viewOptions);
|
|
@@ -169,11 +169,14 @@ export function LegendFilter() {
|
|
|
169
169
|
};
|
|
170
170
|
|
|
171
171
|
if (!legends.length) {
|
|
172
|
-
|
|
172
|
+
const onFilter = (options) => {
|
|
173
173
|
const { values, channel } = options;
|
|
174
174
|
filter(channel, values);
|
|
175
|
-
}
|
|
176
|
-
|
|
175
|
+
};
|
|
176
|
+
emitter.on('legend:filter', onFilter);
|
|
177
|
+
return () => {
|
|
178
|
+
emitter.off('legend:filter', onFilter);
|
|
179
|
+
};
|
|
177
180
|
}
|
|
178
181
|
|
|
179
182
|
const removes = legends.map((legend) => {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { deepMix, throttle } from '@antv/util';
|
|
2
|
+
import { isTranspose } from '../utils/coordinate';
|
|
2
3
|
import { invert, domainOf } from '../utils/scale';
|
|
3
4
|
|
|
4
5
|
export const SLIDER_CLASS_NAME = 'slider';
|
|
@@ -36,10 +37,11 @@ function filterDataByDomain(options, scaleOptions) {
|
|
|
36
37
|
};
|
|
37
38
|
}
|
|
38
39
|
|
|
39
|
-
function abstractValue(values, scale) {
|
|
40
|
+
function abstractValue(values, scale, reverse) {
|
|
40
41
|
const [x, x1] = values;
|
|
41
|
-
const
|
|
42
|
-
const
|
|
42
|
+
const v = reverse ? (d) => 1 - d : (d) => d;
|
|
43
|
+
const d0 = invert(scale, v(x), true);
|
|
44
|
+
const d1 = invert(scale, v(x1), false);
|
|
43
45
|
return domainOf(scale, [d0, d1]);
|
|
44
46
|
}
|
|
45
47
|
|
|
@@ -57,8 +59,16 @@ export function SliderFilter({
|
|
|
57
59
|
if (!sliders.length) return () => {};
|
|
58
60
|
|
|
59
61
|
let filtering = false;
|
|
60
|
-
const { scale } = view;
|
|
62
|
+
const { scale, coordinate } = view;
|
|
61
63
|
const { x: scaleX, y: scaleY } = scale;
|
|
64
|
+
const transposed = isTranspose(coordinate);
|
|
65
|
+
|
|
66
|
+
const channelOf = (orientation) => {
|
|
67
|
+
const channel0 = orientation === 'vertical' ? 'y' : 'x';
|
|
68
|
+
const channel1 = orientation === 'vertical' ? 'x' : 'y';
|
|
69
|
+
if (transposed) return [channel1, channel0];
|
|
70
|
+
return [channel0, channel1];
|
|
71
|
+
};
|
|
62
72
|
|
|
63
73
|
const sliderHandler = new Map();
|
|
64
74
|
|
|
@@ -77,14 +87,18 @@ export function SliderFilter({
|
|
|
77
87
|
if (filtering) return;
|
|
78
88
|
filtering = true;
|
|
79
89
|
|
|
90
|
+
const [channel0, channel1] = channelOf(orientation);
|
|
91
|
+
|
|
80
92
|
// Update domain of the current channel.
|
|
81
|
-
const channel0 = orientation === 'vertical' ? 'y' : 'x';
|
|
82
93
|
const scale0 = scale[channel0];
|
|
83
|
-
const domain0 = abstractValue(
|
|
94
|
+
const domain0 = abstractValue(
|
|
95
|
+
values,
|
|
96
|
+
scale0,
|
|
97
|
+
transposed && orientation === 'horizontal',
|
|
98
|
+
);
|
|
84
99
|
channelDomain[channel0] = domain0;
|
|
85
100
|
|
|
86
101
|
// Get domain of the other channel.
|
|
87
|
-
const channel1 = orientation === 'vertical' ? 'x' : 'y';
|
|
88
102
|
const domain1 = channelDomain[channel1];
|
|
89
103
|
|
|
90
104
|
// Filter data.
|