@antv/g2 5.3.4-beta.2 → 5.3.4
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 +11 -11
- package/dist/g2.min.js +11 -11
- package/esm/component/legendCategory.js +42 -0
- package/esm/component/legendCategory.js.map +1 -1
- package/esm/composition/geoPath.js +2 -1
- package/esm/composition/geoPath.js.map +1 -1
- package/esm/data/cluster.d.ts +1 -1
- package/esm/index.d.ts +2 -0
- package/esm/label-transform/contrastReverse.js +1 -31
- package/esm/label-transform/contrastReverse.js.map +1 -1
- package/esm/label-transform/exceedAdjust.d.ts +7 -2
- package/esm/label-transform/exceedAdjust.js +31 -7
- package/esm/label-transform/exceedAdjust.js.map +1 -1
- package/esm/label-transform/index.d.ts +2 -0
- package/esm/label-transform/index.js +1 -0
- package/esm/label-transform/index.js.map +1 -1
- package/esm/label-transform/overflowStroke.d.ts +8 -0
- package/esm/label-transform/overflowStroke.js +57 -0
- package/esm/label-transform/overflowStroke.js.map +1 -0
- package/esm/label-transform/utils.d.ts +10 -0
- package/esm/label-transform/utils.js +32 -0
- package/esm/label-transform/utils.js.map +1 -0
- package/esm/lib/core.d.ts +1 -0
- package/esm/lib/core.js +2 -1
- package/esm/lib/core.js.map +1 -1
- package/esm/lib/std.d.ts +1 -0
- package/esm/mark/sankey.js +13 -2
- package/esm/mark/sankey.js.map +1 -1
- package/esm/mark/treemap.js +2 -4
- package/esm/mark/treemap.js.map +1 -1
- package/esm/shape/gauge/round.js +23 -2
- package/esm/shape/gauge/round.js.map +1 -1
- package/esm/spec/labelTransform.d.ts +27 -1
- package/lib/component/legendCategory.js +42 -0
- package/lib/component/legendCategory.js.map +1 -1
- package/lib/composition/geoPath.js +2 -1
- package/lib/composition/geoPath.js.map +1 -1
- package/lib/data/cluster.d.ts +1 -1
- package/lib/index.d.ts +2 -0
- package/lib/label-transform/contrastReverse.js +3 -33
- package/lib/label-transform/contrastReverse.js.map +1 -1
- package/lib/label-transform/exceedAdjust.d.ts +7 -2
- package/lib/label-transform/exceedAdjust.js +31 -7
- package/lib/label-transform/exceedAdjust.js.map +1 -1
- package/lib/label-transform/index.d.ts +2 -0
- package/lib/label-transform/index.js +3 -1
- package/lib/label-transform/index.js.map +1 -1
- package/lib/label-transform/overflowStroke.d.ts +8 -0
- package/lib/label-transform/overflowStroke.js +61 -0
- package/lib/label-transform/overflowStroke.js.map +1 -0
- package/lib/label-transform/utils.d.ts +10 -0
- package/lib/label-transform/utils.js +37 -0
- package/lib/label-transform/utils.js.map +1 -0
- package/lib/lib/core.d.ts +1 -0
- package/lib/lib/core.js +1 -0
- package/lib/lib/core.js.map +1 -1
- package/lib/lib/std.d.ts +1 -0
- package/lib/mark/sankey.js +12 -1
- package/lib/mark/sankey.js.map +1 -1
- package/lib/mark/treemap.js +2 -4
- package/lib/mark/treemap.js.map +1 -1
- package/lib/shape/gauge/round.js +23 -2
- package/lib/shape/gauge/round.js.map +1 -1
- package/lib/spec/labelTransform.d.ts +27 -1
- package/package.json +5 -25
- package/src/component/legendCategory.ts +49 -0
- package/src/composition/geoPath.ts +13 -2
- package/src/label-transform/contrastReverse.ts +1 -34
- package/src/label-transform/exceedAdjust.ts +53 -8
- package/src/label-transform/index.ts +2 -0
- package/src/label-transform/overflowStroke.ts +69 -0
- package/src/label-transform/utils.ts +34 -0
- package/src/lib/core.ts +2 -0
- package/src/mark/sankey.ts +16 -2
- package/src/mark/treemap.ts +3 -4
- package/src/shape/gauge/round.ts +24 -2
- package/src/spec/labelTransform.ts +28 -0
package/lib/mark/sankey.js
CHANGED
|
@@ -63,7 +63,7 @@ const DEFAULT_LABEL_OPTIONS = {
|
|
|
63
63
|
* @todo Add source-link color mode
|
|
64
64
|
*/
|
|
65
65
|
const Sankey = (options) => {
|
|
66
|
-
const { data, encode = {}, scale, style = {}, layout = {}, nodeLabels = [], linkLabels = [], animate = {}, tooltip = {}, interaction, } = options;
|
|
66
|
+
const { data, encode = {}, scale, style = {}, layout = {}, nodeLabels = [], linkLabels = [], animate = {}, tooltip = {}, interaction, state = {}, } = options;
|
|
67
67
|
// Initialize data, generating nodes by link if is not specified.
|
|
68
68
|
const { links, nodes } = (0, utils_1.initializeData)(data, encode);
|
|
69
69
|
// Extract encode for node and link.
|
|
@@ -86,6 +86,15 @@ const Sankey = (options) => {
|
|
|
86
86
|
(d) => ({ name: 'target', value: key1(d.target) }),
|
|
87
87
|
],
|
|
88
88
|
});
|
|
89
|
+
// Extract node and link state.
|
|
90
|
+
const [nodeState, linkState] = Object.entries(state).reduce((acc, [stateName, styleObj]) => {
|
|
91
|
+
const commonState = (0, helper_1.omitPrefixObject)(styleObj, 'node', 'link');
|
|
92
|
+
const nodeState = (0, helper_1.subObject)(styleObj, 'node');
|
|
93
|
+
acc[0][stateName] = Object.assign(Object.assign({}, commonState), nodeState);
|
|
94
|
+
const linkState = (0, helper_1.subObject)(styleObj, 'link');
|
|
95
|
+
acc[1][stateName] = Object.assign(Object.assign({}, commonState), linkState);
|
|
96
|
+
return acc;
|
|
97
|
+
}, [{}, {}]);
|
|
89
98
|
return [
|
|
90
99
|
(0, util_1.deepMix)({}, DEFAULT_NODE_OPTIONS, {
|
|
91
100
|
data: nodeData,
|
|
@@ -100,6 +109,7 @@ const Sankey = (options) => {
|
|
|
100
109
|
animate: (0, mark_1.maybeAnimation)(animate, 'node'),
|
|
101
110
|
axis: false,
|
|
102
111
|
interaction,
|
|
112
|
+
state: nodeState,
|
|
103
113
|
}),
|
|
104
114
|
(0, util_1.deepMix)({}, DEFAULT_LINK_OPTIONS, {
|
|
105
115
|
data: linkData,
|
|
@@ -109,6 +119,7 @@ const Sankey = (options) => {
|
|
|
109
119
|
tooltip: linkTooltip,
|
|
110
120
|
animate: (0, mark_1.maybeAnimation)(animate, 'link'),
|
|
111
121
|
interaction,
|
|
122
|
+
state: linkState,
|
|
112
123
|
}),
|
|
113
124
|
];
|
|
114
125
|
};
|
package/lib/mark/sankey.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sankey.js","sourceRoot":"","sources":["../../src/mark/sankey.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,qCAAqC;AAGrC,2CAA2D;AAC3D,
|
|
1
|
+
{"version":3,"file":"sankey.js","sourceRoot":"","sources":["../../src/mark/sankey.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,qCAAqC;AAGrC,2CAA2D;AAC3D,4CAA8D;AAC9D,wCAA2D;AAC3D,mCAAgD;AAEhD,MAAM,sBAAsB,GAAG;IAC7B,MAAM,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,GAAG;IACpB,SAAS,EAAE,IAAI;IACf,WAAW,EAAE,IAAI;CAClB,CAAC;AAEF,MAAM,oBAAoB,GAAG;IAC3B,IAAI,EAAE,SAAS;IACf,IAAI,EAAE,KAAK;IACX,MAAM,EAAE,KAAK;IACb,MAAM,EAAE;QACN,KAAK,EAAE,SAAS;QAChB,CAAC,EAAE,GAAG;QACN,CAAC,EAAE,GAAG;KACP;IACD,KAAK,EAAE;QACL,CAAC,EAAE,EAAE,IAAI,EAAE,UAAU,EAAE;QACvB,CAAC,EAAE,EAAE,IAAI,EAAE,UAAU,EAAE;KACxB;IACD,KAAK,EAAE;QACL,MAAM,EAAE,MAAM;KACf;CACF,CAAC;AAEF,MAAM,oBAAoB,GAAG;IAC3B,IAAI,EAAE,SAAS;IACf,IAAI,EAAE,KAAK;IACX,MAAM,EAAE,KAAK;IACb,MAAM,EAAE;QACN,KAAK,EAAE,QAAQ;QACf,CAAC,EAAE,GAAG;QACN,CAAC,EAAE,GAAG;KACP;IACD,KAAK,EAAE;QACL,WAAW,EAAE,GAAG;QAChB,MAAM,EAAE,SAAS;KAClB;CACF,CAAC;AAEF,MAAM,qBAAqB,GAAG;IAC5B,SAAS,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,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ACX,KAAK,EAAE,SAAS;SACjB,CAAC;KACH,CAAC;AACJ,CAAC,CAAC;AAvGW,QAAA,MAAM,UAuGjB;AAEF,cAAM,CAAC,KAAK,GAAG,EAAE,CAAC"}
|
package/lib/mark/treemap.js
CHANGED
|
@@ -76,10 +76,8 @@ const DEFAULT_TOOLTIP_OPTIONS_DRILL = {
|
|
|
76
76
|
const Treemap = (options, context) => {
|
|
77
77
|
const { width, height, options: markOptions } = context;
|
|
78
78
|
const { data, encode = {}, scale, style = {}, layout = {}, labels = [], tooltip = {} } = options, resOptions = __rest(options, ["data", "encode", "scale", "style", "layout", "labels", "tooltip"]);
|
|
79
|
-
const treemapDrillDown = (0, util_1.get)(markOptions, [
|
|
80
|
-
'interaction',
|
|
81
|
-
'treemapDrillDown',
|
|
82
|
-
]);
|
|
79
|
+
const treemapDrillDown = (0, util_1.get)(markOptions, ['interaction', 'treemapDrillDown']) ||
|
|
80
|
+
(0, util_1.get)(markOptions, ['marks', 0, 'interaction', 'treemapDrillDown']);
|
|
83
81
|
// Layout
|
|
84
82
|
const layoutOptions = (0, util_1.deepMix)({}, GET_DEFAULT_LAYOUT_OPTIONS(width, height), layout, {
|
|
85
83
|
layer: treemapDrillDown
|
package/lib/mark/treemap.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"treemap.js","sourceRoot":"","sources":["../../src/mark/treemap.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,qCAAgD;AAChD,4CAA4C;AAG5C,wCAA6C;AAC7C,kEAA+D;AAI/D,WAAW;AACX,MAAM,0BAA0B,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,CAAC,CAAC;IACrD,IAAI,EAAE,iBAAiB;IACvB,KAAK,EAAE,GAAG,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAC/B,IAAI,EAAE,CAAC,KAAK,EAAE,MAAM,CAAC;IACrB,KAAK,EAAE,KAAK;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,EAC9B,MAAM,EAAE,aAAa,IAEzB,CAAC,CAAC,SAAS,GACd;YACD,MAAM,kBACJ,KAAK,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,IAAA,WAAI,EAAC,CAAC,CAAC,IAAI,CAAC,IACvB,MAAM,CACV;YACD,OAAO,EAAE,IAAA,mBAAY,EAAC,OAAO,EAAE,6BAA6B,CAAC;SAC9D;QACH,CAAC,CAAC,EAAE,CACP,CAAC;AACJ,CAAC,CAAC;AAlFW,QAAA,OAAO,WAkFlB;AAEF,eAAO,CAAC,KAAK,GAAG,EAAE,CAAC"}
|
package/lib/shape/gauge/round.js
CHANGED
|
@@ -6,6 +6,16 @@ const util_1 = require("@antv/util");
|
|
|
6
6
|
const getR = (point1, point2) => {
|
|
7
7
|
return (Math.sqrt(Math.pow(point1[0] - point2[0], 2) + Math.pow(point1[1] - point2[1], 2)) / 2);
|
|
8
8
|
};
|
|
9
|
+
// 计算两点之间的角度
|
|
10
|
+
const getAngle = (start, end, center) => {
|
|
11
|
+
const startAngle = Math.atan2(start[1] - center[1], start[0] - center[0]);
|
|
12
|
+
const endAngle = Math.atan2(end[1] - center[1], end[0] - center[0]);
|
|
13
|
+
let angle = endAngle - startAngle;
|
|
14
|
+
// 确保角度在 0-2π 之间
|
|
15
|
+
if (angle < 0)
|
|
16
|
+
angle += Math.PI * 2;
|
|
17
|
+
return angle;
|
|
18
|
+
};
|
|
9
19
|
// Gauge round.
|
|
10
20
|
const Round = (options, context) => {
|
|
11
21
|
if (!context)
|
|
@@ -21,6 +31,9 @@ const Round = (options, context) => {
|
|
|
21
31
|
const g = document.createElement('g', {});
|
|
22
32
|
const minR = getR(points[0], points[1]);
|
|
23
33
|
const maxR = getR(points[0], center) * 2;
|
|
34
|
+
// 计算每个弧段的角度
|
|
35
|
+
// 判断是否需要使用大弧度(角度大于180度)
|
|
36
|
+
const isHalf = getAngle(points[3], points[0], center) > Math.PI;
|
|
24
37
|
/**
|
|
25
38
|
* MinR small circle radius, maxR big circle radius.
|
|
26
39
|
* Draw four arcs.
|
|
@@ -30,9 +43,17 @@ const Round = (options, context) => {
|
|
|
30
43
|
style: Object.assign(Object.assign(Object.assign({ d: [
|
|
31
44
|
['M', ...points[0]],
|
|
32
45
|
['A', minR, minR, 0, 1, 0, ...points[1]],
|
|
33
|
-
[
|
|
46
|
+
[
|
|
47
|
+
'A',
|
|
48
|
+
maxR + minR * 2,
|
|
49
|
+
maxR + minR * 2,
|
|
50
|
+
0,
|
|
51
|
+
isHalf ? 1 : 0,
|
|
52
|
+
0,
|
|
53
|
+
...points[2],
|
|
54
|
+
],
|
|
34
55
|
['A', minR, minR, 0, 1, index === 0 ? 0 : 1, ...points[3]],
|
|
35
|
-
['A', maxR, maxR, 0, 0, 1, ...points[0]],
|
|
56
|
+
['A', maxR, maxR, 0, isHalf ? 1 : 0, 1, ...points[0]],
|
|
36
57
|
['Z'],
|
|
37
58
|
] }, defaultCfg), (0, util_1.omit)(options, ['shape', 'last', 'first'])), { fill: color || defaultCfg.color }),
|
|
38
59
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"round.js","sourceRoot":"","sources":["../../../src/shape/gauge/round.ts"],"names":[],"mappings":";;;AAAA,qCAAkC;AAKlC,4BAA4B;AAC5B,MAAM,IAAI,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE;IAC9B,OAAO,CACL,IAAI,CAAC,IAAI,CACP,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CACxE,GAAG,CAAC,CACN,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe;AACR,MAAM,KAAK,GAAqB,CAAC,OAAO,EAAE,OAAO,EAAE,EAAE;IAC1D,IAAI,CAAC,OAAO;QAAE,O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,CAAC,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;oBACrD,CAAC,GAAG,CAAC;iBACN,IACE,UAAU,GACV,IAAA,WAAI,EAAC,OAAO,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC,KAC5C,IAAI,EAAE,KAAK,IAAI,UAAU,CAAC,KAAK,GAChC;SACF,CAAC,CAAC;QAEH,CAAC,CAAC,WAAW,CAAC,SAAS,CAAC,CAAC;QAEzB,OAAO,CAAC,CAAC;IACX,CAAC,CAAC;AACJ,CAAC,CAAC;AArDW,QAAA,KAAK,SAqDhB"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { DisplayObject } from '@antv/g';
|
|
2
|
-
export type LabelTransform = OverlapHideLabelTransform | OverlapDodgeYLabelTransform | ContrastReverseLabelTransform | OverflowHideLabelTransform;
|
|
2
|
+
export type LabelTransform = OverlapHideLabelTransform | OverlapDodgeYLabelTransform | ContrastReverseLabelTransform | OverflowStrokeTransform | OverflowHideLabelTransform;
|
|
3
3
|
export type OverlapHideLabelTransform = {
|
|
4
4
|
type?: 'overlapHide';
|
|
5
5
|
/**
|
|
@@ -25,9 +25,35 @@ export type ContrastReverseLabelTransform = {
|
|
|
25
25
|
*/
|
|
26
26
|
palette?: string[];
|
|
27
27
|
};
|
|
28
|
+
export type OverflowStrokeTransform = {
|
|
29
|
+
type?: 'overlapStroke';
|
|
30
|
+
/**
|
|
31
|
+
* Stroke when label overflow more than threshold.
|
|
32
|
+
* Default is `2`.
|
|
33
|
+
*/
|
|
34
|
+
threshold?: number;
|
|
35
|
+
/**
|
|
36
|
+
* The optional color palette, default is [#000, #fff].
|
|
37
|
+
*/
|
|
38
|
+
palette?: string[];
|
|
39
|
+
};
|
|
28
40
|
export type OverflowHideLabelTransform = {
|
|
29
41
|
type: 'overflowHide';
|
|
30
42
|
};
|
|
31
43
|
export type ExceedAdjustLabel = {
|
|
32
44
|
type: 'exceedAdjust';
|
|
45
|
+
/**
|
|
46
|
+
* The boundary area to check for label overflow.
|
|
47
|
+
* - 'view': Check against the entire view area (default)
|
|
48
|
+
* - 'main': Check against the main area (excluding margins and paddings)
|
|
49
|
+
*/
|
|
50
|
+
bounds?: 'view' | 'main';
|
|
51
|
+
/**
|
|
52
|
+
* The X-axis offset, default is 0
|
|
53
|
+
*/
|
|
54
|
+
offsetX?: number;
|
|
55
|
+
/**
|
|
56
|
+
* The Y-axis offset, default is 0
|
|
57
|
+
*/
|
|
58
|
+
offsetY?: number;
|
|
33
59
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@antv/g2",
|
|
3
|
-
"version": "5.3.4
|
|
3
|
+
"version": "5.3.4",
|
|
4
4
|
"description": "the Grammar of Graphics in Javascript",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "lib/index.js",
|
|
@@ -23,15 +23,8 @@
|
|
|
23
23
|
},
|
|
24
24
|
"./package.json": "./package.json"
|
|
25
25
|
},
|
|
26
|
-
"sideEffects": [
|
|
27
|
-
|
|
28
|
-
],
|
|
29
|
-
"files": [
|
|
30
|
-
"src",
|
|
31
|
-
"lib",
|
|
32
|
-
"esm",
|
|
33
|
-
"dist"
|
|
34
|
-
],
|
|
26
|
+
"sideEffects": ["./esm/exports.js"],
|
|
27
|
+
"files": ["src", "lib", "esm", "dist"],
|
|
35
28
|
"scripts": {
|
|
36
29
|
"start": "cd site && npm run start",
|
|
37
30
|
"dev": "cross-env TZ=Asia/Shanghai vite",
|
|
@@ -57,16 +50,7 @@
|
|
|
57
50
|
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s",
|
|
58
51
|
"translate": "translate -d"
|
|
59
52
|
},
|
|
60
|
-
"keywords": [
|
|
61
|
-
"antv",
|
|
62
|
-
"g2",
|
|
63
|
-
"visualization",
|
|
64
|
-
"chart",
|
|
65
|
-
"grammar",
|
|
66
|
-
"graphics",
|
|
67
|
-
"interaction",
|
|
68
|
-
"animation"
|
|
69
|
-
],
|
|
53
|
+
"keywords": ["antv", "g2", "visualization", "chart", "grammar", "graphics", "interaction", "animation"],
|
|
70
54
|
"dependencies": {
|
|
71
55
|
"@antv/component": "^2.1.3",
|
|
72
56
|
"@antv/coord": "^0.4.7",
|
|
@@ -132,11 +116,7 @@
|
|
|
132
116
|
"xmlserializer": "^0.6.1"
|
|
133
117
|
},
|
|
134
118
|
"lint-staged": {
|
|
135
|
-
"*.{ts,tsx}": [
|
|
136
|
-
"eslint --fix",
|
|
137
|
-
"prettier --write",
|
|
138
|
-
"git add"
|
|
139
|
-
]
|
|
119
|
+
"*.{ts,tsx}": ["eslint --fix", "prettier --write", "git add"]
|
|
140
120
|
},
|
|
141
121
|
"limit-size": [
|
|
142
122
|
{
|
|
@@ -122,6 +122,54 @@ function inferItemMarkerSize(scales: Scale[], defaults: number) {
|
|
|
122
122
|
return defaults;
|
|
123
123
|
}
|
|
124
124
|
|
|
125
|
+
function inferItemMarkerLineWidth(options, context: GuideComponentContext) {
|
|
126
|
+
const { scales, markState } = context;
|
|
127
|
+
const [mark, shapes] = inferShape(scales, markState);
|
|
128
|
+
const { itemMarker, itemMarkerLineWidth } = options;
|
|
129
|
+
|
|
130
|
+
// If user explicitly set itemMarkerLineWidth, use it
|
|
131
|
+
if (itemMarkerLineWidth !== undefined) {
|
|
132
|
+
return itemMarkerLineWidth;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// Define line-based shapes that should have thicker line width
|
|
136
|
+
const lineShapes = [
|
|
137
|
+
'line',
|
|
138
|
+
'hyphen',
|
|
139
|
+
'dash',
|
|
140
|
+
'smooth',
|
|
141
|
+
'hv',
|
|
142
|
+
'hvh',
|
|
143
|
+
'vh',
|
|
144
|
+
'vhv',
|
|
145
|
+
];
|
|
146
|
+
|
|
147
|
+
// If itemMarker is explicitly set to a line shape
|
|
148
|
+
if (typeof itemMarker === 'string' && lineShapes.includes(itemMarker)) {
|
|
149
|
+
return 4;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
// If itemMarker is a function, we need to return a function that checks each shape
|
|
153
|
+
if (typeof itemMarker === 'function') {
|
|
154
|
+
return (d, i) => {
|
|
155
|
+
const markerShape = itemMarker(d.id, i);
|
|
156
|
+
if (typeof markerShape === 'string' && lineShapes.includes(markerShape)) {
|
|
157
|
+
return 4;
|
|
158
|
+
}
|
|
159
|
+
return undefined;
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
// Check if any of the inferred shapes are line-based
|
|
164
|
+
const shapesArray = Array.isArray(shapes) ? shapes : [shapes];
|
|
165
|
+
const hasLineShape = shapesArray.some((shape) => lineShapes.includes(shape));
|
|
166
|
+
if (hasLineShape) {
|
|
167
|
+
return 4;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
return undefined;
|
|
171
|
+
}
|
|
172
|
+
|
|
125
173
|
function inferCategoryStyle(options, context: GuideComponentContext) {
|
|
126
174
|
const { labelFormatter = (d) => `${d}` } = options;
|
|
127
175
|
const { scales, theme } = context;
|
|
@@ -131,6 +179,7 @@ function inferCategoryStyle(options, context: GuideComponentContext) {
|
|
|
131
179
|
itemMarker: inferItemMarker({ ...options, itemMarkerSize }, context),
|
|
132
180
|
itemMarkerSize: itemMarkerSize,
|
|
133
181
|
itemMarkerOpacity: inferItemMarkerOpacity(scales),
|
|
182
|
+
itemMarkerLineWidth: inferItemMarkerLineWidth(options, context),
|
|
134
183
|
};
|
|
135
184
|
|
|
136
185
|
const finalLabelFormatter =
|
|
@@ -8,8 +8,18 @@ export type GeoPathOptions = Omit<GeoPathComposition, 'type'>;
|
|
|
8
8
|
*/
|
|
9
9
|
export const GeoPath: CC<GeoPathOptions> = () => {
|
|
10
10
|
return (options) => {
|
|
11
|
-
const {
|
|
12
|
-
|
|
11
|
+
const {
|
|
12
|
+
type,
|
|
13
|
+
data,
|
|
14
|
+
scale,
|
|
15
|
+
encode,
|
|
16
|
+
style,
|
|
17
|
+
animate,
|
|
18
|
+
key,
|
|
19
|
+
state,
|
|
20
|
+
tooltip,
|
|
21
|
+
...rest
|
|
22
|
+
} = options;
|
|
13
23
|
return [
|
|
14
24
|
{
|
|
15
25
|
type: 'geoView',
|
|
@@ -26,6 +36,7 @@ export const GeoPath: CC<GeoPathOptions> = () => {
|
|
|
26
36
|
style,
|
|
27
37
|
animate,
|
|
28
38
|
state,
|
|
39
|
+
tooltip,
|
|
29
40
|
},
|
|
30
41
|
],
|
|
31
42
|
},
|
|
@@ -1,46 +1,13 @@
|
|
|
1
1
|
import { DisplayObject } from '@antv/g';
|
|
2
|
-
import { maxIndex } from '@antv/vendor/d3-array';
|
|
3
2
|
import { ContrastReverseLabelTransform } from '../spec';
|
|
4
3
|
import { LabelTransformComponent as LLC } from '../runtime';
|
|
5
|
-
import {
|
|
4
|
+
import { contrast, mostContrast } from './utils';
|
|
6
5
|
|
|
7
6
|
export type ContrastReverseOptions = Omit<
|
|
8
7
|
ContrastReverseLabelTransform,
|
|
9
8
|
'type'
|
|
10
9
|
>;
|
|
11
10
|
|
|
12
|
-
function getsRGB(s: number) {
|
|
13
|
-
let c = s / 255;
|
|
14
|
-
c = c <= 0.03928 ? c / 12.92 : Math.pow((c + 0.055) / 1.055, 2.4);
|
|
15
|
-
return c;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
function getL(r: number, g: number, b: number) {
|
|
19
|
-
return 0.2126 * getsRGB(r) + 0.7152 * getsRGB(g) + 0.0722 * getsRGB(b);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Calculate the contrast. see https://webaim.org/resources/contrastchecker/
|
|
24
|
-
* @param foreground
|
|
25
|
-
* @param background
|
|
26
|
-
*/
|
|
27
|
-
function contrast(foreground, background): number {
|
|
28
|
-
if (!foreground || !background || foreground === background) return 1;
|
|
29
|
-
const { r, g, b } = foreground;
|
|
30
|
-
const { r: rb, g: gb, b: bb } = background;
|
|
31
|
-
const L1 = getL(r, g, b);
|
|
32
|
-
const L2 = getL(rb, gb, bb);
|
|
33
|
-
return (Math.max(L1, L2) + 0.05) / (Math.min(L1, L2) + 0.05);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Reverse color for max contrast.
|
|
38
|
-
*/
|
|
39
|
-
function mostContrast(color, palette: string[]): string {
|
|
40
|
-
const i = maxIndex(palette, (c) => contrast(color, parseToRGB(c)));
|
|
41
|
-
return palette[i];
|
|
42
|
-
}
|
|
43
|
-
|
|
44
11
|
/**
|
|
45
12
|
* Reverse the label color when the contrast is lower then `threshold`.
|
|
46
13
|
* The default value of `threshold` is 4.5.
|
|
@@ -28,13 +28,61 @@ const adjustPosition = (target: Bounds, edge: Bounds) => {
|
|
|
28
28
|
return [changeX, changeY];
|
|
29
29
|
};
|
|
30
30
|
|
|
31
|
-
export type ExceedAdjustOptions = Omit<ExceedAdjustLabel, 'type'
|
|
31
|
+
export type ExceedAdjustOptions = Omit<ExceedAdjustLabel, 'type'> & {
|
|
32
|
+
/** X-axis offset default is 0 */
|
|
33
|
+
offsetX?: number;
|
|
34
|
+
/** Y-axis offset default is 0 */
|
|
35
|
+
offsetY?: number;
|
|
36
|
+
};
|
|
32
37
|
|
|
33
38
|
/**
|
|
34
|
-
* adjust the label when exceed the
|
|
39
|
+
* adjust the label when exceed the specific area
|
|
35
40
|
*/
|
|
36
|
-
export const ExceedAdjust: LLC<ExceedAdjustOptions> = () => {
|
|
41
|
+
export const ExceedAdjust: LLC<ExceedAdjustOptions> = (options = {}) => {
|
|
37
42
|
return (labels: DisplayObject[], { canvas, layout }) => {
|
|
43
|
+
const { bounds = 'view', offsetX = 0, offsetY = 0 } = options;
|
|
44
|
+
|
|
45
|
+
// Calculate boundary area based on bounds option
|
|
46
|
+
const getBoundaryArea = () => {
|
|
47
|
+
if (bounds === 'main') {
|
|
48
|
+
// Main area: exclude margins and paddings from view area
|
|
49
|
+
const {
|
|
50
|
+
x = 0,
|
|
51
|
+
y = 0,
|
|
52
|
+
width = 0,
|
|
53
|
+
height = 0,
|
|
54
|
+
marginLeft = 0,
|
|
55
|
+
marginRight = 0,
|
|
56
|
+
marginTop = 0,
|
|
57
|
+
marginBottom = 0,
|
|
58
|
+
paddingLeft = 0,
|
|
59
|
+
paddingRight = 0,
|
|
60
|
+
paddingTop = 0,
|
|
61
|
+
paddingBottom = 0,
|
|
62
|
+
} = layout;
|
|
63
|
+
|
|
64
|
+
return [
|
|
65
|
+
[
|
|
66
|
+
x + marginLeft + paddingLeft + offsetX,
|
|
67
|
+
y + marginTop + paddingTop + offsetY,
|
|
68
|
+
],
|
|
69
|
+
[
|
|
70
|
+
x + width - marginRight - paddingRight - offsetX,
|
|
71
|
+
y + height - marginBottom - paddingBottom - offsetY,
|
|
72
|
+
],
|
|
73
|
+
] as Bounds;
|
|
74
|
+
} else {
|
|
75
|
+
// View area (default): entire layout area
|
|
76
|
+
const { x = 0, y = 0, width = 0, height = 0 } = layout;
|
|
77
|
+
return [
|
|
78
|
+
[x + offsetX, y + offsetY],
|
|
79
|
+
[x + width - offsetX, y + height - offsetY],
|
|
80
|
+
] as Bounds;
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
const boundaryArea = getBoundaryArea();
|
|
85
|
+
|
|
38
86
|
labels.forEach((l) => {
|
|
39
87
|
show(l);
|
|
40
88
|
const { max, min } = l.getRenderBounds();
|
|
@@ -45,11 +93,8 @@ export const ExceedAdjust: LLC<ExceedAdjustOptions> = () => {
|
|
|
45
93
|
[xMin, yMin],
|
|
46
94
|
[xMax, yMax],
|
|
47
95
|
],
|
|
48
|
-
//
|
|
49
|
-
|
|
50
|
-
[layout.x, layout.y],
|
|
51
|
-
[layout.x + layout.width, layout.y + layout.height],
|
|
52
|
-
],
|
|
96
|
+
// Use the calculated boundary area based on bounds configuration
|
|
97
|
+
boundaryArea,
|
|
53
98
|
);
|
|
54
99
|
// For label with connectorPoints
|
|
55
100
|
if (l.style.connector && l.style.connectorPoints) {
|
|
@@ -3,9 +3,11 @@ export { OverlapDodgeY } from './overlapDodgeY';
|
|
|
3
3
|
export { ContrastReverse } from './contrastReverse';
|
|
4
4
|
export { OverflowHide } from './overflowHide';
|
|
5
5
|
export { ExceedAdjust } from './exceedAdjust';
|
|
6
|
+
export { OverflowStroke } from './overflowStroke';
|
|
6
7
|
|
|
7
8
|
export type { OverlapHideOptions } from './overlapHide';
|
|
8
9
|
export type { OverlapDodgeYOptions } from './overlapDodgeY';
|
|
9
10
|
export type { ContrastReverseOptions } from './contrastReverse';
|
|
11
|
+
export type { OverflowStrokeOptions } from './overflowStroke';
|
|
10
12
|
export type { OverflowHideOptions } from './overflowHide';
|
|
11
13
|
export type { ExceedAdjustOptions } from './exceedAdjust';
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { DisplayObject } from '@antv/g';
|
|
2
|
+
import { OverflowStrokeTransform } from '../spec';
|
|
3
|
+
import { LabelTransformComponent as LLC } from '../runtime';
|
|
4
|
+
import { parseToRGB } from '../utils/color';
|
|
5
|
+
import { isOverflow, parseAABB } from '../utils/bounds';
|
|
6
|
+
import { bboxOf } from '../interaction/utils';
|
|
7
|
+
import { mostContrast } from './utils';
|
|
8
|
+
|
|
9
|
+
export type OverflowStrokeOptions = Omit<OverflowStrokeTransform, 'type'>;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Get bounds of element considering animation state.
|
|
13
|
+
* If element has animations, get the final state bounds.
|
|
14
|
+
*/
|
|
15
|
+
function getBoundsWithAnimation(element: DisplayObject) {
|
|
16
|
+
const animations = element.getAnimations();
|
|
17
|
+
|
|
18
|
+
// If no animations, use regular bboxOf.
|
|
19
|
+
if (!animations || animations.length === 0) {
|
|
20
|
+
return bboxOf(element);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// Clone element and apply final animation state.
|
|
24
|
+
const cloneElement = element.cloneNode(true) as DisplayObject;
|
|
25
|
+
cloneElement.style.visibility = 'hidden';
|
|
26
|
+
|
|
27
|
+
animations.forEach((animation) => {
|
|
28
|
+
const keyframes = animation.effect.getKeyframes();
|
|
29
|
+
if (keyframes && keyframes.length > 0) {
|
|
30
|
+
cloneElement.attr(keyframes[keyframes.length - 1]);
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
element.parentNode?.appendChild(cloneElement);
|
|
35
|
+
const bounds = bboxOf(cloneElement);
|
|
36
|
+
cloneElement.destroy();
|
|
37
|
+
|
|
38
|
+
return bounds;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Reverse label stroke against label color.
|
|
43
|
+
* More about contract, see https://webaim.org/resources/contrastchecker/
|
|
44
|
+
*/
|
|
45
|
+
export const OverflowStroke: LLC<OverflowStrokeOptions> = (options) => {
|
|
46
|
+
const { palette = ['#000', '#fff'], threshold = 2 } = options;
|
|
47
|
+
|
|
48
|
+
return (labels: DisplayObject[]) => {
|
|
49
|
+
labels.forEach((l) => {
|
|
50
|
+
const dependentElement = l.attr('dependentElement');
|
|
51
|
+
const labelFill = l.attributes.fill ?? l.parsedStyle.fill ?? '#fff';
|
|
52
|
+
|
|
53
|
+
const textBounds = parseAABB(getBoundsWithAnimation(l));
|
|
54
|
+
const elementBounds = parseAABB(getBoundsWithAnimation(dependentElement));
|
|
55
|
+
|
|
56
|
+
if (isOverflow(textBounds, elementBounds, threshold)) {
|
|
57
|
+
// Add stroke to make overflowing text more visible.
|
|
58
|
+
// Use the opposite color from palette for stroke.
|
|
59
|
+
const strokeColor = mostContrast(parseToRGB(labelFill), palette);
|
|
60
|
+
|
|
61
|
+
l.attr('stroke', strokeColor);
|
|
62
|
+
} else {
|
|
63
|
+
// Undefined can't set to attrs, have to remove.
|
|
64
|
+
l.removeAttribute('stroke');
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
return labels;
|
|
68
|
+
};
|
|
69
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { maxIndex } from '@antv/vendor/d3-array';
|
|
2
|
+
import { parseToRGB } from '../utils/color';
|
|
3
|
+
|
|
4
|
+
function getsRGB(s: number) {
|
|
5
|
+
let c = s / 255;
|
|
6
|
+
c = c <= 0.03928 ? c / 12.92 : Math.pow((c + 0.055) / 1.055, 2.4);
|
|
7
|
+
return c;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
function getL(r: number, g: number, b: number) {
|
|
11
|
+
return 0.2126 * getsRGB(r) + 0.7152 * getsRGB(g) + 0.0722 * getsRGB(b);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Calculate the contrast. see https://webaim.org/resources/contrastchecker/
|
|
16
|
+
* @param foreground
|
|
17
|
+
* @param background
|
|
18
|
+
*/
|
|
19
|
+
export function contrast(foreground, background): number {
|
|
20
|
+
if (!foreground || !background || foreground === background) return 1;
|
|
21
|
+
const { r, g, b } = foreground;
|
|
22
|
+
const { r: rb, g: gb, b: bb } = background;
|
|
23
|
+
const L1 = getL(r, g, b);
|
|
24
|
+
const L2 = getL(rb, gb, bb);
|
|
25
|
+
return (Math.max(L1, L2) + 0.05) / (Math.min(L1, L2) + 0.05);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Reverse color for max contrast.
|
|
30
|
+
*/
|
|
31
|
+
export function mostContrast(color, palette: string[]): string {
|
|
32
|
+
const i = maxIndex(palette, (c) => contrast(color, parseToRGB(c)));
|
|
33
|
+
return palette[i];
|
|
34
|
+
}
|
package/src/lib/core.ts
CHANGED
|
@@ -164,6 +164,7 @@ import {
|
|
|
164
164
|
ContrastReverse,
|
|
165
165
|
OverlapHide,
|
|
166
166
|
ExceedAdjust,
|
|
167
|
+
OverflowStroke,
|
|
167
168
|
} from '../label-transform';
|
|
168
169
|
|
|
169
170
|
export function corelib() {
|
|
@@ -322,6 +323,7 @@ export function corelib() {
|
|
|
322
323
|
'labelTransform.overlapDodgeY': OverlapDodgeY,
|
|
323
324
|
'labelTransform.overflowHide': OverflowHide,
|
|
324
325
|
'labelTransform.contrastReverse': ContrastReverse,
|
|
326
|
+
'labelTransform.overflowStroke': OverflowStroke,
|
|
325
327
|
'labelTransform.exceedAdjust': ExceedAdjust,
|
|
326
328
|
} as const;
|
|
327
329
|
}
|
package/src/mark/sankey.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { deepMix } from '@antv/util';
|
|
|
2
2
|
import { CompositeMarkComponent as CC } from '../runtime';
|
|
3
3
|
import { SankeyMark } from '../spec';
|
|
4
4
|
import { Sankey as SankeyTransform } from '../data/sankey';
|
|
5
|
-
import { subObject } from '../utils/helper';
|
|
5
|
+
import { omitPrefixObject, subObject } from '../utils/helper';
|
|
6
6
|
import { subTooltip, maybeAnimation } from '../utils/mark';
|
|
7
7
|
import { field, initializeData } from './utils';
|
|
8
8
|
|
|
@@ -69,6 +69,7 @@ export const Sankey: CC<SankeyOptions> = (options) => {
|
|
|
69
69
|
animate = {},
|
|
70
70
|
tooltip = {},
|
|
71
71
|
interaction,
|
|
72
|
+
state = {},
|
|
72
73
|
} = options;
|
|
73
74
|
|
|
74
75
|
// Initialize data, generating nodes by link if is not specified.
|
|
@@ -111,7 +112,18 @@ export const Sankey: CC<SankeyOptions> = (options) => {
|
|
|
111
112
|
(d) => ({ name: 'target', value: key1(d.target) }),
|
|
112
113
|
],
|
|
113
114
|
});
|
|
114
|
-
|
|
115
|
+
// Extract node and link state.
|
|
116
|
+
const [nodeState, linkState] = Object.entries(state).reduce(
|
|
117
|
+
(acc, [stateName, styleObj]) => {
|
|
118
|
+
const commonState = omitPrefixObject(styleObj, 'node', 'link');
|
|
119
|
+
const nodeState = subObject(styleObj, 'node');
|
|
120
|
+
acc[0][stateName] = { ...commonState, ...nodeState };
|
|
121
|
+
const linkState = subObject(styleObj, 'link');
|
|
122
|
+
acc[1][stateName] = { ...commonState, ...linkState };
|
|
123
|
+
return acc;
|
|
124
|
+
},
|
|
125
|
+
[{}, {}],
|
|
126
|
+
);
|
|
115
127
|
return [
|
|
116
128
|
deepMix({}, DEFAULT_NODE_OPTIONS, {
|
|
117
129
|
data: nodeData,
|
|
@@ -131,6 +143,7 @@ export const Sankey: CC<SankeyOptions> = (options) => {
|
|
|
131
143
|
animate: maybeAnimation(animate, 'node'),
|
|
132
144
|
axis: false,
|
|
133
145
|
interaction,
|
|
146
|
+
state: nodeState,
|
|
134
147
|
}),
|
|
135
148
|
deepMix({}, DEFAULT_LINK_OPTIONS, {
|
|
136
149
|
data: linkData,
|
|
@@ -144,6 +157,7 @@ export const Sankey: CC<SankeyOptions> = (options) => {
|
|
|
144
157
|
tooltip: linkTooltip,
|
|
145
158
|
animate: maybeAnimation(animate, 'link'),
|
|
146
159
|
interaction,
|
|
160
|
+
state: linkState,
|
|
147
161
|
}),
|
|
148
162
|
];
|
|
149
163
|
};
|