@antv/g2 5.0.6 → 5.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (185) hide show
  1. package/dist/g2-lite.min.js +4 -4
  2. package/dist/g2.min.js +4 -4
  3. package/esm/animation/morphing.js +4 -0
  4. package/esm/animation/morphing.js.map +1 -1
  5. package/esm/api/chart.d.ts +4 -7
  6. package/esm/api/chart.js +16 -88
  7. package/esm/api/chart.js.map +1 -1
  8. package/esm/api/utils.d.ts +10 -0
  9. package/esm/api/utils.js +71 -0
  10. package/esm/api/utils.js.map +1 -0
  11. package/esm/component/axis.js +15 -17
  12. package/esm/component/axis.js.map +1 -1
  13. package/esm/component/axisX.js +3 -1
  14. package/esm/component/axisX.js.map +1 -1
  15. package/esm/component/axisY.js +1 -1
  16. package/esm/component/axisY.js.map +1 -1
  17. package/esm/component/constant.js +6 -0
  18. package/esm/component/constant.js.map +1 -1
  19. package/esm/component/legendCategory.js +8 -5
  20. package/esm/component/legendCategory.js.map +1 -1
  21. package/esm/component/legendContinuous.js +91 -33
  22. package/esm/component/legendContinuous.js.map +1 -1
  23. package/esm/component/utils.d.ts +9 -5
  24. package/esm/component/utils.js +14 -14
  25. package/esm/component/utils.js.map +1 -1
  26. package/esm/interaction/brushFilter.js +2 -6
  27. package/esm/interaction/brushFilter.js.map +1 -1
  28. package/esm/interaction/brushHighlight.d.ts +3 -2
  29. package/esm/interaction/brushHighlight.js +197 -26
  30. package/esm/interaction/brushHighlight.js.map +1 -1
  31. package/esm/interaction/brushXHighlight.js +1 -1
  32. package/esm/interaction/brushXHighlight.js.map +1 -1
  33. package/esm/interaction/brushYHighlight.js +1 -1
  34. package/esm/interaction/brushYHighlight.js.map +1 -1
  35. package/esm/interaction/event.d.ts +1 -0
  36. package/esm/interaction/event.js +14 -12
  37. package/esm/interaction/event.js.map +1 -1
  38. package/esm/interaction/tooltip.d.ts +4 -4
  39. package/esm/interaction/tooltip.js +103 -31
  40. package/esm/interaction/tooltip.js.map +1 -1
  41. package/esm/mark/gauge.d.ts +7 -0
  42. package/esm/mark/gauge.js +4 -6
  43. package/esm/mark/gauge.js.map +1 -1
  44. package/esm/runtime/plot.js +9 -6
  45. package/esm/runtime/plot.js.map +1 -1
  46. package/esm/runtime/scale.js +2 -2
  47. package/esm/runtime/scale.js.map +1 -1
  48. package/esm/runtime/transform.js +4 -1
  49. package/esm/runtime/transform.js.map +1 -1
  50. package/esm/runtime/types/component.d.ts +1 -0
  51. package/esm/shape/area/area.js +1 -1
  52. package/esm/shape/area/area.js.map +1 -1
  53. package/esm/shape/area/curve.js +1 -1
  54. package/esm/shape/area/curve.js.map +1 -1
  55. package/esm/shape/connector/connector.js +1 -1
  56. package/esm/shape/line/curve.js +1 -1
  57. package/esm/shape/line/curve.js.map +1 -1
  58. package/esm/shape/text/advance.d.ts +1 -1
  59. package/esm/shape/text/advance.js +1 -1
  60. package/esm/shape/text/advance.js.map +1 -1
  61. package/esm/shape/text/badge.js +1 -1
  62. package/esm/shape/utils.js +1 -1
  63. package/esm/shape/utils.js.map +1 -1
  64. package/esm/spec/interaction.d.ts +3 -1
  65. package/esm/theme/classic.js +3 -0
  66. package/esm/theme/classic.js.map +1 -1
  67. package/esm/theme/classicDark.js +1 -0
  68. package/esm/theme/classicDark.js.map +1 -1
  69. package/esm/transform/filter.js +6 -2
  70. package/esm/transform/filter.js.map +1 -1
  71. package/esm/{shape → utils}/createElement.d.ts +1 -1
  72. package/esm/{shape → utils}/createElement.js.map +1 -1
  73. package/esm/utils/helper.d.ts +3 -0
  74. package/esm/utils/helper.js +3 -0
  75. package/esm/utils/helper.js.map +1 -1
  76. package/lib/animation/morphing.js +4 -0
  77. package/lib/animation/morphing.js.map +1 -1
  78. package/lib/api/chart.d.ts +4 -7
  79. package/lib/api/chart.js +21 -95
  80. package/lib/api/chart.js.map +1 -1
  81. package/lib/api/utils.d.ts +10 -0
  82. package/lib/api/utils.js +80 -0
  83. package/lib/api/utils.js.map +1 -0
  84. package/lib/component/axis.js +15 -17
  85. package/lib/component/axis.js.map +1 -1
  86. package/lib/component/axisX.js +3 -1
  87. package/lib/component/axisX.js.map +1 -1
  88. package/lib/component/axisY.js +1 -1
  89. package/lib/component/axisY.js.map +1 -1
  90. package/lib/component/constant.js +6 -0
  91. package/lib/component/constant.js.map +1 -1
  92. package/lib/component/legendCategory.js +7 -4
  93. package/lib/component/legendCategory.js.map +1 -1
  94. package/lib/component/legendContinuous.js +90 -32
  95. package/lib/component/legendContinuous.js.map +1 -1
  96. package/lib/component/utils.d.ts +9 -5
  97. package/lib/component/utils.js +16 -15
  98. package/lib/component/utils.js.map +1 -1
  99. package/lib/interaction/brushFilter.js +2 -6
  100. package/lib/interaction/brushFilter.js.map +1 -1
  101. package/lib/interaction/brushHighlight.d.ts +3 -2
  102. package/lib/interaction/brushHighlight.js +196 -25
  103. package/lib/interaction/brushHighlight.js.map +1 -1
  104. package/lib/interaction/brushXHighlight.js +1 -1
  105. package/lib/interaction/brushXHighlight.js.map +1 -1
  106. package/lib/interaction/brushYHighlight.js +1 -1
  107. package/lib/interaction/brushYHighlight.js.map +1 -1
  108. package/lib/interaction/event.d.ts +1 -0
  109. package/lib/interaction/event.js +15 -12
  110. package/lib/interaction/event.js.map +1 -1
  111. package/lib/interaction/tooltip.d.ts +4 -4
  112. package/lib/interaction/tooltip.js +102 -30
  113. package/lib/interaction/tooltip.js.map +1 -1
  114. package/lib/mark/gauge.d.ts +7 -0
  115. package/lib/mark/gauge.js +4 -6
  116. package/lib/mark/gauge.js.map +1 -1
  117. package/lib/runtime/plot.js +9 -6
  118. package/lib/runtime/plot.js.map +1 -1
  119. package/lib/runtime/scale.js +2 -2
  120. package/lib/runtime/scale.js.map +1 -1
  121. package/lib/runtime/transform.js +4 -1
  122. package/lib/runtime/transform.js.map +1 -1
  123. package/lib/runtime/types/component.d.ts +1 -0
  124. package/lib/shape/area/area.js +1 -1
  125. package/lib/shape/area/area.js.map +1 -1
  126. package/lib/shape/area/curve.js +1 -1
  127. package/lib/shape/area/curve.js.map +1 -1
  128. package/lib/shape/connector/connector.js +1 -1
  129. package/lib/shape/line/curve.js +1 -1
  130. package/lib/shape/line/curve.js.map +1 -1
  131. package/lib/shape/text/advance.d.ts +1 -1
  132. package/lib/shape/text/advance.js +1 -1
  133. package/lib/shape/text/advance.js.map +1 -1
  134. package/lib/shape/text/badge.js +1 -1
  135. package/lib/shape/utils.js +1 -1
  136. package/lib/shape/utils.js.map +1 -1
  137. package/lib/spec/interaction.d.ts +3 -1
  138. package/lib/theme/classic.js +3 -0
  139. package/lib/theme/classic.js.map +1 -1
  140. package/lib/theme/classicDark.js +1 -0
  141. package/lib/theme/classicDark.js.map +1 -1
  142. package/lib/transform/filter.js +6 -2
  143. package/lib/transform/filter.js.map +1 -1
  144. package/lib/{shape → utils}/createElement.d.ts +1 -1
  145. package/lib/{shape → utils}/createElement.js.map +1 -1
  146. package/lib/utils/helper.d.ts +3 -0
  147. package/lib/utils/helper.js +5 -1
  148. package/lib/utils/helper.js.map +1 -1
  149. package/package.json +3 -2
  150. package/src/animation/morphing.ts +5 -0
  151. package/src/api/chart.ts +23 -111
  152. package/src/api/utils.ts +79 -0
  153. package/src/component/axis.ts +20 -18
  154. package/src/component/axisX.ts +3 -1
  155. package/src/component/axisY.ts +2 -1
  156. package/src/component/constant.ts +6 -0
  157. package/src/component/legendCategory.ts +19 -6
  158. package/src/component/legendContinuous.ts +185 -74
  159. package/src/component/utils.ts +14 -3
  160. package/src/interaction/brushFilter.ts +8 -6
  161. package/src/interaction/brushHighlight.ts +255 -18
  162. package/src/interaction/brushXHighlight.ts +1 -0
  163. package/src/interaction/brushYHighlight.ts +1 -0
  164. package/src/interaction/event.ts +19 -13
  165. package/src/interaction/tooltip.ts +154 -25
  166. package/src/mark/gauge.ts +13 -7
  167. package/src/runtime/plot.ts +7 -5
  168. package/src/runtime/scale.ts +2 -2
  169. package/src/runtime/transform.ts +2 -1
  170. package/src/runtime/types/component.ts +1 -0
  171. package/src/shape/area/area.ts +1 -1
  172. package/src/shape/area/curve.ts +1 -1
  173. package/src/shape/connector/connector.ts +1 -1
  174. package/src/shape/line/curve.ts +1 -1
  175. package/src/shape/text/advance.ts +1 -1
  176. package/src/shape/text/badge.ts +1 -1
  177. package/src/shape/utils.ts +1 -1
  178. package/src/spec/interaction.ts +3 -2
  179. package/src/theme/classic.ts +3 -0
  180. package/src/theme/classicDark.ts +1 -0
  181. package/src/transform/filter.ts +6 -2
  182. package/src/{shape → utils}/createElement.ts +1 -1
  183. package/src/utils/helper.ts +12 -1
  184. /package/esm/{shape → utils}/createElement.js +0 -0
  185. /package/lib/{shape → utils}/createElement.js +0 -0
@@ -198,6 +198,11 @@ export const LEGEND_INFER_STRATEGIES: InferStrategy[] = [
198
198
  ['color', 'constant'],
199
199
  ['size', 'continuous'],
200
200
  ],
201
+ [
202
+ ['size', 'continuous'],
203
+ ['opacity', 'continuous'],
204
+ ],
205
+ [['size', 'continuous']],
201
206
  ],
202
207
  ],
203
208
  [
@@ -232,6 +237,7 @@ export const LEGEND_INFER_STRATEGIES: InferStrategy[] = [
232
237
  ['opacity', 'continuous'],
233
238
  ],
234
239
  [['color', 'continuous']],
240
+ [['opacity', 'continuous']],
235
241
  ],
236
242
  ],
237
243
  ];
@@ -19,7 +19,7 @@ import { useMarker } from '../utils/marker';
19
19
  import {
20
20
  adaptor,
21
21
  domainOf,
22
- G2Layout,
22
+ LegendCategoryLayout,
23
23
  inferComponentLayout,
24
24
  inferComponentShape,
25
25
  scaleOf,
@@ -124,9 +124,15 @@ function inferItemMarker(
124
124
  }
125
125
  if (typeof itemMarker === 'function') return itemMarker;
126
126
  return (d, i) =>
127
- createShape(itemMarker || shapes[i], library, coordinate, theme, {
128
- color: d.color,
129
- });
127
+ createShape(
128
+ itemMarker || `${namespace}.${shapes[i]}`,
129
+ library,
130
+ coordinate,
131
+ theme,
132
+ {
133
+ color: d.color,
134
+ },
135
+ );
130
136
  }
131
137
 
132
138
  function inferItemMarkerOpacity(scales: Scale[]) {
@@ -238,20 +244,27 @@ export const LegendCategory: GCC<LegendCategoryOptions> = (options) => {
238
244
  };
239
245
 
240
246
  const { legend: legendTheme = {} } = theme;
241
- const layoutWrapper = new G2Layout({
247
+
248
+ const categoryStyle = adaptor(
249
+ Object.assign({}, legendTheme, legendStyle, style),
250
+ );
251
+
252
+ const layoutWrapper = new LegendCategoryLayout({
242
253
  style: {
243
254
  x: bbox.x,
244
255
  y: bbox.y,
245
256
  width: bbox.width,
246
257
  height: bbox.height,
247
258
  ...finalLayout,
259
+ // @ts-ignore
260
+ subOptions: categoryStyle,
248
261
  },
249
262
  });
250
263
 
251
264
  layoutWrapper.appendChild(
252
265
  new Category({
253
266
  className: 'legend-category',
254
- style: adaptor(Object.assign({}, legendTheme, legendStyle, style)),
267
+ style: categoryStyle,
255
268
  }),
256
269
  );
257
270
  return layoutWrapper;
@@ -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
- function inferContinuousConfig(
27
- scales: Scale[],
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 colorScale = scaleOf(scales, 'color');
33
- const { domain, range } = colorScale.getOptions();
34
- const [min, max] = [domain[0], domain.slice(-1)[0]];
35
- const { orientation, width, height, length } = inferComponentShape(
36
- value,
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
- const shape = { orientation, width, height };
80
+ function getFormatter(max: number) {
81
+ return (value: number) => ({
82
+ value: value / max,
83
+ label: String(value),
84
+ });
85
+ }
42
86
 
43
- if (colorScale instanceof Threshold) {
44
- const thresholds = (colorScale as any).thresholds as number[];
45
- // for quantize, quantile scale
46
- if (colorScale instanceof Quantize || colorScale instanceof Quantile) {
47
- return {
48
- color: range,
49
- ...shape,
50
- data: [min, ...thresholds, max].map((value, index) => ({
51
- value: value / max,
52
- label: value,
53
- })),
54
- };
55
- }
56
- // for threshhold
57
- const data = [-Infinity, ...thresholds, Infinity].map((value, index) => ({
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
- // for linear, pow, sqrt, log, time, utc scale
72
- const opacityScale = scaleOf(scales, 'opacity');
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: colorScale.getTicks().map((value) => ({ value })),
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 = colorScale.map(value);
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}), ([\d]{1,3}), ([\d]{1,3})[\S\s]*\)/,
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 finalLayout = inferComponentLayout(
109
- position,
110
- value.scales?.[0]?.guide?.layout,
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: adaptor(
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
  };
@@ -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 { width, height, ...restOptions } = options;
89
- (this.children?.[0] as any)?.update(restOptions);
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[] {
@@ -131,9 +131,10 @@ export function BrushFilter({ hideX = true, hideY = true, ...rest }) {
131
131
  );
132
132
 
133
133
  // Emit event.
134
- event.data = event.data || {};
135
- event.data.selection = [domainX, domainY];
136
- emitter.emit('brush:filter', event);
134
+ emitter.emit('brush:filter', {
135
+ ...event,
136
+ data: { selection: [domainX, domainY] },
137
+ });
137
138
 
138
139
  // Rerender and update view.
139
140
  const newOptions = {
@@ -154,9 +155,10 @@ export function BrushFilter({ hideX = true, hideY = true, ...rest }) {
154
155
  const { x: scaleX, y: scaleY } = scale;
155
156
  const domainX = scaleX.getOptions().domain;
156
157
  const domainY = scaleY.getOptions().domain;
157
- event.data = event.data || {};
158
- event.data.selection = [domainX, domainY];
159
- emitter.emit('brush:filter', event);
158
+ emitter.emit('brush:filter', {
159
+ ...event,
160
+ data: { selection: [domainX, domainY] },
161
+ });
160
162
 
161
163
  filtered = false;
162
164
  newView = view;