@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.
- 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 +4 -7
- package/esm/api/chart.js +16 -88
- 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.js +2 -6
- package/esm/interaction/brushFilter.js.map +1 -1
- package/esm/interaction/brushHighlight.d.ts +3 -2
- package/esm/interaction/brushHighlight.js +197 -26
- package/esm/interaction/brushHighlight.js.map +1 -1
- package/esm/interaction/brushXHighlight.js +1 -1
- package/esm/interaction/brushXHighlight.js.map +1 -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/lib/animation/morphing.js +4 -0
- package/lib/animation/morphing.js.map +1 -1
- package/lib/api/chart.d.ts +4 -7
- package/lib/api/chart.js +21 -95
- 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.js +2 -6
- package/lib/interaction/brushFilter.js.map +1 -1
- package/lib/interaction/brushHighlight.d.ts +3 -2
- package/lib/interaction/brushHighlight.js +196 -25
- package/lib/interaction/brushHighlight.js.map +1 -1
- package/lib/interaction/brushXHighlight.js +1 -1
- package/lib/interaction/brushXHighlight.js.map +1 -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/package.json +3 -2
- package/src/animation/morphing.ts +5 -0
- package/src/api/chart.ts +23 -111
- 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 +8 -6
- package/src/interaction/brushHighlight.ts +255 -18
- 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/esm/{shape → utils}/createElement.js +0 -0
- /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
|
-
|
|
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(
|
|
128
|
-
|
|
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
|
-
|
|
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:
|
|
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
|
-
|
|
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[] {
|
|
@@ -131,9 +131,10 @@ export function BrushFilter({ hideX = true, hideY = true, ...rest }) {
|
|
|
131
131
|
);
|
|
132
132
|
|
|
133
133
|
// Emit event.
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
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
|
-
|
|
158
|
-
|
|
159
|
-
|
|
158
|
+
emitter.emit('brush:filter', {
|
|
159
|
+
...event,
|
|
160
|
+
data: { selection: [domainX, domainY] },
|
|
161
|
+
});
|
|
160
162
|
|
|
161
163
|
filtered = false;
|
|
162
164
|
newView = view;
|