@antv/g2 5.4.0 → 5.4.2
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 +10 -10
- package/dist/g2.min.js +10 -10
- package/esm/component/axis.d.ts +1 -0
- package/esm/component/axis.js.map +1 -1
- package/esm/component/constant.d.ts +1 -0
- package/esm/component/constant.js +8 -0
- package/esm/component/constant.js.map +1 -1
- package/esm/component/slider.js +3 -1
- package/esm/component/slider.js.map +1 -1
- package/esm/composition/view.js +4 -4
- package/esm/composition/view.js.map +1 -1
- package/esm/index.d.ts +4 -0
- package/esm/interaction/adaptiveFilter.d.ts +147 -0
- package/esm/interaction/adaptiveFilter.js +305 -0
- package/esm/interaction/adaptiveFilter.js.map +1 -0
- package/esm/interaction/brushHighlight.d.ts +5 -0
- package/esm/interaction/brushHighlight.js +4 -0
- package/esm/interaction/brushHighlight.js.map +1 -1
- package/esm/interaction/index.d.ts +1 -0
- package/esm/interaction/index.js +1 -0
- package/esm/interaction/index.js.map +1 -1
- package/esm/interaction/legendFilter.js +11 -1
- package/esm/interaction/legendFilter.js.map +1 -1
- package/esm/interaction/sliderFilter.d.ts +2 -1
- package/esm/interaction/sliderFilter.js +400 -42
- package/esm/interaction/sliderFilter.js.map +1 -1
- package/esm/interaction/sliderWheel.d.ts +16 -0
- package/esm/interaction/sliderWheel.js +163 -0
- package/esm/interaction/sliderWheel.js.map +1 -0
- package/esm/interaction/tooltip.d.ts +2 -2
- package/esm/interaction/tooltip.js +32 -8
- package/esm/interaction/tooltip.js.map +1 -1
- package/esm/interaction/utils.d.ts +79 -0
- package/esm/interaction/utils.js +221 -0
- package/esm/interaction/utils.js.map +1 -1
- package/esm/lib/builtinlib.d.ts +1 -1
- package/esm/lib/core.d.ts +3 -1
- package/esm/lib/core.js +4 -2
- package/esm/lib/core.js.map +1 -1
- package/esm/lib/std.d.ts +2 -0
- package/esm/mark/beeswarm.d.ts +7 -0
- package/esm/mark/beeswarm.js +98 -0
- package/esm/mark/beeswarm.js.map +1 -0
- package/esm/mark/index.d.ts +2 -0
- package/esm/mark/index.js +1 -0
- package/esm/mark/index.js.map +1 -1
- package/esm/mark/sankey.js +3 -1
- package/esm/mark/sankey.js.map +1 -1
- package/esm/runtime/layout.js +35 -4
- package/esm/runtime/layout.js.map +1 -1
- package/esm/runtime/mark.js +3 -2
- package/esm/runtime/mark.js.map +1 -1
- package/esm/runtime/render.js +1 -0
- package/esm/runtime/render.js.map +1 -1
- package/esm/shape/axis-breaks/axis-breaks.d.ts +3 -1
- package/esm/shape/axis-breaks/axis-breaks.js +52 -33
- package/esm/shape/axis-breaks/axis-breaks.js.map +1 -1
- package/esm/spec/interaction.d.ts +7 -0
- package/esm/utils/helper.js +17 -1
- package/esm/utils/helper.js.map +1 -1
- package/lib/component/axis.d.ts +1 -0
- package/lib/component/axis.js.map +1 -1
- package/lib/component/constant.d.ts +1 -0
- package/lib/component/constant.js +9 -1
- package/lib/component/constant.js.map +1 -1
- package/lib/component/slider.js +3 -1
- package/lib/component/slider.js.map +1 -1
- package/lib/composition/view.js +4 -4
- package/lib/composition/view.js.map +1 -1
- package/lib/index.d.ts +4 -0
- package/lib/interaction/adaptiveFilter.d.ts +147 -0
- package/lib/interaction/adaptiveFilter.js +315 -0
- package/lib/interaction/adaptiveFilter.js.map +1 -0
- package/lib/interaction/brushHighlight.d.ts +5 -0
- package/lib/interaction/brushHighlight.js +4 -0
- package/lib/interaction/brushHighlight.js.map +1 -1
- package/lib/interaction/index.d.ts +1 -0
- package/lib/interaction/index.js +3 -1
- package/lib/interaction/index.js.map +1 -1
- package/lib/interaction/legendFilter.js +11 -1
- package/lib/interaction/legendFilter.js.map +1 -1
- package/lib/interaction/sliderFilter.d.ts +2 -1
- package/lib/interaction/sliderFilter.js +399 -41
- package/lib/interaction/sliderFilter.js.map +1 -1
- package/lib/interaction/sliderWheel.d.ts +16 -0
- package/lib/interaction/sliderWheel.js +167 -0
- package/lib/interaction/sliderWheel.js.map +1 -0
- package/lib/interaction/tooltip.d.ts +2 -2
- package/lib/interaction/tooltip.js +32 -8
- package/lib/interaction/tooltip.js.map +1 -1
- package/lib/interaction/utils.d.ts +79 -0
- package/lib/interaction/utils.js +228 -1
- package/lib/interaction/utils.js.map +1 -1
- package/lib/lib/builtinlib.d.ts +1 -1
- package/lib/lib/core.d.ts +3 -1
- package/lib/lib/core.js +2 -0
- package/lib/lib/core.js.map +1 -1
- package/lib/lib/std.d.ts +2 -0
- package/lib/mark/beeswarm.d.ts +7 -0
- package/lib/mark/beeswarm.js +102 -0
- package/lib/mark/beeswarm.js.map +1 -0
- package/lib/mark/index.d.ts +2 -0
- package/lib/mark/index.js +3 -1
- package/lib/mark/index.js.map +1 -1
- package/lib/mark/sankey.js +3 -1
- package/lib/mark/sankey.js.map +1 -1
- package/lib/runtime/layout.js +41 -10
- package/lib/runtime/layout.js.map +1 -1
- package/lib/runtime/mark.js +3 -2
- package/lib/runtime/mark.js.map +1 -1
- package/lib/runtime/render.js +1 -0
- package/lib/runtime/render.js.map +1 -1
- package/lib/shape/axis-breaks/axis-breaks.d.ts +3 -1
- package/lib/shape/axis-breaks/axis-breaks.js +51 -32
- package/lib/shape/axis-breaks/axis-breaks.js.map +1 -1
- package/lib/spec/interaction.d.ts +7 -0
- package/lib/utils/helper.js +17 -1
- package/lib/utils/helper.js.map +1 -1
- package/package.json +30 -9
- package/src/component/axis.ts +5 -0
- package/src/component/constant.ts +9 -0
- package/src/component/slider.ts +6 -1
- package/src/composition/view.ts +4 -1
- package/src/interaction/adaptiveFilter.ts +517 -0
- package/src/interaction/brushHighlight.ts +5 -0
- package/src/interaction/index.ts +1 -0
- package/src/interaction/legendFilter.ts +12 -0
- package/src/interaction/sliderFilter.ts +762 -72
- package/src/interaction/sliderWheel.ts +224 -0
- package/src/interaction/tooltip.ts +33 -8
- package/src/interaction/utils.ts +284 -0
- package/src/lib/core.ts +4 -0
- package/src/mark/beeswarm.ts +150 -0
- package/src/mark/index.ts +2 -0
- package/src/mark/sankey.ts +3 -0
- package/src/runtime/layout.ts +46 -3
- package/src/runtime/mark.ts +2 -1
- package/src/runtime/render.ts +1 -0
- package/src/shape/axis-breaks/axis-breaks.ts +72 -40
- package/src/spec/interaction.ts +7 -0
- package/src/utils/helper.ts +19 -1
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import {
|
|
2
|
+
forceSimulation,
|
|
3
|
+
forceX,
|
|
4
|
+
forceY,
|
|
5
|
+
forceCollide,
|
|
6
|
+
} from '@antv/vendor/d3-force';
|
|
7
|
+
import { MarkComponent as MC, Vector2 } from '../runtime';
|
|
8
|
+
import { PointMark } from '../spec';
|
|
9
|
+
import {
|
|
10
|
+
PointBowtie,
|
|
11
|
+
PointCross,
|
|
12
|
+
PointDiamond,
|
|
13
|
+
PointHexagon,
|
|
14
|
+
PointHollowBowtie,
|
|
15
|
+
PointHollowDiamond,
|
|
16
|
+
PointHollowHexagon,
|
|
17
|
+
PointHollow,
|
|
18
|
+
PointHollowSquare,
|
|
19
|
+
PointHollowTriangle,
|
|
20
|
+
PointHollowTriangleDown,
|
|
21
|
+
PointHyphen,
|
|
22
|
+
PointLine,
|
|
23
|
+
PointTriangleDown,
|
|
24
|
+
PointPlus,
|
|
25
|
+
PointSquare,
|
|
26
|
+
PointShape,
|
|
27
|
+
PointTick,
|
|
28
|
+
PointTriangle,
|
|
29
|
+
PointCircle,
|
|
30
|
+
PointHollowCircle,
|
|
31
|
+
} from '../shape';
|
|
32
|
+
import { MaybeZeroX, MaybeZeroY, MaybeSize } from '../transform';
|
|
33
|
+
import {
|
|
34
|
+
baseGeometryChannels,
|
|
35
|
+
basePostInference,
|
|
36
|
+
basePreInference,
|
|
37
|
+
createBandOffset,
|
|
38
|
+
tooltip2d,
|
|
39
|
+
} from './utils';
|
|
40
|
+
|
|
41
|
+
const shape = {
|
|
42
|
+
hollow: PointHollow,
|
|
43
|
+
hollowDiamond: PointHollowDiamond,
|
|
44
|
+
hollowHexagon: PointHollowHexagon,
|
|
45
|
+
hollowSquare: PointHollowSquare,
|
|
46
|
+
hollowTriangleDown: PointHollowTriangleDown,
|
|
47
|
+
hollowTriangle: PointHollowTriangle,
|
|
48
|
+
hollowBowtie: PointHollowBowtie,
|
|
49
|
+
hollowCircle: PointHollowCircle,
|
|
50
|
+
point: PointShape,
|
|
51
|
+
plus: PointPlus,
|
|
52
|
+
diamond: PointDiamond,
|
|
53
|
+
square: PointSquare,
|
|
54
|
+
triangle: PointTriangle,
|
|
55
|
+
hexagon: PointHexagon,
|
|
56
|
+
cross: PointCross,
|
|
57
|
+
bowtie: PointBowtie,
|
|
58
|
+
hyphen: PointHyphen,
|
|
59
|
+
line: PointLine,
|
|
60
|
+
tick: PointTick,
|
|
61
|
+
triangleDown: PointTriangleDown,
|
|
62
|
+
circle: PointCircle,
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
export type BeeswarmOptions = Omit<PointMark, 'type'>;
|
|
66
|
+
|
|
67
|
+
const DEFAULT_RADIUS = 4;
|
|
68
|
+
const ITERATIONS = 200;
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* 蜂群图 (Beeswarm)
|
|
72
|
+
*/
|
|
73
|
+
export const Beeswarm: MC<BeeswarmOptions> = (options) => {
|
|
74
|
+
return (index, scale, value, coordinate) => {
|
|
75
|
+
const { x: X, y: Y, size: S } = value;
|
|
76
|
+
|
|
77
|
+
if (!X.length || !Y.length) return [index, Y.map(() => [[]])];
|
|
78
|
+
const [width, height] = coordinate.getSize();
|
|
79
|
+
const offset = createBandOffset(scale, value, options);
|
|
80
|
+
|
|
81
|
+
const nodes = Array.from(index, (i) => {
|
|
82
|
+
const x0 = +X[i] * width;
|
|
83
|
+
const y0 = +Y[i] * height;
|
|
84
|
+
const r = +S[i] || DEFAULT_RADIUS;
|
|
85
|
+
return { i, x: x0, y: y0, r };
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
// 2. forceSimulation
|
|
89
|
+
const sim = forceSimulation(nodes)
|
|
90
|
+
.stop()
|
|
91
|
+
.force(
|
|
92
|
+
'collide',
|
|
93
|
+
forceCollide<any>()
|
|
94
|
+
.radius((d) => d.r + 1)
|
|
95
|
+
.strength(1),
|
|
96
|
+
);
|
|
97
|
+
|
|
98
|
+
// 主轴吸附
|
|
99
|
+
sim.force('x', forceX<any>((d) => d.x).strength(0.5));
|
|
100
|
+
sim.force('y', forceY<any>((d) => d.y).strength(5));
|
|
101
|
+
|
|
102
|
+
for (let i = 0; i < ITERATIONS; i++) sim.tick();
|
|
103
|
+
sim.stop();
|
|
104
|
+
|
|
105
|
+
const xy = (i: number): Vector2 => {
|
|
106
|
+
const n = nodes.find((d) => d.i === i)!;
|
|
107
|
+
return [n.x / width, n.y / height];
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
const P = S
|
|
111
|
+
? Array.from(index, (i) => {
|
|
112
|
+
const [cx, cy] = xy(i);
|
|
113
|
+
const r = +S[i];
|
|
114
|
+
const a = r / width;
|
|
115
|
+
const b = r / height;
|
|
116
|
+
const p1: Vector2 = [cx - a, cy - b];
|
|
117
|
+
const p2: Vector2 = [cx + a, cy + b];
|
|
118
|
+
return [
|
|
119
|
+
coordinate.map(offset(p1, i)),
|
|
120
|
+
coordinate.map(offset(p2, i)),
|
|
121
|
+
] as Vector2[];
|
|
122
|
+
})
|
|
123
|
+
: Array.from(
|
|
124
|
+
index,
|
|
125
|
+
(i) => [coordinate.map(offset(xy(i), i))] as Vector2[],
|
|
126
|
+
);
|
|
127
|
+
|
|
128
|
+
return [index, P];
|
|
129
|
+
};
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
Beeswarm.props = {
|
|
133
|
+
defaultShape: 'point',
|
|
134
|
+
defaultLabelShape: 'label',
|
|
135
|
+
composite: false,
|
|
136
|
+
shape,
|
|
137
|
+
channels: [
|
|
138
|
+
...baseGeometryChannels({ shapes: Object.keys(shape) }),
|
|
139
|
+
{ name: 'x', required: true },
|
|
140
|
+
{ name: 'y', required: true },
|
|
141
|
+
{ name: 'series', scale: 'band' },
|
|
142
|
+
{ name: 'size', quantitative: 'sqrt' },
|
|
143
|
+
],
|
|
144
|
+
preInference: [
|
|
145
|
+
...basePreInference(),
|
|
146
|
+
{ type: MaybeZeroX },
|
|
147
|
+
{ type: MaybeZeroY },
|
|
148
|
+
],
|
|
149
|
+
postInference: [...basePostInference(), { type: MaybeSize }, ...tooltip2d()],
|
|
150
|
+
};
|
package/src/mark/index.ts
CHANGED
|
@@ -30,6 +30,7 @@ export { Gauge } from './gauge';
|
|
|
30
30
|
export { Density } from './density';
|
|
31
31
|
export { Heatmap } from './heatmap';
|
|
32
32
|
export { Liquid } from './liquid';
|
|
33
|
+
export { Beeswarm } from './beeswarm';
|
|
33
34
|
|
|
34
35
|
export type { IntervalOptions } from './interval';
|
|
35
36
|
export type { RectOptions } from './rect';
|
|
@@ -61,3 +62,4 @@ export type { GaugeOptions } from './gauge';
|
|
|
61
62
|
export type { DensityOptions } from './density';
|
|
62
63
|
export type { HeatmapOptions } from './heatmap';
|
|
63
64
|
export type { LiquidOptions } from './liquid';
|
|
65
|
+
export type { BeeswarmOptions } from './beeswarm';
|
package/src/mark/sankey.ts
CHANGED
|
@@ -70,6 +70,7 @@ export const Sankey: CC<SankeyOptions> = (options) => {
|
|
|
70
70
|
tooltip = {},
|
|
71
71
|
interaction,
|
|
72
72
|
state = {},
|
|
73
|
+
viewStyle = {},
|
|
73
74
|
} = options;
|
|
74
75
|
|
|
75
76
|
// Initialize data, generating nodes by link if is not specified.
|
|
@@ -84,6 +85,7 @@ export const Sankey: CC<SankeyOptions> = (options) => {
|
|
|
84
85
|
encode: {},
|
|
85
86
|
scale,
|
|
86
87
|
style: subObject(style, 'node'),
|
|
88
|
+
viewStyle,
|
|
87
89
|
labels: [],
|
|
88
90
|
tooltip: false,
|
|
89
91
|
animate: false,
|
|
@@ -160,6 +162,7 @@ export const Sankey: CC<SankeyOptions> = (options) => {
|
|
|
160
162
|
encode: { ...nodeEncode, color },
|
|
161
163
|
scale,
|
|
162
164
|
style: subObject(style, 'node'),
|
|
165
|
+
viewStyle,
|
|
163
166
|
labels: [
|
|
164
167
|
{
|
|
165
168
|
...DEFAULT_LABEL_OPTIONS,
|
package/src/runtime/layout.ts
CHANGED
|
@@ -7,7 +7,8 @@ import {
|
|
|
7
7
|
min,
|
|
8
8
|
sum,
|
|
9
9
|
} from '@antv/vendor/d3-array';
|
|
10
|
-
import {
|
|
10
|
+
import { measureTextWidth } from '@antv/component';
|
|
11
|
+
import { deepMix, head, last, get } from '@antv/util';
|
|
11
12
|
import { isParallel, isPolar, isRadar, radiusOf } from '../utils/coordinate';
|
|
12
13
|
import { capitalizeFirst, defined } from '../utils/helper';
|
|
13
14
|
import { divide } from '../utils/array';
|
|
@@ -35,6 +36,8 @@ import {
|
|
|
35
36
|
isRadial as isRadarOptions,
|
|
36
37
|
} from './coordinate';
|
|
37
38
|
|
|
39
|
+
const DEFAULT_MARGIN = 16;
|
|
40
|
+
|
|
38
41
|
export function processAxisZ(components: G2GuideComponentOptions[]) {
|
|
39
42
|
const axisX = components.find(({ type }) => type === 'axisX');
|
|
40
43
|
const axisY = components.find(({ type }) => type === 'axisY');
|
|
@@ -104,6 +107,16 @@ export function computeLayout(
|
|
|
104
107
|
paddingTop = padding,
|
|
105
108
|
} = computeInset(components, options, theme, library);
|
|
106
109
|
|
|
110
|
+
const isDefaultLayoutLeft =
|
|
111
|
+
marginLeft === DEFAULT_MARGIN && paddingLeft === 'auto';
|
|
112
|
+
const isDefaultLayoutRight =
|
|
113
|
+
marginRight === DEFAULT_MARGIN && paddingRight === 'auto';
|
|
114
|
+
const isTranspose = get(options, 'coordinates', []).some(
|
|
115
|
+
(t) => t.type === 'transpose',
|
|
116
|
+
);
|
|
117
|
+
const axisX = components.find(({ type }) => type === 'axisX');
|
|
118
|
+
const { size, labelTransform } = axisX || {};
|
|
119
|
+
|
|
107
120
|
const MIN_CONTENT_RATIO = 1 / 4;
|
|
108
121
|
|
|
109
122
|
const maybeClamp = (viewWidth, paddingLeft, paddingRight, pl0, pr0) => {
|
|
@@ -140,8 +153,8 @@ export function computeLayout(
|
|
|
140
153
|
);
|
|
141
154
|
const { paddingLeft: pl0, paddingRight: pr0 } = horizontalPadding;
|
|
142
155
|
const viewWidth = width - marginLeft - marginRight;
|
|
143
|
-
|
|
144
|
-
|
|
156
|
+
let [pl, pr] = maybeClamp(viewWidth, paddingLeft, paddingRight, pl0, pr0);
|
|
157
|
+
let iw = viewWidth - pl - pr;
|
|
145
158
|
|
|
146
159
|
// Compute paddingBottom and paddingTop based on innerWidth.
|
|
147
160
|
const verticalPadding = computePadding(
|
|
@@ -158,6 +171,36 @@ export function computeLayout(
|
|
|
158
171
|
const [pb, pt] = maybeClamp(viewHeight, paddingBottom, paddingTop, pb0, pt0);
|
|
159
172
|
const ih = viewHeight - pb - pt;
|
|
160
173
|
|
|
174
|
+
// Adjust paddingLeft and paddingRight for axisX when they are 'auto' and not specified by user.
|
|
175
|
+
if (size && !isTranspose && !labelTransform) {
|
|
176
|
+
const { fontSize = 12, fontFamily = 'sans-serif', scales = [] } = axisX;
|
|
177
|
+
const domain = scales?.[0]?.domain ?? [];
|
|
178
|
+
if (!domain.length) return;
|
|
179
|
+
|
|
180
|
+
const adjustSide = (
|
|
181
|
+
side: 'left' | 'right',
|
|
182
|
+
labelText: string,
|
|
183
|
+
margin: number,
|
|
184
|
+
padding: number,
|
|
185
|
+
) => {
|
|
186
|
+
const labelWidth = measureTextWidth(labelText, { fontSize, fontFamily });
|
|
187
|
+
const diff = labelWidth / 2 - margin - padding;
|
|
188
|
+
if (diff > 0) {
|
|
189
|
+
iw -= diff;
|
|
190
|
+
if (side === 'left') pl += labelWidth / 2 - margin;
|
|
191
|
+
else pr += labelWidth / 2 - margin;
|
|
192
|
+
}
|
|
193
|
+
};
|
|
194
|
+
|
|
195
|
+
if (isDefaultLayoutLeft) {
|
|
196
|
+
adjustSide('left', head(domain), marginLeft, pl);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
if (isDefaultLayoutRight) {
|
|
200
|
+
adjustSide('right', last(domain), marginRight, pr);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
161
204
|
return {
|
|
162
205
|
width,
|
|
163
206
|
height,
|
package/src/runtime/mark.ts
CHANGED
|
@@ -39,7 +39,7 @@ export async function initializeMark(
|
|
|
39
39
|
context,
|
|
40
40
|
);
|
|
41
41
|
|
|
42
|
-
const { encode, scale, data, tooltip } = transformedMark;
|
|
42
|
+
const { encode, scale, data, tooltip, key: markerKey } = transformedMark;
|
|
43
43
|
|
|
44
44
|
// Skip mark with non-tabular data. Do not skip empty
|
|
45
45
|
// data, they are useful for facet to display axes.
|
|
@@ -107,6 +107,7 @@ export async function initializeMark(
|
|
|
107
107
|
scaleKey: independent || isConstant ? Symbol('independent') : key,
|
|
108
108
|
scale: {
|
|
109
109
|
type,
|
|
110
|
+
markerKey,
|
|
110
111
|
range: finalRange,
|
|
111
112
|
...scaleOptions,
|
|
112
113
|
quantitative,
|
package/src/runtime/render.ts
CHANGED
|
@@ -147,6 +147,7 @@ export function renderToMountedElement<T extends G2ViewTree = G2ViewTree>(
|
|
|
147
147
|
const selection = select(group);
|
|
148
148
|
context.group = group;
|
|
149
149
|
context.emitter = emitter;
|
|
150
|
+
context.externals = {};
|
|
150
151
|
context.canvas =
|
|
151
152
|
context.canvas || (group?.ownerDocument?.defaultView as GCanvas);
|
|
152
153
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Path } from '@antv/g';
|
|
2
|
-
import { get,
|
|
2
|
+
import { get, deepMix, set } from '@antv/util';
|
|
3
3
|
import type { PathStyleProps } from '@antv/g';
|
|
4
4
|
import {
|
|
5
5
|
BREAK_GROUP_CLASS_NAME,
|
|
@@ -19,6 +19,8 @@ export type BreakOptions = {
|
|
|
19
19
|
vertices?: number;
|
|
20
20
|
/** Offset of each vertex, default is 3. */
|
|
21
21
|
verticeOffset?: number;
|
|
22
|
+
/** Compression type of the break, default is 'middle'. */
|
|
23
|
+
compress?: 'start' | 'end' | 'middle';
|
|
22
24
|
/** Custom styles of the break. */
|
|
23
25
|
[key: string]: any;
|
|
24
26
|
};
|
|
@@ -73,25 +75,67 @@ const createPathPoints = (
|
|
|
73
75
|
return [pathPoints, clipPoints] as const;
|
|
74
76
|
};
|
|
75
77
|
|
|
76
|
-
const
|
|
77
|
-
const scale = get(view, 'scale.y');
|
|
78
|
-
const scaleOptions = get(scale, 'options', {});
|
|
79
|
-
const { breaks } = scaleOptions;
|
|
80
|
-
const filterBreaks = breaks.filter(
|
|
81
|
-
(b) => b.start !== breakValues[0] && b.end !== breakValues[1],
|
|
82
|
-
);
|
|
83
|
-
scale.update({
|
|
84
|
-
...scaleOptions,
|
|
85
|
-
breaks: filterBreaks,
|
|
86
|
-
});
|
|
87
|
-
};
|
|
88
|
-
|
|
89
|
-
export const AxisBreaks = (options, params) => {
|
|
78
|
+
export const AxisBreaks = (_, params) => {
|
|
90
79
|
const { context, selection, view } = params;
|
|
91
80
|
const layer = selection.select(`.${PLOT_CLASS_NAME}`).node();
|
|
92
81
|
const { document } = context.canvas;
|
|
93
|
-
const { externals } = context;
|
|
94
82
|
const { scale } = view;
|
|
83
|
+
|
|
84
|
+
const collapsed = new Map<string, BreakOptions>();
|
|
85
|
+
|
|
86
|
+
const handleCollapseToggle = async (
|
|
87
|
+
key: string,
|
|
88
|
+
start: number,
|
|
89
|
+
end: number,
|
|
90
|
+
) => {
|
|
91
|
+
const { update, setState } = context.externals;
|
|
92
|
+
setState('options', (prev) => {
|
|
93
|
+
const { marks } = prev;
|
|
94
|
+
if (!marks || !marks.length) return prev;
|
|
95
|
+
const newMarks = marks.map((mark) => {
|
|
96
|
+
const breaks = get(mark, 'scale.y.breaks', []);
|
|
97
|
+
|
|
98
|
+
const newBreaks = breaks.filter(
|
|
99
|
+
(b) => b.start !== start && b.end !== end && !b.collapsed,
|
|
100
|
+
);
|
|
101
|
+
// add collapsed: true flag to the corresponding breaks
|
|
102
|
+
breaks.forEach((b) => {
|
|
103
|
+
if (b.start === start && b.end === end) {
|
|
104
|
+
b.collapsed = true;
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
console.log('breaks group:', breaks, newBreaks);
|
|
108
|
+
return deepMix({}, mark, { scale: { y: { breaks: newBreaks } } });
|
|
109
|
+
});
|
|
110
|
+
collapsed.set(key, { start, end });
|
|
111
|
+
return { ...prev, marks: newMarks };
|
|
112
|
+
});
|
|
113
|
+
await update();
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
const resetCollapsed = async () => {
|
|
117
|
+
if (!collapsed.size) return;
|
|
118
|
+
const { update, setState } = context.externals;
|
|
119
|
+
setState('options', (prev) => {
|
|
120
|
+
const { marks } = prev;
|
|
121
|
+
const newMarks = marks.map((mark) => {
|
|
122
|
+
const breaks = get(mark, 'scale.y.breaks', []);
|
|
123
|
+
set(
|
|
124
|
+
mark,
|
|
125
|
+
'scale.y.breaks',
|
|
126
|
+
breaks.map((b) => ({
|
|
127
|
+
...b,
|
|
128
|
+
collapsed: false,
|
|
129
|
+
})),
|
|
130
|
+
);
|
|
131
|
+
return mark;
|
|
132
|
+
});
|
|
133
|
+
collapsed.clear();
|
|
134
|
+
return { ...prev, marks: newMarks };
|
|
135
|
+
});
|
|
136
|
+
await update();
|
|
137
|
+
};
|
|
138
|
+
|
|
95
139
|
return (option: BreakOptions) => {
|
|
96
140
|
const {
|
|
97
141
|
key,
|
|
@@ -160,37 +204,25 @@ export const AxisBreaks = (options, params) => {
|
|
|
160
204
|
try {
|
|
161
205
|
const path1 = new Path({ style: { ...pathAttrs, d: linePath } });
|
|
162
206
|
const path2 = new Path({
|
|
163
|
-
style: { ...pathAttrs, d: clipPath, lineWidth: 0 },
|
|
207
|
+
style: { ...pathAttrs, d: clipPath, lineWidth: 0, cursor: 'pointer' },
|
|
164
208
|
});
|
|
209
|
+
// double click to remove break
|
|
165
210
|
path2.addEventListener('click', async (e) => {
|
|
166
|
-
|
|
211
|
+
e.stopPropagation();
|
|
167
212
|
if (e.detail === 2) {
|
|
168
|
-
|
|
169
|
-
const { update, setState } = context.externals;
|
|
170
|
-
setState('options', (prev) => {
|
|
171
|
-
console.log(prev);
|
|
172
|
-
const { marks } = prev;
|
|
173
|
-
if (!marks || !marks.length) return prev;
|
|
174
|
-
const newMarks = marks.map((mark) => {
|
|
175
|
-
const breaks = get(mark, 'scale.y.breaks', []);
|
|
176
|
-
const newBreaks = breaks.filter(
|
|
177
|
-
(b) => b.start !== start && b.end !== end && !b.used,
|
|
178
|
-
);
|
|
179
|
-
// add used: true flag to the corresponding breaks
|
|
180
|
-
breaks.forEach((b) => {
|
|
181
|
-
if (b.start === start && b.end === end) {
|
|
182
|
-
b.used = true;
|
|
183
|
-
}
|
|
184
|
-
});
|
|
185
|
-
return deepMix({}, mark, { scale: { y: { breaks: newBreaks } } });
|
|
186
|
-
});
|
|
187
|
-
return { ...prev, marks: newMarks };
|
|
188
|
-
});
|
|
189
|
-
await update();
|
|
213
|
+
await handleCollapseToggle(key, start, end);
|
|
190
214
|
}
|
|
191
215
|
});
|
|
192
216
|
g.appendChild(path1);
|
|
193
217
|
g.appendChild(path2);
|
|
218
|
+
|
|
219
|
+
// reset collapsed breaks on double click the plot background
|
|
220
|
+
layer.addEventListener('click', async (e) => {
|
|
221
|
+
if (e.detail === 2) {
|
|
222
|
+
await resetCollapsed();
|
|
223
|
+
}
|
|
224
|
+
});
|
|
225
|
+
|
|
194
226
|
layer.appendChild(g);
|
|
195
227
|
} catch (e) {
|
|
196
228
|
console.error('Failed to create break path:', e);
|
package/src/spec/interaction.ts
CHANGED
|
@@ -167,9 +167,16 @@ export type ChartIndexInteraction = {
|
|
|
167
167
|
|
|
168
168
|
export type SliderFilterInteraction = {
|
|
169
169
|
type?: 'sliderFilter';
|
|
170
|
+
initDomain?: Record<string, any>;
|
|
171
|
+
className?: string;
|
|
172
|
+
prefix?: string;
|
|
173
|
+
setValue?: (component: any, values: any) => void;
|
|
174
|
+
hasState?: boolean;
|
|
170
175
|
wait?: number;
|
|
171
176
|
leading?: boolean;
|
|
172
177
|
trailing?: boolean;
|
|
178
|
+
adaptiveMode?: 'filter' | false | null;
|
|
179
|
+
getInitValues?: (slider: any) => any;
|
|
173
180
|
};
|
|
174
181
|
|
|
175
182
|
export type TooltipInteraction = {
|
package/src/utils/helper.ts
CHANGED
|
@@ -61,12 +61,30 @@ export function seriesOf(elemenet: G2Element): string {
|
|
|
61
61
|
return groupNameOf(scale, elemenet.__data__);
|
|
62
62
|
}
|
|
63
63
|
|
|
64
|
+
/**
|
|
65
|
+
* Get series scale by markerKey
|
|
66
|
+
*/
|
|
67
|
+
function getSeriesByMarkerKey(scale: Record<string, Base<any>>, datum) {
|
|
68
|
+
// For path mark, markerKey is in datum.element?.__data__?.markKey.
|
|
69
|
+
const markerKey = datum.markKey ?? datum.element?.__data__?.markKey;
|
|
70
|
+
|
|
71
|
+
const seriesKey = Object.keys(scale).find((channel) => {
|
|
72
|
+
if (channel.startsWith('series')) {
|
|
73
|
+
const options = scale[channel].getOptions();
|
|
74
|
+
return options.name === 'series' && options.markerKey === markerKey;
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
return scale[seriesKey] ?? scale.series;
|
|
78
|
+
}
|
|
79
|
+
|
|
64
80
|
/**
|
|
65
81
|
* Get group name with view's scale and element's datum.
|
|
66
82
|
*/
|
|
67
83
|
export function groupNameOf(scale: Record<string, Base<any>>, datum) {
|
|
68
|
-
const { color: scaleColor,
|
|
84
|
+
const { color: scaleColor, facet = false } = scale;
|
|
69
85
|
const { color, series } = datum;
|
|
86
|
+
const scaleSeries = getSeriesByMarkerKey(scale, datum);
|
|
87
|
+
|
|
70
88
|
const invertAble = (scale) => {
|
|
71
89
|
return (
|
|
72
90
|
scale &&
|