@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.
Files changed (146) hide show
  1. package/dist/g2-lite.min.js +3 -3
  2. package/dist/g2.min.js +3 -3
  3. package/esm/api/chart.d.ts +7 -5
  4. package/esm/api/chart.js +39 -25
  5. package/esm/api/chart.js.map +1 -1
  6. package/esm/api/composition/base.d.ts +1 -0
  7. package/esm/api/composition/base.js +2 -2
  8. package/esm/api/composition/base.js.map +1 -1
  9. package/esm/component/axis.d.ts +5 -2
  10. package/esm/component/axis.js +30 -19
  11. package/esm/component/axis.js.map +1 -1
  12. package/esm/component/constant.d.ts +14 -0
  13. package/esm/component/constant.js +235 -0
  14. package/esm/component/constant.js.map +1 -0
  15. package/esm/component/legendContinuousBlockSize.js +2 -1
  16. package/esm/component/legendContinuousBlockSize.js.map +1 -1
  17. package/esm/component/legendContinuousSize.js +14 -5
  18. package/esm/component/legendContinuousSize.js.map +1 -1
  19. package/esm/component/slider.js +8 -5
  20. package/esm/component/slider.js.map +1 -1
  21. package/esm/interaction/brushFilter.d.ts +1 -1
  22. package/esm/interaction/brushFilter.js +22 -8
  23. package/esm/interaction/brushFilter.js.map +1 -1
  24. package/esm/interaction/brushHighlight.js +1 -1
  25. package/esm/interaction/brushHighlight.js.map +1 -1
  26. package/esm/interaction/brushXFilter.d.ts +1 -1
  27. package/esm/interaction/brushYFilter.d.ts +1 -1
  28. package/esm/interaction/legendFilter.js +6 -3
  29. package/esm/interaction/legendFilter.js.map +1 -1
  30. package/esm/interaction/sliderFilter.js +16 -7
  31. package/esm/interaction/sliderFilter.js.map +1 -1
  32. package/esm/interaction/tooltip.js +38 -17
  33. package/esm/interaction/tooltip.js.map +1 -1
  34. package/esm/runtime/component.js +2 -92
  35. package/esm/runtime/component.js.map +1 -1
  36. package/esm/runtime/plot.js +4 -2
  37. package/esm/runtime/plot.js.map +1 -1
  38. package/esm/runtime/render.js +3 -1
  39. package/esm/runtime/render.js.map +1 -1
  40. package/esm/runtime/transform.js +5 -7
  41. package/esm/runtime/transform.js.map +1 -1
  42. package/esm/shape/label/label.js +3 -2
  43. package/esm/shape/label/label.js.map +1 -1
  44. package/esm/shape/lineXY/line.d.ts +22 -1
  45. package/esm/shape/lineXY/line.js +12 -1
  46. package/esm/shape/lineXY/line.js.map +1 -1
  47. package/esm/shape/link/link.d.ts +2 -1
  48. package/esm/shape/link/link.js +5 -41
  49. package/esm/shape/link/link.js.map +1 -1
  50. package/esm/shape/text/advance.js +2 -4
  51. package/esm/shape/text/advance.js.map +1 -1
  52. package/esm/shape/utils.d.ts +4 -0
  53. package/esm/shape/utils.js.map +1 -1
  54. package/esm/shape/vector/vector.d.ts +1 -0
  55. package/esm/shape/vector/vector.js +12 -8
  56. package/esm/shape/vector/vector.js.map +1 -1
  57. package/esm/transform/sort.js +13 -3
  58. package/esm/transform/sort.js.map +1 -1
  59. package/esm/utils/size.d.ts +0 -10
  60. package/esm/utils/size.js +0 -23
  61. package/esm/utils/size.js.map +1 -1
  62. package/lib/api/chart.d.ts +7 -5
  63. package/lib/api/chart.js +38 -24
  64. package/lib/api/chart.js.map +1 -1
  65. package/lib/api/composition/base.d.ts +1 -0
  66. package/lib/api/composition/base.js +2 -2
  67. package/lib/api/composition/base.js.map +1 -1
  68. package/lib/component/axis.d.ts +5 -2
  69. package/lib/component/axis.js +30 -19
  70. package/lib/component/axis.js.map +1 -1
  71. package/lib/component/constant.d.ts +14 -0
  72. package/lib/component/constant.js +238 -0
  73. package/lib/component/constant.js.map +1 -0
  74. package/lib/component/legendContinuousBlockSize.js +2 -1
  75. package/lib/component/legendContinuousBlockSize.js.map +1 -1
  76. package/lib/component/legendContinuousSize.js +14 -5
  77. package/lib/component/legendContinuousSize.js.map +1 -1
  78. package/lib/component/slider.js +8 -5
  79. package/lib/component/slider.js.map +1 -1
  80. package/lib/interaction/brushFilter.d.ts +1 -1
  81. package/lib/interaction/brushFilter.js +22 -8
  82. package/lib/interaction/brushFilter.js.map +1 -1
  83. package/lib/interaction/brushHighlight.js +1 -1
  84. package/lib/interaction/brushHighlight.js.map +1 -1
  85. package/lib/interaction/brushXFilter.d.ts +1 -1
  86. package/lib/interaction/brushYFilter.d.ts +1 -1
  87. package/lib/interaction/legendFilter.js +6 -3
  88. package/lib/interaction/legendFilter.js.map +1 -1
  89. package/lib/interaction/sliderFilter.js +16 -7
  90. package/lib/interaction/sliderFilter.js.map +1 -1
  91. package/lib/interaction/tooltip.js +37 -16
  92. package/lib/interaction/tooltip.js.map +1 -1
  93. package/lib/runtime/component.js +2 -92
  94. package/lib/runtime/component.js.map +1 -1
  95. package/lib/runtime/plot.js +4 -2
  96. package/lib/runtime/plot.js.map +1 -1
  97. package/lib/runtime/render.js +3 -1
  98. package/lib/runtime/render.js.map +1 -1
  99. package/lib/runtime/transform.js +5 -7
  100. package/lib/runtime/transform.js.map +1 -1
  101. package/lib/shape/label/label.js +3 -2
  102. package/lib/shape/label/label.js.map +1 -1
  103. package/lib/shape/lineXY/line.d.ts +22 -1
  104. package/lib/shape/lineXY/line.js +12 -1
  105. package/lib/shape/lineXY/line.js.map +1 -1
  106. package/lib/shape/link/link.d.ts +2 -1
  107. package/lib/shape/link/link.js +5 -41
  108. package/lib/shape/link/link.js.map +1 -1
  109. package/lib/shape/text/advance.js +2 -4
  110. package/lib/shape/text/advance.js.map +1 -1
  111. package/lib/shape/utils.d.ts +4 -0
  112. package/lib/shape/utils.js.map +1 -1
  113. package/lib/shape/vector/vector.d.ts +1 -0
  114. package/lib/shape/vector/vector.js +12 -8
  115. package/lib/shape/vector/vector.js.map +1 -1
  116. package/lib/transform/sort.js +13 -3
  117. package/lib/transform/sort.js.map +1 -1
  118. package/lib/utils/size.d.ts +0 -10
  119. package/lib/utils/size.js +1 -25
  120. package/lib/utils/size.js.map +1 -1
  121. package/package.json +2 -2
  122. package/src/api/chart.ts +49 -42
  123. package/src/api/composition/base.ts +4 -2
  124. package/src/component/axis.ts +55 -23
  125. package/src/component/constant.ts +237 -0
  126. package/src/component/legendContinuousBlockSize.ts +2 -3
  127. package/src/component/legendContinuousSize.ts +21 -12
  128. package/src/component/slider.ts +10 -5
  129. package/src/interaction/brushFilter.ts +25 -8
  130. package/src/interaction/brushHighlight.ts +1 -1
  131. package/src/interaction/legendFilter.ts +6 -3
  132. package/src/interaction/sliderFilter.ts +21 -7
  133. package/src/interaction/tooltip.ts +64 -28
  134. package/src/runtime/component.ts +2 -98
  135. package/src/runtime/plot.ts +4 -1
  136. package/src/runtime/render.ts +3 -1
  137. package/src/runtime/transform.ts +5 -7
  138. package/src/shape/label/label.ts +13 -2
  139. package/src/shape/lineXY/line.ts +45 -2
  140. package/src/shape/link/link.ts +6 -38
  141. package/src/shape/text/advance.ts +11 -2
  142. package/src/shape/utils.ts +4 -0
  143. package/src/shape/vector/vector.ts +12 -9
  144. package/src/transform/sort.ts +12 -3
  145. package/src/utils/size.ts +0 -31
  146. 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 LegendContinuous(
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 LegendContinuous(
10
- Object.assign(
11
- {},
12
- {
13
- type: 'size',
14
- tick: false,
15
- labelFilter: (datum, index, data) =>
16
- index === 0 || index === data.length - 1,
17
- },
18
- options,
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 = {
@@ -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 } = options;
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: orientation === 'horizontal' ? width : height,
38
+ trackLength: isHorizontal ? width : height,
34
39
  orientation,
35
40
  formatter: (v) => {
36
41
  const f = formatter || defaultFormatter;
37
- // @todo Pass index to distinguish the left and the right value.
38
- const tick = invert(scale, v, true);
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: domainOf(scaleX, [p0[0], p1[0]]) },
115
- y: { domain: domainOf(scaleY, [p0[1], p1[1]]) },
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);
@@ -211,7 +211,7 @@ export function brush(
211
211
  end = brushMousePosition(root, event);
212
212
  const [fx, fy, fx1, fy1] = updateMask(start, end);
213
213
  resizing = false;
214
- brushcreated(fx, fy, fx1, fy1);
214
+ brushcreated(fx, fy, fx1, fy1, event);
215
215
  };
216
216
 
217
217
  // Hide mask.
@@ -169,11 +169,14 @@ export function LegendFilter() {
169
169
  };
170
170
 
171
171
  if (!legends.length) {
172
- emitter.on('legend:filter', (options) => {
172
+ const onFilter = (options) => {
173
173
  const { values, channel } = options;
174
174
  filter(channel, values);
175
- });
176
- return () => {};
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 d0 = invert(scale, x, true);
42
- const d1 = invert(scale, x1, false);
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(values, scale0);
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.