@antv/g2 5.4.7 → 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 +2 -0
- package/README.zh-CN.md +2 -0
- package/dist/g2.lite.min.js +14 -53
- package/dist/g2.min.js +14 -53
- package/esm/component/utils.js +4 -2
- package/esm/component/utils.js.map +1 -1
- package/esm/data/cluster.d.ts +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 +25 -2
- 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/lib/component/utils.js +4 -2
- package/lib/component/utils.js.map +1 -1
- package/lib/data/cluster.d.ts +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 +25 -2
- 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/package.json +1 -2
- 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 +41 -2
- package/src/shape/interval/pyramid.ts +31 -0
- package/src/spec/interaction.ts +0 -1
package/src/runtime/component.ts
CHANGED
|
@@ -871,19 +871,94 @@ function computeCategoryLegendSize(
|
|
|
871
871
|
? crossSize0 + (isVertical ? 0 : crossPadding[0] + crossPadding[1])
|
|
872
872
|
: length;
|
|
873
873
|
|
|
874
|
+
// Create scale.
|
|
875
|
+
const scale = createScale(component, library);
|
|
876
|
+
|
|
877
|
+
// If render is provided, use HTML to render.
|
|
878
|
+
const { render } = component;
|
|
879
|
+
if (render && typeof document !== 'undefined') {
|
|
880
|
+
const domain = scale.getOptions().domain;
|
|
881
|
+
const { labelFormatter } = rest;
|
|
882
|
+
const formatLabel = (d: any) => {
|
|
883
|
+
if (!labelFormatter) return `${d}`;
|
|
884
|
+
return typeof labelFormatter === 'string'
|
|
885
|
+
? format(labelFormatter)(d)
|
|
886
|
+
: labelFormatter(d);
|
|
887
|
+
};
|
|
888
|
+
|
|
889
|
+
const items = domain.map((d, i) => ({
|
|
890
|
+
id: d,
|
|
891
|
+
index: i,
|
|
892
|
+
label: formatLabel(d),
|
|
893
|
+
value: d,
|
|
894
|
+
color: scale.map(d),
|
|
895
|
+
}));
|
|
896
|
+
|
|
897
|
+
const html = render(items, rest);
|
|
898
|
+
const container = document.createElement('div');
|
|
899
|
+
const { width, height } = component;
|
|
900
|
+
|
|
901
|
+
const style: Partial<CSSStyleDeclaration> = {
|
|
902
|
+
position: 'absolute',
|
|
903
|
+
visibility: 'hidden',
|
|
904
|
+
top: '-9999px',
|
|
905
|
+
};
|
|
906
|
+
|
|
907
|
+
if (width) style.width = `${width}px`;
|
|
908
|
+
else if (!isVertical) style.width = `${crossSize}px`;
|
|
909
|
+
|
|
910
|
+
if (height) style.height = `${height}px`;
|
|
911
|
+
else if (isVertical) style.height = `${crossSize}px`;
|
|
912
|
+
|
|
913
|
+
Object.assign(container.style, style);
|
|
914
|
+
|
|
915
|
+
if (typeof html === 'string') {
|
|
916
|
+
container.innerHTML = html;
|
|
917
|
+
} else if (html instanceof HTMLElement) {
|
|
918
|
+
container.appendChild(html);
|
|
919
|
+
}
|
|
920
|
+
document.body.appendChild(container);
|
|
921
|
+
const bbox = container.getBoundingClientRect();
|
|
922
|
+
document.body.removeChild(container);
|
|
923
|
+
component.size = isVertical ? bbox.width : bbox.height;
|
|
924
|
+
return;
|
|
925
|
+
}
|
|
926
|
+
|
|
874
927
|
// Compute title.
|
|
875
928
|
const titleBBox = computeTitleBBox(rest);
|
|
876
929
|
|
|
877
|
-
const scale = createScale(component, library);
|
|
878
930
|
const labelBBoxes = computeLabelsBBox(rest, scale, 'itemLabel');
|
|
879
931
|
|
|
880
|
-
|
|
881
|
-
const
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
932
|
+
// Compute itemValue sizes if itemValue is configured
|
|
933
|
+
const valueBBoxes =
|
|
934
|
+
rest.itemValueText !== undefined
|
|
935
|
+
? computeLabelsBBox(rest, scale, 'itemValue')
|
|
936
|
+
: null;
|
|
937
|
+
|
|
938
|
+
const height =
|
|
939
|
+
Math.max(
|
|
940
|
+
labelBBoxes[0].height,
|
|
941
|
+
itemMarkerSize,
|
|
942
|
+
// Also consider itemValue height if it exists
|
|
943
|
+
...(valueBBoxes?.[0] ? [valueBBoxes[0].height] : []),
|
|
944
|
+
) + rowPadding;
|
|
945
|
+
|
|
946
|
+
const widthOf = (labelWidth, padding = 0) => {
|
|
947
|
+
// Calculate total width including marker, label, value (if exists), and focus icon
|
|
948
|
+
let totalWidth = itemMarkerSize + labelWidth + itemSpacing[0] + padding;
|
|
949
|
+
|
|
950
|
+
// Add itemValue width if it exists
|
|
951
|
+
if (valueBBoxes?.[0]) {
|
|
952
|
+
totalWidth += valueBBoxes[0].width + itemSpacing[1];
|
|
953
|
+
}
|
|
954
|
+
|
|
955
|
+
// Add focus icon width if focus is enabled
|
|
956
|
+
if (focus) {
|
|
957
|
+
totalWidth += focusMarkerSize + itemSpacing[2];
|
|
958
|
+
}
|
|
959
|
+
|
|
960
|
+
return totalWidth;
|
|
961
|
+
};
|
|
887
962
|
|
|
888
963
|
// Only support grid layout for vertical area.
|
|
889
964
|
const computeVerticalSize = () => {
|
|
@@ -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,15 +22,45 @@ 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];
|
|
@@ -125,7 +157,14 @@ export const Funnel: SC<FunnelOptions> = (options, context) => {
|
|
|
125
157
|
const { index } = value;
|
|
126
158
|
const { color: defaultColor, ...rest } = defaults;
|
|
127
159
|
const nextPoints = point2d[index + 1];
|
|
128
|
-
const
|
|
160
|
+
const previousPoints = point2d[index - 1];
|
|
161
|
+
const funnelPoints = adjustPoints(
|
|
162
|
+
points,
|
|
163
|
+
nextPoints,
|
|
164
|
+
previousPoints,
|
|
165
|
+
coordinate,
|
|
166
|
+
style.reverse,
|
|
167
|
+
);
|
|
129
168
|
const tpShape = !!isTranspose(coordinate);
|
|
130
169
|
const [p0, p1, p2, p3] = tpShape ? reorder(funnelPoints) : funnelPoints;
|
|
131
170
|
const { color = defaultColor, opacity } = value;
|
|
@@ -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