@antv/g2 5.4.6 → 5.4.8
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/README.md +3 -0
- package/README.zh-CN.md +3 -0
- package/dist/g2.lite.min.js +13 -62
- package/dist/g2.min.js +13 -62
- package/esm/component/legendCategory.js +1 -1
- package/esm/component/legendCategory.js.map +1 -1
- package/esm/component/utils.js +4 -2
- package/esm/component/utils.js.map +1 -1
- package/esm/interaction/elementHoverScale.d.ts +2 -3
- package/esm/interaction/elementHoverScale.js +40 -50
- package/esm/interaction/elementHoverScale.js.map +1 -1
- package/esm/interaction/scrollbarFilter.js +4 -1
- package/esm/interaction/scrollbarFilter.js.map +1 -1
- package/esm/interaction/tooltip.js +11 -7
- package/esm/interaction/tooltip.js.map +1 -1
- package/esm/mark/beeswarm.js +1 -1
- package/esm/mark/beeswarm.js.map +1 -1
- package/esm/runtime/component.js +70 -7
- package/esm/runtime/component.js.map +1 -1
- package/esm/shape/interval/funnel.d.ts +1 -1
- package/esm/shape/interval/funnel.js +90 -5
- package/esm/shape/interval/funnel.js.map +1 -1
- package/esm/shape/interval/pyramid.js +23 -1
- package/esm/shape/interval/pyramid.js.map +1 -1
- package/esm/spec/interaction.d.ts +0 -1
- package/esm/transform/filter.js +4 -2
- package/esm/transform/filter.js.map +1 -1
- package/esm/transform/symmetryY.js +2 -1
- package/esm/transform/symmetryY.js.map +1 -1
- package/lib/component/legendCategory.js +1 -1
- package/lib/component/legendCategory.js.map +1 -1
- package/lib/component/utils.js +4 -2
- package/lib/component/utils.js.map +1 -1
- package/lib/interaction/elementHoverScale.d.ts +2 -3
- package/lib/interaction/elementHoverScale.js +40 -50
- package/lib/interaction/elementHoverScale.js.map +1 -1
- package/lib/interaction/scrollbarFilter.js +4 -1
- package/lib/interaction/scrollbarFilter.js.map +1 -1
- package/lib/interaction/tooltip.js +10 -6
- package/lib/interaction/tooltip.js.map +1 -1
- package/lib/mark/beeswarm.js +1 -1
- package/lib/mark/beeswarm.js.map +1 -1
- package/lib/runtime/component.js +70 -7
- package/lib/runtime/component.js.map +1 -1
- package/lib/shape/interval/funnel.d.ts +1 -1
- package/lib/shape/interval/funnel.js +90 -5
- package/lib/shape/interval/funnel.js.map +1 -1
- package/lib/shape/interval/pyramid.js +23 -1
- package/lib/shape/interval/pyramid.js.map +1 -1
- package/lib/spec/interaction.d.ts +0 -1
- package/lib/transform/filter.js +4 -2
- package/lib/transform/filter.js.map +1 -1
- package/lib/transform/symmetryY.js +2 -1
- package/lib/transform/symmetryY.js.map +1 -1
- package/package.json +1 -2
- package/src/component/legendCategory.ts +4 -1
- package/src/component/utils.ts +4 -2
- package/src/interaction/elementHoverScale.ts +38 -47
- package/src/interaction/scrollbarFilter.ts +3 -0
- package/src/interaction/tooltip.ts +15 -7
- package/src/mark/beeswarm.ts +1 -1
- package/src/runtime/component.ts +83 -8
- package/src/shape/interval/funnel.ts +137 -5
- package/src/shape/interval/pyramid.ts +31 -0
- package/src/spec/interaction.ts +0 -1
- package/src/transform/filter.ts +6 -2
- package/src/transform/symmetryY.ts +6 -2
|
@@ -9,7 +9,9 @@ export type FunnelOptions = {
|
|
|
9
9
|
adjustPoints?: (
|
|
10
10
|
points: Vector2[],
|
|
11
11
|
nextPoints: Vector2[],
|
|
12
|
+
previousPoints: Vector2[],
|
|
12
13
|
coordinate: Coordinate,
|
|
14
|
+
reverse: boolean,
|
|
13
15
|
) => Vector2[];
|
|
14
16
|
[key: string]: any;
|
|
15
17
|
};
|
|
@@ -20,38 +22,168 @@ export type FunnelOptions = {
|
|
|
20
22
|
function getFunnelPoints(
|
|
21
23
|
points: Vector2[],
|
|
22
24
|
nextPoints: Vector2[],
|
|
25
|
+
previousPoints: Vector2[],
|
|
23
26
|
coordinate: Coordinate,
|
|
27
|
+
reverse: boolean,
|
|
24
28
|
) {
|
|
25
29
|
const [p0, p1, p2, p3] = points;
|
|
26
|
-
|
|
27
30
|
if (isTranspose(coordinate)) {
|
|
31
|
+
if (reverse) {
|
|
32
|
+
const newP0: Vector2 = [
|
|
33
|
+
previousPoints ? previousPoints[1][0] : p0[0],
|
|
34
|
+
p0[1],
|
|
35
|
+
];
|
|
36
|
+
|
|
37
|
+
const newP3: Vector2 = [
|
|
38
|
+
previousPoints ? previousPoints[2][0] : p3[0],
|
|
39
|
+
p3[1],
|
|
40
|
+
];
|
|
41
|
+
|
|
42
|
+
return [newP0, p1, p2, newP3];
|
|
43
|
+
}
|
|
44
|
+
|
|
28
45
|
const newP1: Vector2 = [nextPoints ? nextPoints[0][0] : p1[0], p1[1]];
|
|
29
46
|
const newP2: Vector2 = [nextPoints ? nextPoints[3][0] : p2[0], p2[1]];
|
|
30
47
|
return [p0, newP1, newP2, p3];
|
|
31
48
|
}
|
|
49
|
+
|
|
50
|
+
if (reverse) {
|
|
51
|
+
const newP0: Vector2 = [
|
|
52
|
+
p0[0],
|
|
53
|
+
previousPoints ? previousPoints[1][1] : p0[1],
|
|
54
|
+
];
|
|
55
|
+
|
|
56
|
+
const newP3: Vector2 = [
|
|
57
|
+
p3[0],
|
|
58
|
+
previousPoints ? previousPoints[2][1] : p3[1],
|
|
59
|
+
];
|
|
60
|
+
|
|
61
|
+
return [newP0, p1, p2, newP3];
|
|
62
|
+
}
|
|
63
|
+
|
|
32
64
|
const newP1: Vector2 = [p1[0], nextPoints ? nextPoints[0][1] : p1[1]];
|
|
33
65
|
const newP2: Vector2 = [p2[0], nextPoints ? nextPoints[3][1] : p2[1]];
|
|
34
66
|
return [p0, newP1, newP2, p3];
|
|
35
67
|
}
|
|
36
68
|
|
|
69
|
+
/**
|
|
70
|
+
* Calculate the offset
|
|
71
|
+
*/
|
|
72
|
+
const getOffset = (
|
|
73
|
+
angle: number,
|
|
74
|
+
radius: number,
|
|
75
|
+
sign: 1 | -1,
|
|
76
|
+
): { x: number; y: number } => {
|
|
77
|
+
const offsetX = Math.cos(angle) * radius;
|
|
78
|
+
const offsetY = Math.sin(angle) * radius;
|
|
79
|
+
return { x: offsetX * sign, y: offsetY };
|
|
80
|
+
};
|
|
81
|
+
/**
|
|
82
|
+
* Calculate the radius of the long side
|
|
83
|
+
*/
|
|
84
|
+
const getRadiusOfLongerBase = (angle: number, radius: number): number => {
|
|
85
|
+
return radius / Math.tan(angle / 2);
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Create a rounded rectangle path with given corner radius.
|
|
90
|
+
*/
|
|
91
|
+
function createRoundedPath(
|
|
92
|
+
points: Vector2[],
|
|
93
|
+
radius: [number, number, number, number],
|
|
94
|
+
): string {
|
|
95
|
+
const [p0, p1, p2, p3] = points;
|
|
96
|
+
const [r0, r1, r2, r3] = radius;
|
|
97
|
+
const isLongBaseOnTop = p1[0] - p0[0] > p2[0] - p3[0];
|
|
98
|
+
|
|
99
|
+
const angle = Math.atan2(Math.abs(p1[1] - p2[1]), Math.abs(p1[0] - p2[0]));
|
|
100
|
+
|
|
101
|
+
// The radius on the long side requires additional calculation
|
|
102
|
+
const rs = isLongBaseOnTop
|
|
103
|
+
? [
|
|
104
|
+
getRadiusOfLongerBase(angle, r0),
|
|
105
|
+
getRadiusOfLongerBase(angle, r1),
|
|
106
|
+
r2,
|
|
107
|
+
r3,
|
|
108
|
+
]
|
|
109
|
+
: [
|
|
110
|
+
r0,
|
|
111
|
+
r1,
|
|
112
|
+
getRadiusOfLongerBase(angle, r2),
|
|
113
|
+
getRadiusOfLongerBase(angle, r3),
|
|
114
|
+
];
|
|
115
|
+
|
|
116
|
+
// Determine the direction of the X-axis offset based on the lengths of the upper and lower sides
|
|
117
|
+
const sign = isLongBaseOnTop ? 1 : -1;
|
|
118
|
+
|
|
119
|
+
const ofs = rs.map((r) => getOffset(angle, r, sign));
|
|
120
|
+
|
|
121
|
+
return [
|
|
122
|
+
`M${p0[0] + rs[0]} ${p0[1]}`,
|
|
123
|
+
`L${p1[0] - rs[1]} ${p1[1]}`,
|
|
124
|
+
`Q${p1[0]} ${p1[1]} ${p1[0] - ofs[1].x} ${p1[1] + ofs[1].y}`,
|
|
125
|
+
`L${p2[0] + ofs[2].x} ${p2[1] - ofs[2].y}`,
|
|
126
|
+
`Q${p2[0]} ${p2[1]} ${p2[0] - rs[2]} ${p2[1]}`,
|
|
127
|
+
`L${p3[0] + rs[3]} ${p3[1]}`,
|
|
128
|
+
`Q${p3[0]} ${p3[1]} ${p3[0] - ofs[3].x} ${p3[1] - ofs[3].y}`,
|
|
129
|
+
`L${p0[0] + ofs[0].x} ${p0[1] + ofs[0].y}`,
|
|
130
|
+
`Q${p0[0]} ${p0[1]} ${p0[0] + rs[0]} ${p0[1]}`,
|
|
131
|
+
'Z',
|
|
132
|
+
].join(' ');
|
|
133
|
+
}
|
|
134
|
+
|
|
37
135
|
/**
|
|
38
136
|
* Render funnel in different coordinate and using color channel for stroke and fill attribute.
|
|
39
137
|
*/
|
|
40
138
|
export const Funnel: SC<FunnelOptions> = (options, context) => {
|
|
41
|
-
const {
|
|
139
|
+
const {
|
|
140
|
+
adjustPoints = getFunnelPoints,
|
|
141
|
+
radius,
|
|
142
|
+
radiusTopLeft = radius,
|
|
143
|
+
radiusTopRight = radius,
|
|
144
|
+
radiusBottomRight = radius,
|
|
145
|
+
radiusBottomLeft = radius,
|
|
146
|
+
innerRadius = 0,
|
|
147
|
+
innerRadiusTopLeft = innerRadius,
|
|
148
|
+
innerRadiusTopRight = innerRadius,
|
|
149
|
+
innerRadiusBottomRight = innerRadius,
|
|
150
|
+
innerRadiusBottomLeft = innerRadius,
|
|
151
|
+
first = true,
|
|
152
|
+
last = true,
|
|
153
|
+
...style
|
|
154
|
+
} = options;
|
|
42
155
|
const { coordinate, document } = context;
|
|
43
156
|
return (points, value, defaults, point2d) => {
|
|
44
157
|
const { index } = value;
|
|
45
158
|
const { color: defaultColor, ...rest } = defaults;
|
|
46
159
|
const nextPoints = point2d[index + 1];
|
|
47
|
-
const
|
|
160
|
+
const previousPoints = point2d[index - 1];
|
|
161
|
+
const funnelPoints = adjustPoints(
|
|
162
|
+
points,
|
|
163
|
+
nextPoints,
|
|
164
|
+
previousPoints,
|
|
165
|
+
coordinate,
|
|
166
|
+
style.reverse,
|
|
167
|
+
);
|
|
48
168
|
const tpShape = !!isTranspose(coordinate);
|
|
49
169
|
const [p0, p1, p2, p3] = tpShape ? reorder(funnelPoints) : funnelPoints;
|
|
50
170
|
const { color = defaultColor, opacity } = value;
|
|
51
|
-
const
|
|
171
|
+
const standardDirRadius: [number, number, number, number] = [
|
|
172
|
+
first ? radiusTopLeft ?? innerRadiusTopLeft : innerRadiusTopLeft,
|
|
173
|
+
first ? radiusTopRight ?? innerRadiusTopRight : innerRadiusTopRight,
|
|
174
|
+
last
|
|
175
|
+
? radiusBottomRight ?? innerRadiusBottomRight
|
|
176
|
+
: innerRadiusBottomRight,
|
|
177
|
+
last ? radiusBottomLeft ?? innerRadiusBottomLeft : innerRadiusBottomLeft,
|
|
178
|
+
];
|
|
179
|
+
|
|
180
|
+
const path = standardDirRadius.find((r) => r > 0)
|
|
181
|
+
? createRoundedPath([p0, p1, p2, p3], standardDirRadius)
|
|
182
|
+
: line().curve(curveLinearClosed)([p0, p1, p2, p3]);
|
|
183
|
+
|
|
52
184
|
return select(document.createElement('path', {}))
|
|
53
185
|
.call(applyStyle, rest)
|
|
54
|
-
.style('d',
|
|
186
|
+
.style('d', path)
|
|
55
187
|
.style('fill', color)
|
|
56
188
|
.style('fillOpacity', opacity)
|
|
57
189
|
.call(applyStyle, style)
|
|
@@ -11,11 +11,27 @@ export type PyramidOptions = Record<string, any>;
|
|
|
11
11
|
function getPyramidPoints(
|
|
12
12
|
points: Vector2[],
|
|
13
13
|
nextPoints: Vector2[],
|
|
14
|
+
previousPoints: Vector2[],
|
|
14
15
|
coordinate: Coordinate,
|
|
16
|
+
reverse: boolean,
|
|
15
17
|
) {
|
|
16
18
|
const [p0, p1, p2, p3] = points;
|
|
17
19
|
|
|
18
20
|
if (isTranspose(coordinate)) {
|
|
21
|
+
if (reverse) {
|
|
22
|
+
const newP0: Vector2 = [
|
|
23
|
+
previousPoints ? previousPoints[1][0] : (p0[0] + p3[0]) / 2,
|
|
24
|
+
p0[1],
|
|
25
|
+
];
|
|
26
|
+
|
|
27
|
+
const newP3: Vector2 = [
|
|
28
|
+
previousPoints ? previousPoints[2][0] : (p0[0] + p3[0]) / 2,
|
|
29
|
+
p3[1],
|
|
30
|
+
];
|
|
31
|
+
|
|
32
|
+
return [newP0, p1, p2, newP3];
|
|
33
|
+
}
|
|
34
|
+
|
|
19
35
|
const newP1: Vector2 = [
|
|
20
36
|
nextPoints ? nextPoints[0][0] : (p1[0] + p2[0]) / 2,
|
|
21
37
|
p1[1],
|
|
@@ -26,6 +42,21 @@ function getPyramidPoints(
|
|
|
26
42
|
];
|
|
27
43
|
return [p0, newP1, newP2, p3];
|
|
28
44
|
}
|
|
45
|
+
|
|
46
|
+
if (reverse) {
|
|
47
|
+
const newP0: Vector2 = [
|
|
48
|
+
p0[0],
|
|
49
|
+
previousPoints ? previousPoints[1][1] : (p0[1] + p3[1]) / 2,
|
|
50
|
+
];
|
|
51
|
+
|
|
52
|
+
const newP3: Vector2 = [
|
|
53
|
+
p3[0],
|
|
54
|
+
previousPoints ? previousPoints[2][1] : (p0[1] + p3[1]) / 2,
|
|
55
|
+
];
|
|
56
|
+
|
|
57
|
+
return [newP0, p1, p2, newP3];
|
|
58
|
+
}
|
|
59
|
+
|
|
29
60
|
const newP1: Vector2 = [
|
|
30
61
|
p1[0],
|
|
31
62
|
nextPoints ? nextPoints[0][1] : (p1[1] + p2[1]) / 2,
|
package/src/spec/interaction.ts
CHANGED
package/src/transform/filter.ts
CHANGED
|
@@ -65,6 +65,9 @@ function filterWhenNoElements(mark: G2Mark) {
|
|
|
65
65
|
export const Filter: TC<FilterOptions> = (options = {}) => {
|
|
66
66
|
return (I, mark) => {
|
|
67
67
|
const { encode, data } = mark;
|
|
68
|
+
|
|
69
|
+
const hasChannelOptions = Object.keys(options).length > 0;
|
|
70
|
+
|
|
68
71
|
const filters = Object.entries(options)
|
|
69
72
|
.map(([key, v]) => {
|
|
70
73
|
const [V] = columnOf(encode, key);
|
|
@@ -88,9 +91,10 @@ export const Filter: TC<FilterOptions> = (options = {}) => {
|
|
|
88
91
|
const FI = I.filter(totalFilter);
|
|
89
92
|
const newIndex = FI.map((_, i) => i);
|
|
90
93
|
|
|
91
|
-
if (filters.length === 0) {
|
|
94
|
+
if (filters.length === 0 && hasChannelOptions) {
|
|
92
95
|
const targetMark = filterWhenNoElements(mark);
|
|
93
|
-
|
|
96
|
+
// Return empty index array to ensure no elements are rendered
|
|
97
|
+
return [[], targetMark];
|
|
94
98
|
}
|
|
95
99
|
|
|
96
100
|
const newEncodes = Object.entries(encode).map(([key, encode]) => {
|
|
@@ -14,7 +14,7 @@ export type SymmetryYOptions = Omit<SymmetryYTransform, 'type'>;
|
|
|
14
14
|
export const SymmetryY: TC<SymmetryYOptions> = (options = {}) => {
|
|
15
15
|
const { groupBy = 'x' } = options;
|
|
16
16
|
return (I, mark) => {
|
|
17
|
-
const { encode } = mark;
|
|
17
|
+
const { encode, style = {} } = mark;
|
|
18
18
|
const { x, ...rest } = encode;
|
|
19
19
|
|
|
20
20
|
// Extract and create new channels starts with y, such as y, y1.
|
|
@@ -22,7 +22,6 @@ export const SymmetryY: TC<SymmetryYOptions> = (options = {}) => {
|
|
|
22
22
|
.filter(([k]) => k.startsWith('y'))
|
|
23
23
|
.map(([k]) => [k, columnOf(encode, k)[0]] as const);
|
|
24
24
|
const newYn = Yn.map(([k]) => [k, new Array(I.length)] as const);
|
|
25
|
-
|
|
26
25
|
// Group marks into series by specified keys.
|
|
27
26
|
const groups = createGroups(groupBy, I, mark);
|
|
28
27
|
const MY = new Array(groups.length);
|
|
@@ -52,6 +51,11 @@ export const SymmetryY: TC<SymmetryYOptions> = (options = {}) => {
|
|
|
52
51
|
encode: Object.fromEntries(
|
|
53
52
|
newYn.map(([k, v]) => [k, column(v, columnOf(encode, k)[1])]),
|
|
54
53
|
),
|
|
54
|
+
style: {
|
|
55
|
+
first: (_, i) => i === 0,
|
|
56
|
+
last: (_, i) => i === groups.length - 1,
|
|
57
|
+
...style,
|
|
58
|
+
},
|
|
55
59
|
}),
|
|
56
60
|
];
|
|
57
61
|
};
|