@antv/g2 5.1.13 → 5.1.15-beta.0
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 +1 -1
- package/dist/g2.min.js +1 -1
- package/esm/animation/growInX.js +1 -1
- package/esm/animation/growInX.js.map +1 -1
- package/esm/animation/growInY.js +1 -1
- package/esm/animation/growInY.js.map +1 -1
- package/esm/animation/morphing.js +8 -4
- package/esm/animation/morphing.js.map +1 -1
- package/esm/animation/scaleInY.js +2 -5
- package/esm/animation/scaleInY.js.map +1 -1
- package/esm/animation/waveIn.js +2 -1
- package/esm/animation/waveIn.js.map +1 -1
- package/esm/api/utils.js +27 -15
- package/esm/api/utils.js.map +1 -1
- package/esm/component/axis.js +13 -7
- package/esm/component/axis.js.map +1 -1
- package/esm/component/title.js +2 -1
- package/esm/component/title.js.map +1 -1
- package/esm/coordinate/polar.d.ts +1 -1
- package/esm/coordinate/polar.js +3 -1
- package/esm/coordinate/polar.js.map +1 -1
- package/esm/index.d.ts +2 -0
- package/esm/interaction/event.js +15 -3
- package/esm/interaction/event.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.d.ts +1 -0
- package/esm/interaction/legendFilter.js +6 -0
- package/esm/interaction/legendFilter.js.map +1 -1
- package/esm/interaction/scrollbarFilter.js +5 -1
- package/esm/interaction/scrollbarFilter.js.map +1 -1
- package/esm/interaction/sliderFilter.d.ts +1 -1
- package/esm/interaction/sliderFilter.js +19 -2
- package/esm/interaction/sliderFilter.js.map +1 -1
- package/esm/interaction/tooltip.js +2 -2
- package/esm/interaction/tooltip.js.map +1 -1
- package/esm/interaction/treemapDrillDown.d.ts +10 -0
- package/esm/interaction/treemapDrillDown.js +229 -0
- package/esm/interaction/treemapDrillDown.js.map +1 -0
- package/esm/interaction/utils.js +7 -6
- package/esm/interaction/utils.js.map +1 -1
- package/esm/lib/core.d.ts +2 -1
- 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/chord.js +0 -1
- package/esm/mark/chord.js.map +1 -1
- package/esm/mark/gauge.js +4 -1
- package/esm/mark/gauge.js.map +1 -1
- package/esm/mark/sankey.js +1 -1
- package/esm/mark/sankey.js.map +1 -1
- package/esm/mark/treemap.js +37 -57
- package/esm/mark/treemap.js.map +1 -1
- package/esm/mark/utils.d.ts +0 -5
- package/esm/mark/utils.js +0 -13
- package/esm/mark/utils.js.map +1 -1
- package/esm/runtime/plot.js +52 -35
- package/esm/runtime/plot.js.map +1 -1
- package/esm/runtime/types/common.d.ts +1 -1
- package/esm/shape/connector/connector.js +1 -1
- package/esm/shape/connector/connector.js.map +1 -1
- package/esm/shape/gauge/round.d.ts +3 -0
- package/esm/shape/gauge/round.js +40 -0
- package/esm/shape/gauge/round.js.map +1 -0
- package/esm/shape/image/image.js +1 -1
- package/esm/shape/index.d.ts +1 -0
- package/esm/shape/index.js +1 -0
- package/esm/shape/index.js.map +1 -1
- package/esm/shape/interval/color.js +1 -1
- package/esm/shape/interval/color.js.map +1 -1
- package/esm/shape/interval/funnel.js +1 -1
- package/esm/shape/interval/funnel.js.map +1 -1
- package/esm/shape/label/position/default.js +9 -9
- package/esm/shape/label/position/default.js.map +1 -1
- package/esm/shape/lineXY/line.js +1 -1
- package/esm/shape/lineXY/line.js.map +1 -1
- package/esm/shape/liquid/liquid.js +4 -4
- package/esm/shape/liquid/liquid.js.map +1 -1
- package/esm/shape/liquid/wave.js +1 -1
- package/esm/shape/liquid/wave.js.map +1 -1
- package/esm/shape/point/color.js +1 -0
- package/esm/shape/point/color.js.map +1 -1
- package/esm/shape/text/advance.js +2 -1
- package/esm/shape/text/advance.js.map +1 -1
- package/esm/shape/utils.js +2 -2
- package/esm/shape/utils.js.map +1 -1
- package/esm/theme/create.d.ts +2 -2
- package/esm/theme/create.js +2 -2
- package/esm/theme/create.js.map +1 -1
- package/esm/utils/angle.d.ts +4 -0
- package/esm/utils/angle.js +18 -0
- package/esm/utils/angle.js.map +1 -1
- package/esm/utils/marker.d.ts +1 -1
- package/esm/utils/marker.js +2 -2
- package/esm/utils/marker.js.map +1 -1
- package/esm/utils/treeDataTransform.d.ts +21 -0
- package/esm/utils/treeDataTransform.js +90 -0
- package/esm/utils/treeDataTransform.js.map +1 -0
- package/lib/animation/growInX.js +1 -1
- package/lib/animation/growInX.js.map +1 -1
- package/lib/animation/growInY.js +1 -1
- package/lib/animation/growInY.js.map +1 -1
- package/lib/animation/morphing.js +8 -4
- package/lib/animation/morphing.js.map +1 -1
- package/lib/animation/scaleInY.js +2 -5
- package/lib/animation/scaleInY.js.map +1 -1
- package/lib/animation/waveIn.js +2 -1
- package/lib/animation/waveIn.js.map +1 -1
- package/lib/api/utils.js +27 -15
- package/lib/api/utils.js.map +1 -1
- package/lib/component/axis.js +13 -7
- package/lib/component/axis.js.map +1 -1
- package/lib/component/title.js +2 -1
- package/lib/component/title.js.map +1 -1
- package/lib/coordinate/polar.d.ts +1 -1
- package/lib/coordinate/polar.js +3 -1
- package/lib/coordinate/polar.js.map +1 -1
- package/lib/index.d.ts +2 -0
- package/lib/interaction/event.js +15 -3
- package/lib/interaction/event.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.d.ts +1 -0
- package/lib/interaction/legendFilter.js +8 -1
- package/lib/interaction/legendFilter.js.map +1 -1
- package/lib/interaction/scrollbarFilter.js +5 -1
- package/lib/interaction/scrollbarFilter.js.map +1 -1
- package/lib/interaction/sliderFilter.d.ts +1 -1
- package/lib/interaction/sliderFilter.js +19 -2
- package/lib/interaction/sliderFilter.js.map +1 -1
- package/lib/interaction/tooltip.js +2 -2
- package/lib/interaction/tooltip.js.map +1 -1
- package/lib/interaction/treemapDrillDown.d.ts +10 -0
- package/lib/interaction/treemapDrillDown.js +233 -0
- package/lib/interaction/treemapDrillDown.js.map +1 -0
- package/lib/interaction/utils.js +7 -6
- package/lib/interaction/utils.js.map +1 -1
- package/lib/lib/core.d.ts +2 -1
- 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/chord.js +0 -1
- package/lib/mark/chord.js.map +1 -1
- package/lib/mark/gauge.js +4 -1
- package/lib/mark/gauge.js.map +1 -1
- package/lib/mark/sankey.js +1 -1
- package/lib/mark/sankey.js.map +1 -1
- package/lib/mark/treemap.js +36 -56
- package/lib/mark/treemap.js.map +1 -1
- package/lib/mark/utils.d.ts +0 -5
- package/lib/mark/utils.js +1 -15
- package/lib/mark/utils.js.map +1 -1
- package/lib/runtime/plot.js +51 -34
- package/lib/runtime/plot.js.map +1 -1
- package/lib/runtime/types/common.d.ts +1 -1
- package/lib/shape/connector/connector.js +1 -1
- package/lib/shape/connector/connector.js.map +1 -1
- package/lib/shape/gauge/round.d.ts +3 -0
- package/lib/shape/gauge/round.js +44 -0
- package/lib/shape/gauge/round.js.map +1 -0
- package/lib/shape/image/image.js +1 -1
- package/lib/shape/index.d.ts +1 -0
- package/lib/shape/index.js +3 -1
- package/lib/shape/index.js.map +1 -1
- package/lib/shape/interval/color.js +1 -1
- package/lib/shape/interval/color.js.map +1 -1
- package/lib/shape/interval/funnel.js +1 -1
- package/lib/shape/interval/funnel.js.map +1 -1
- package/lib/shape/label/position/default.js +9 -9
- package/lib/shape/label/position/default.js.map +1 -1
- package/lib/shape/lineXY/line.js +1 -1
- package/lib/shape/lineXY/line.js.map +1 -1
- package/lib/shape/liquid/liquid.js +4 -4
- package/lib/shape/liquid/liquid.js.map +1 -1
- package/lib/shape/liquid/wave.js +1 -1
- package/lib/shape/liquid/wave.js.map +1 -1
- package/lib/shape/point/color.js +1 -0
- package/lib/shape/point/color.js.map +1 -1
- package/lib/shape/text/advance.js +2 -1
- package/lib/shape/text/advance.js.map +1 -1
- package/lib/shape/utils.js +1 -1
- package/lib/shape/utils.js.map +1 -1
- package/lib/theme/create.d.ts +2 -2
- package/lib/theme/create.js +2 -2
- package/lib/theme/create.js.map +1 -1
- package/lib/utils/angle.d.ts +4 -0
- package/lib/utils/angle.js +20 -1
- package/lib/utils/angle.js.map +1 -1
- package/lib/utils/marker.d.ts +1 -1
- package/lib/utils/marker.js +2 -2
- package/lib/utils/marker.js.map +1 -1
- package/lib/utils/treeDataTransform.d.ts +21 -0
- package/lib/utils/treeDataTransform.js +94 -0
- package/lib/utils/treeDataTransform.js.map +1 -0
- package/package.json +15 -15
- package/src/animation/growInX.ts +1 -1
- package/src/animation/growInY.ts +1 -1
- package/src/animation/morphing.ts +7 -5
- package/src/animation/scaleInY.ts +2 -5
- package/src/animation/waveIn.ts +2 -1
- package/src/api/utils.ts +41 -13
- package/src/component/axis.ts +17 -10
- package/src/component/title.ts +4 -0
- package/src/coordinate/polar.ts +6 -1
- package/src/interaction/event.ts +20 -7
- package/src/interaction/index.ts +1 -0
- package/src/interaction/legendFilter.ts +8 -0
- package/src/interaction/scrollbarFilter.ts +4 -0
- package/src/interaction/sliderFilter.ts +21 -1
- package/src/interaction/tooltip.ts +3 -3
- package/src/interaction/treemapDrillDown.ts +282 -0
- package/src/interaction/utils.ts +8 -5
- package/src/lib/core.ts +2 -0
- package/src/mark/chord.ts +0 -1
- package/src/mark/gauge.ts +5 -1
- package/src/mark/sankey.ts +1 -1
- package/src/mark/treemap.ts +76 -123
- package/src/mark/utils.ts +0 -17
- package/src/runtime/plot.ts +93 -45
- package/src/runtime/types/common.ts +5 -1
- package/src/shape/connector/connector.ts +1 -1
- package/src/shape/gauge/round.ts +57 -0
- package/src/shape/image/image.ts +1 -1
- package/src/shape/index.ts +1 -0
- package/src/shape/interval/color.ts +1 -1
- package/src/shape/interval/funnel.ts +1 -1
- package/src/shape/label/position/default.ts +9 -9
- package/src/shape/lineXY/line.ts +1 -2
- package/src/shape/liquid/liquid.ts +4 -4
- package/src/shape/liquid/wave.ts +1 -1
- package/src/shape/point/color.ts +1 -0
- package/src/shape/text/advance.ts +3 -1
- package/src/shape/utils.ts +3 -2
- package/src/theme/create.ts +2 -2
- package/src/utils/angle.ts +22 -0
- package/src/utils/marker.ts +2 -11
- package/src/utils/treeDataTransform.ts +153 -0
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.treeDataTransform = void 0;
|
|
4
|
+
const util_1 = require("@antv/util");
|
|
5
|
+
const d3_hierarchy_1 = require("d3-hierarchy");
|
|
6
|
+
const utils_1 = require("../mark/utils");
|
|
7
|
+
/**
|
|
8
|
+
* @description Path need when the data is a flat json structure,
|
|
9
|
+
* and the tree object structure do not need.
|
|
10
|
+
*/
|
|
11
|
+
function generateHierarchyRoot(data, path) {
|
|
12
|
+
if (Array.isArray(data)) {
|
|
13
|
+
return typeof path === 'function'
|
|
14
|
+
? (0, d3_hierarchy_1.stratify)().path(path)(data)
|
|
15
|
+
: (0, d3_hierarchy_1.stratify)()(data);
|
|
16
|
+
}
|
|
17
|
+
return (0, d3_hierarchy_1.hierarchy)(data);
|
|
18
|
+
}
|
|
19
|
+
function addObjectDataPath(root, path = [root.data.name]) {
|
|
20
|
+
root.id = root.id || root.data.name;
|
|
21
|
+
root.path = path;
|
|
22
|
+
if (root.children) {
|
|
23
|
+
root.children.forEach((item) => {
|
|
24
|
+
item.id = `${root.id}/${item.data.name}`;
|
|
25
|
+
item.path = [...path, item.data.name];
|
|
26
|
+
addObjectDataPath(item, item.path);
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
function addArrayDataPath(root) {
|
|
31
|
+
const name = (0, util_1.get)(root, ['data', 'name']);
|
|
32
|
+
if (name.replaceAll) {
|
|
33
|
+
root.path = name.replaceAll('.', '/').split('/');
|
|
34
|
+
}
|
|
35
|
+
if (root.children) {
|
|
36
|
+
root.children.forEach((item) => {
|
|
37
|
+
addArrayDataPath(item);
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
function getTileMethod(tile, ratio) {
|
|
42
|
+
const tiles = {
|
|
43
|
+
treemapBinary: d3_hierarchy_1.treemapBinary,
|
|
44
|
+
treemapDice: d3_hierarchy_1.treemapDice,
|
|
45
|
+
treemapSlice: d3_hierarchy_1.treemapSlice,
|
|
46
|
+
treemapSliceDice: d3_hierarchy_1.treemapSliceDice,
|
|
47
|
+
treemapSquarify: d3_hierarchy_1.treemapSquarify,
|
|
48
|
+
treemapResquarify: d3_hierarchy_1.treemapResquarify,
|
|
49
|
+
};
|
|
50
|
+
const tileMethod = tile === 'treemapSquarify' ? tiles[tile].ratio(ratio) : tiles[tile];
|
|
51
|
+
if (!tileMethod) {
|
|
52
|
+
throw new TypeError('Invalid tile method!');
|
|
53
|
+
}
|
|
54
|
+
return tileMethod;
|
|
55
|
+
}
|
|
56
|
+
function treeDataTransform(data, layout, encode) {
|
|
57
|
+
const { value } = encode;
|
|
58
|
+
const tileMethod = getTileMethod(layout.tile, layout.ratio);
|
|
59
|
+
const root = generateHierarchyRoot(data, layout.path);
|
|
60
|
+
if ((0, util_1.isArray)(data)) {
|
|
61
|
+
addArrayDataPath(root);
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
addObjectDataPath(root);
|
|
65
|
+
}
|
|
66
|
+
// Calculate the value and sort.
|
|
67
|
+
value
|
|
68
|
+
? root
|
|
69
|
+
.sum((d) => layout.ignoreParentValue && d.children ? 0 : (0, utils_1.field)(value)(d))
|
|
70
|
+
.sort(layout.sort)
|
|
71
|
+
: root.count();
|
|
72
|
+
(0, d3_hierarchy_1.treemap)()
|
|
73
|
+
.tile(tileMethod)
|
|
74
|
+
// @ts-ignore
|
|
75
|
+
.size(layout.size)
|
|
76
|
+
.round(layout.round)
|
|
77
|
+
.paddingInner(layout.paddingInner)
|
|
78
|
+
.paddingOuter(layout.paddingOuter)
|
|
79
|
+
.paddingTop(layout.paddingTop)
|
|
80
|
+
.paddingRight(layout.paddingRight)
|
|
81
|
+
.paddingBottom(layout.paddingBottom)
|
|
82
|
+
.paddingLeft(layout.paddingLeft)(root);
|
|
83
|
+
const nodes = root.descendants().map((d) => Object.assign(d, {
|
|
84
|
+
id: d.id.replace(/^\//, ''),
|
|
85
|
+
x: [d.x0, d.x1],
|
|
86
|
+
y: [d.y0, d.y1],
|
|
87
|
+
}));
|
|
88
|
+
const filterData = nodes.filter(typeof layout.layer === 'function'
|
|
89
|
+
? layout.layer
|
|
90
|
+
: (d) => d.height === layout.layer);
|
|
91
|
+
return [filterData, nodes];
|
|
92
|
+
}
|
|
93
|
+
exports.treeDataTransform = treeDataTransform;
|
|
94
|
+
//# sourceMappingURL=treeDataTransform.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"treeDataTransform.js","sourceRoot":"src/","sources":["utils/treeDataTransform.ts"],"names":[],"mappings":"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"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@antv/g2",
|
|
3
|
-
"version": "5.1.
|
|
3
|
+
"version": "5.1.15-beta.0",
|
|
4
4
|
"description": "the Grammar of Graphics in Javascript",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "lib/index.js",
|
|
@@ -24,6 +24,7 @@
|
|
|
24
24
|
"dist"
|
|
25
25
|
],
|
|
26
26
|
"scripts": {
|
|
27
|
+
"start": "cd site && npm run start",
|
|
27
28
|
"dev": "cross-env TZ=Asia/Shanghai vite",
|
|
28
29
|
"dev:link": "cross-env LINK=1 vite",
|
|
29
30
|
"clean": "rimraf lib esm dist",
|
|
@@ -31,7 +32,7 @@
|
|
|
31
32
|
"size": "limit-size",
|
|
32
33
|
"lint": "eslint ./src ./__tests__ && prettier ./src ./__tests__ --check ",
|
|
33
34
|
"fix": "eslint ./src ./__tests__ --fix && prettier ./src ./__tests__ --write ",
|
|
34
|
-
"test": "cross-env TZ=Asia/Shanghai node --expose-gc --max-old-space-size=4096 --unhandled-rejections=strict node_modules/jest/bin/jest __tests__ --logHeapUsage",
|
|
35
|
+
"test": "cross-env TZ=Asia/Shanghai node --expose-gc --max-old-space-size=4096 --unhandled-rejections=strict node_modules/jest/bin/jest __tests__ --coverage --logHeapUsage",
|
|
35
36
|
"test:unit": "cross-env TZ=Asia/Shanghai node --expose-gc --max-old-space-size=4096 --unhandled-rejections=strict node_modules/jest/bin/jest __tests__/unit/ --coverage --logHeapUsage",
|
|
36
37
|
"test:integration": "cross-env TZ=Asia/Shanghai node --expose-gc --max-old-space-size=4096 --unhandled-rejections=strict node_modules/jest/bin/jest __tests__/integration/ --coverage --logHeapUsage",
|
|
37
38
|
"preview": "vite preview",
|
|
@@ -41,7 +42,6 @@
|
|
|
41
42
|
"build": "run-p build:*",
|
|
42
43
|
"bundle-vis": "cross-env BUNDLE_VIS=1 run-p build:umd",
|
|
43
44
|
"ci": "run-s lint test build",
|
|
44
|
-
"prepublishOnly": "npm run ci",
|
|
45
45
|
"prepare": "husky install",
|
|
46
46
|
"upload": "node scripts/upload/snapshot.js",
|
|
47
47
|
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s",
|
|
@@ -58,12 +58,12 @@
|
|
|
58
58
|
"animation"
|
|
59
59
|
],
|
|
60
60
|
"dependencies": {
|
|
61
|
-
"@antv/component": "^1.0.1-beta.
|
|
61
|
+
"@antv/component": "^1.0.1-beta.5",
|
|
62
62
|
"@antv/coord": "^0.4.6",
|
|
63
63
|
"@antv/event-emitter": "^0.1.3",
|
|
64
|
-
"@antv/g": "
|
|
65
|
-
"@antv/g-canvas": "
|
|
66
|
-
"@antv/g-plugin-dragndrop": "
|
|
64
|
+
"@antv/g": "5.18.25-next.18",
|
|
65
|
+
"@antv/g-canvas": "1.11.27-next.18",
|
|
66
|
+
"@antv/g-plugin-dragndrop": "1.8.22-next.18",
|
|
67
67
|
"@antv/path-util": "^3.0.1",
|
|
68
68
|
"@antv/scale": "^0.4.12",
|
|
69
69
|
"@antv/util": "^3.3.5",
|
|
@@ -83,13 +83,13 @@
|
|
|
83
83
|
},
|
|
84
84
|
"devDependencies": {
|
|
85
85
|
"@antv/data-set": "^0.11.8",
|
|
86
|
-
"@antv/g-pattern": "
|
|
87
|
-
"@antv/g-plugin-3d": "
|
|
88
|
-
"@antv/g-plugin-control": "
|
|
89
|
-
"@antv/g-plugin-rough-canvas-renderer": "
|
|
90
|
-
"@antv/g-plugin-rough-svg-renderer": "
|
|
91
|
-
"@antv/g-svg": "
|
|
92
|
-
"@antv/g-webgl": "
|
|
86
|
+
"@antv/g-pattern": "1.2.22-next.18",
|
|
87
|
+
"@antv/g-plugin-3d": "1.9.34-next.18",
|
|
88
|
+
"@antv/g-plugin-control": "1.9.22-next.18",
|
|
89
|
+
"@antv/g-plugin-rough-canvas-renderer": "1.9.27-next.18",
|
|
90
|
+
"@antv/g-plugin-rough-svg-renderer": "1.9.27-next.18",
|
|
91
|
+
"@antv/g-svg": "1.10.26-next.18",
|
|
92
|
+
"@antv/g-webgl": "1.9.37-next.18",
|
|
93
93
|
"@antv/g2-extension-3d": "^0.1.3",
|
|
94
94
|
"@antv/g2-extension-ava": "^0.1.1",
|
|
95
95
|
"@antv/g2-extension-plot": "^0.1.0",
|
|
@@ -163,7 +163,7 @@
|
|
|
163
163
|
},
|
|
164
164
|
{
|
|
165
165
|
"path": "dist/g2.lite.min.js",
|
|
166
|
-
"limit": "
|
|
166
|
+
"limit": "250 Kb",
|
|
167
167
|
"gzip": true
|
|
168
168
|
}
|
|
169
169
|
],
|
package/src/animation/growInX.ts
CHANGED
|
@@ -14,7 +14,7 @@ export const GrowInX: AC<GrowInXOptions> = (options, context) => {
|
|
|
14
14
|
const { height, width } = shape.getBoundingClientRect();
|
|
15
15
|
const clipPath = new Path({
|
|
16
16
|
style: {
|
|
17
|
-
|
|
17
|
+
d: `M0,0L${width},0L${width},${height}L0,${height}Z`,
|
|
18
18
|
},
|
|
19
19
|
});
|
|
20
20
|
shape.appendChild(clipPath);
|
package/src/animation/growInY.ts
CHANGED
|
@@ -14,7 +14,7 @@ export const GrowInY: AC<GrowInYOptions> = (options, context) => {
|
|
|
14
14
|
const { height, width } = shape.getBoundingClientRect();
|
|
15
15
|
const clipPath = new Path({
|
|
16
16
|
style: {
|
|
17
|
-
|
|
17
|
+
d: `M0,0L${width},0L${width},${height}L0,${height}Z`,
|
|
18
18
|
},
|
|
19
19
|
});
|
|
20
20
|
shape.appendChild(clipPath);
|
|
@@ -172,16 +172,18 @@ function oneToOne(
|
|
|
172
172
|
const pathShape = maybePath(shape, fromPath);
|
|
173
173
|
// Convert Path will take transform, anchor, etc into account,
|
|
174
174
|
// so there is no need to specify these attributes in keyframes.
|
|
175
|
-
const keyframes = [
|
|
175
|
+
const keyframes: Keyframe[] = [
|
|
176
176
|
{
|
|
177
|
-
path: fromPath,
|
|
178
177
|
...attributeOf(from, attributeKeys),
|
|
179
178
|
},
|
|
180
179
|
{
|
|
181
|
-
path: toPath,
|
|
182
180
|
...attributeOf(to, attributeKeys),
|
|
183
181
|
},
|
|
184
182
|
];
|
|
183
|
+
if (fromPath !== toPath) {
|
|
184
|
+
keyframes[0].d = fromPath;
|
|
185
|
+
keyframes[1].d = toPath;
|
|
186
|
+
}
|
|
185
187
|
const animation = pathShape.animate(keyframes, timeEffect);
|
|
186
188
|
|
|
187
189
|
animation.onfinish = () => {
|
|
@@ -207,7 +209,7 @@ function oneToMultiple(
|
|
|
207
209
|
return to.map((shape, i) => {
|
|
208
210
|
const path = new Path({
|
|
209
211
|
style: {
|
|
210
|
-
|
|
212
|
+
d: D[i],
|
|
211
213
|
...attributeOf(from, attributeKeys),
|
|
212
214
|
},
|
|
213
215
|
});
|
|
@@ -236,7 +238,7 @@ function multipleToOne(
|
|
|
236
238
|
const animations = from.map((shape, i) => {
|
|
237
239
|
const path = new Path({
|
|
238
240
|
style: {
|
|
239
|
-
|
|
241
|
+
d: D[i],
|
|
240
242
|
fill: to.style.fill,
|
|
241
243
|
},
|
|
242
244
|
});
|
|
@@ -51,7 +51,6 @@ export const ScaleInY: AC<ScaleInYOptions> = (options, context) => {
|
|
|
51
51
|
.cornerRadius(radius as number)
|
|
52
52
|
.padAngle((inset * Math.PI) / 180);
|
|
53
53
|
const pathForConversion = new Path({});
|
|
54
|
-
const center = coordinate.getCenter();
|
|
55
54
|
const createArcPath = (arcParams: {
|
|
56
55
|
startAngle: number;
|
|
57
56
|
endAngle: number;
|
|
@@ -60,10 +59,8 @@ export const ScaleInY: AC<ScaleInYOptions> = (options, context) => {
|
|
|
60
59
|
}) => {
|
|
61
60
|
pathForConversion.attr({
|
|
62
61
|
d: path(arcParams),
|
|
63
|
-
transform: `translate(${center[0]}, ${center[1]})`,
|
|
64
62
|
});
|
|
65
63
|
const convertedPathDefinition = convertToPath(pathForConversion);
|
|
66
|
-
pathForConversion.style.transform = '';
|
|
67
64
|
return convertedPathDefinition;
|
|
68
65
|
};
|
|
69
66
|
|
|
@@ -91,14 +88,14 @@ export const ScaleInY: AC<ScaleInYOptions> = (options, context) => {
|
|
|
91
88
|
|
|
92
89
|
const animation = shape.animate(keyframes, { ...defaults, ...options });
|
|
93
90
|
animation.onframe = function () {
|
|
94
|
-
shape.style.
|
|
91
|
+
shape.style.d = createArcPath({
|
|
95
92
|
...arcObject,
|
|
96
93
|
outerRadius: Number(shape.style.scaleInYRadius),
|
|
97
94
|
});
|
|
98
95
|
};
|
|
99
96
|
|
|
100
97
|
animation.onfinish = function () {
|
|
101
|
-
shape.style.
|
|
98
|
+
shape.style.d = createArcPath({
|
|
102
99
|
...arcObject,
|
|
103
100
|
outerRadius: outerRadius,
|
|
104
101
|
});
|
package/src/animation/waveIn.ts
CHANGED
|
@@ -63,7 +63,8 @@ export const WaveIn: AC<WaveInOptions> = (options, context) => {
|
|
|
63
63
|
transform: `translate(${center[0]}, ${center[1]})`,
|
|
64
64
|
});
|
|
65
65
|
const convertedPathDefinition = convertToPath(pathForConversion);
|
|
66
|
-
|
|
66
|
+
console.log(convertedPathDefinition);
|
|
67
|
+
// pathForConversion.style.transform = '';
|
|
67
68
|
return convertedPathDefinition;
|
|
68
69
|
};
|
|
69
70
|
|
package/src/api/utils.ts
CHANGED
|
@@ -76,9 +76,9 @@ export function valueOf(node: Node): Record<string, any> {
|
|
|
76
76
|
}
|
|
77
77
|
|
|
78
78
|
export function sizeOf(options, container) {
|
|
79
|
-
const { width
|
|
80
|
-
let effectiveWidth =
|
|
81
|
-
let effectiveHeight =
|
|
79
|
+
const { width, height, autoFit, depth = 0 } = options;
|
|
80
|
+
let effectiveWidth = 640;
|
|
81
|
+
let effectiveHeight = 480;
|
|
82
82
|
|
|
83
83
|
if (autoFit) {
|
|
84
84
|
const { width: containerWidth, height: containerHeight } =
|
|
@@ -87,6 +87,9 @@ export function sizeOf(options, container) {
|
|
|
87
87
|
effectiveHeight = containerHeight || effectiveHeight;
|
|
88
88
|
}
|
|
89
89
|
|
|
90
|
+
effectiveWidth = width || effectiveWidth;
|
|
91
|
+
effectiveHeight = height || effectiveHeight;
|
|
92
|
+
|
|
90
93
|
return {
|
|
91
94
|
width: Math.max(
|
|
92
95
|
isNumber(effectiveWidth) ? effectiveWidth : MIN_CHART_WIDTH,
|
|
@@ -133,25 +136,44 @@ function isMark(
|
|
|
133
136
|
return new Set(Object.keys(mark)).has(type);
|
|
134
137
|
}
|
|
135
138
|
|
|
139
|
+
function isComposition(
|
|
140
|
+
type: string | ((...args: any[]) => any),
|
|
141
|
+
composition: Record<string, new () => Node>,
|
|
142
|
+
): boolean {
|
|
143
|
+
return (
|
|
144
|
+
typeof type !== 'function' && new Set(Object.keys(composition)).has(type)
|
|
145
|
+
);
|
|
146
|
+
}
|
|
147
|
+
|
|
136
148
|
function normalizeRootOptions(
|
|
137
149
|
node: Node,
|
|
138
150
|
options: G2ViewTree,
|
|
139
151
|
previousType: string,
|
|
140
152
|
marks: Record<string, new () => Node>,
|
|
153
|
+
composition: Record<string, new () => Node>,
|
|
141
154
|
) {
|
|
142
155
|
const { type: oldType } = node;
|
|
143
156
|
const { type = previousType || oldType } = options;
|
|
144
|
-
if (type
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
157
|
+
if (isComposition(type, composition)) {
|
|
158
|
+
for (const key of VIEW_KEYS) {
|
|
159
|
+
if (node.attr(key) !== undefined && options[key] === undefined) {
|
|
160
|
+
options[key] = node.attr(key);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
return options;
|
|
164
|
+
}
|
|
165
|
+
if (isMark(type, marks)) {
|
|
166
|
+
const view = { type: 'view' };
|
|
167
|
+
const mark = { ...options };
|
|
168
|
+
for (const key of VIEW_KEYS) {
|
|
169
|
+
if (mark[key] !== undefined) {
|
|
170
|
+
view[key] = mark[key];
|
|
171
|
+
delete mark[key];
|
|
172
|
+
}
|
|
152
173
|
}
|
|
174
|
+
return { ...view, children: [mark] };
|
|
153
175
|
}
|
|
154
|
-
return
|
|
176
|
+
return options;
|
|
155
177
|
}
|
|
156
178
|
|
|
157
179
|
function typeCtor(
|
|
@@ -232,7 +254,13 @@ export function updateRoot(
|
|
|
232
254
|
mark: Record<string, new () => Node>,
|
|
233
255
|
composition: Record<string, new () => Node>,
|
|
234
256
|
) {
|
|
235
|
-
const rootOptions = normalizeRootOptions(
|
|
257
|
+
const rootOptions = normalizeRootOptions(
|
|
258
|
+
node,
|
|
259
|
+
options,
|
|
260
|
+
definedType,
|
|
261
|
+
mark,
|
|
262
|
+
composition,
|
|
263
|
+
);
|
|
236
264
|
const discovered: [Node, Node, G2ViewTree][] = [[null, node, rootOptions]];
|
|
237
265
|
while (discovered.length) {
|
|
238
266
|
const [parent, oldNode, newNode] = discovered.shift();
|
package/src/component/axis.ts
CHANGED
|
@@ -328,6 +328,7 @@ function inferAxisLinearOverrideStyle(
|
|
|
328
328
|
orientation: GCO,
|
|
329
329
|
bbox: BBox,
|
|
330
330
|
coordinate: Coordinate,
|
|
331
|
+
xScale: Scale,
|
|
331
332
|
): {
|
|
332
333
|
startPos?: [number, number];
|
|
333
334
|
endPos?: [number, number];
|
|
@@ -387,14 +388,23 @@ function inferAxisLinearOverrideStyle(
|
|
|
387
388
|
actualCy + innerR * sin,
|
|
388
389
|
];
|
|
389
390
|
|
|
391
|
+
const getAxisXDomainLength = () => {
|
|
392
|
+
const { domain } = xScale.getOptions();
|
|
393
|
+
return domain.length;
|
|
394
|
+
};
|
|
395
|
+
const controllAngleCount =
|
|
396
|
+
isPolar(coordinate) && xScale ? getAxisXDomainLength() : 3;
|
|
397
|
+
|
|
390
398
|
return {
|
|
391
399
|
startPos,
|
|
392
400
|
endPos,
|
|
393
|
-
gridClosed: endAngle - startAngle
|
|
401
|
+
gridClosed: Math.abs(endAngle - startAngle - 360) < 1e-6,
|
|
394
402
|
gridCenter: [actualCx, actualCy],
|
|
395
|
-
gridControlAngles: new Array(
|
|
403
|
+
gridControlAngles: new Array(controllAngleCount)
|
|
396
404
|
.fill(0)
|
|
397
|
-
.map(
|
|
405
|
+
.map(
|
|
406
|
+
(d, i, arr) => ((endAngle - startAngle) / controllAngleCount) * i,
|
|
407
|
+
),
|
|
398
408
|
};
|
|
399
409
|
}
|
|
400
410
|
}
|
|
@@ -547,11 +557,10 @@ const LinearAxisComponent: GCC<AxisOptions> = (options) => {
|
|
|
547
557
|
indexBBox,
|
|
548
558
|
...userDefinitions
|
|
549
559
|
} = options;
|
|
550
|
-
|
|
551
|
-
return ({ scales: [scale], value, coordinate, theme }) => {
|
|
560
|
+
return ({ scales, value, coordinate, theme }) => {
|
|
552
561
|
const { bbox } = value;
|
|
553
|
-
const
|
|
554
|
-
|
|
562
|
+
const [scale] = scales;
|
|
563
|
+
const { domain, xScale } = scale.getOptions();
|
|
555
564
|
const defaultStyle = inferDefaultStyle(
|
|
556
565
|
scale,
|
|
557
566
|
coordinate,
|
|
@@ -560,7 +569,6 @@ const LinearAxisComponent: GCC<AxisOptions> = (options) => {
|
|
|
560
569
|
position,
|
|
561
570
|
orientation,
|
|
562
571
|
);
|
|
563
|
-
|
|
564
572
|
const internalAxisStyle = {
|
|
565
573
|
...defaultStyle,
|
|
566
574
|
...style,
|
|
@@ -578,6 +586,7 @@ const LinearAxisComponent: GCC<AxisOptions> = (options) => {
|
|
|
578
586
|
orientation,
|
|
579
587
|
bbox,
|
|
580
588
|
coordinate,
|
|
589
|
+
xScale,
|
|
581
590
|
);
|
|
582
591
|
|
|
583
592
|
const threeDOverrideStyle = infer3DAxisLinearOverrideStyle(coordinate);
|
|
@@ -604,7 +613,6 @@ const LinearAxisComponent: GCC<AxisOptions> = (options) => {
|
|
|
604
613
|
return { ...d, bbox: bbox[1] };
|
|
605
614
|
})
|
|
606
615
|
: data;
|
|
607
|
-
|
|
608
616
|
const finalAxisStyle = {
|
|
609
617
|
...internalAxisStyle,
|
|
610
618
|
type: 'linear' as const,
|
|
@@ -654,7 +662,6 @@ const axisFactor: (
|
|
|
654
662
|
: useDefinedLabelFormatter;
|
|
655
663
|
const labelFilter = (datum: any, index: number, array: any[]) =>
|
|
656
664
|
userDefinedLabelFilter(ticks[index], index, ticks);
|
|
657
|
-
|
|
658
665
|
const normalizedOptions = {
|
|
659
666
|
...options,
|
|
660
667
|
labelFormatter,
|
package/src/component/title.ts
CHANGED
|
@@ -49,9 +49,13 @@ const Title = createComponent<TitleStyleProps>({
|
|
|
49
49
|
subtitle,
|
|
50
50
|
spacing = 2,
|
|
51
51
|
align = 'left',
|
|
52
|
+
x,
|
|
53
|
+
y,
|
|
52
54
|
...style
|
|
53
55
|
} = attributes;
|
|
54
56
|
|
|
57
|
+
container.style.transform = `translate(${x}, ${y})`;
|
|
58
|
+
|
|
55
59
|
const titleStyle = subObject(style, 'title');
|
|
56
60
|
const subtitleStyle = subObject(style, 'subtitle');
|
|
57
61
|
|
package/src/coordinate/polar.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { convertAngles } from '../utils/angle';
|
|
1
2
|
import { CoordinateComponent as CC } from '../runtime';
|
|
2
3
|
import { PolarCoordinate } from '../spec';
|
|
3
4
|
|
|
@@ -10,7 +11,11 @@ export const getPolarOptions = (options: PolarOptions = {}) => {
|
|
|
10
11
|
innerRadius: 0,
|
|
11
12
|
outerRadius: 1,
|
|
12
13
|
};
|
|
13
|
-
|
|
14
|
+
const polarOption = { ...defaultOptions, ...options };
|
|
15
|
+
return {
|
|
16
|
+
...polarOption,
|
|
17
|
+
...convertAngles(polarOption.startAngle, polarOption.endAngle),
|
|
18
|
+
};
|
|
14
19
|
};
|
|
15
20
|
/**
|
|
16
21
|
* Polar transformation for circular charts using center of canvas as origin.
|
package/src/interaction/event.ts
CHANGED
|
@@ -31,6 +31,11 @@ function maybeElementRoot(node) {
|
|
|
31
31
|
return maybeRoot(node, (node) => node.className === 'element');
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
+
// For extended label.
|
|
35
|
+
function maybeLabelRoot(node) {
|
|
36
|
+
return maybeRoot(node, (node) => node.className === 'label');
|
|
37
|
+
}
|
|
38
|
+
|
|
34
39
|
function bubblesEvent(eventType, view, emitter, predicate = (event) => true) {
|
|
35
40
|
return (e) => {
|
|
36
41
|
if (!predicate(e)) return;
|
|
@@ -52,19 +57,27 @@ function bubblesEvent(eventType, view, emitter, predicate = (event) => true) {
|
|
|
52
57
|
const elementRoot = maybeElementRoot(target);
|
|
53
58
|
// If target is component or child of component.
|
|
54
59
|
const componentRoot = maybeComponentRoot(target);
|
|
55
|
-
|
|
60
|
+
// If target is babel or child of babel.
|
|
61
|
+
const babelRoot = maybeLabelRoot(target);
|
|
62
|
+
|
|
63
|
+
const root = elementRoot || componentRoot || babelRoot;
|
|
64
|
+
|
|
56
65
|
if (!root) return;
|
|
57
66
|
const { className: elementType, markType } = root;
|
|
67
|
+
const e1 = {
|
|
68
|
+
...e,
|
|
69
|
+
nativeEvent: true,
|
|
70
|
+
};
|
|
58
71
|
if (elementType === 'element') {
|
|
59
|
-
|
|
60
|
-
...e,
|
|
61
|
-
nativeEvent: true,
|
|
62
|
-
data: { data: dataOf(root, view) },
|
|
63
|
-
};
|
|
72
|
+
e1['data'] = { data: dataOf(root, view) };
|
|
64
73
|
emitter.emit(`element:${eventType}`, e1);
|
|
65
74
|
emitter.emit(`${markType}:${eventType}`, e1);
|
|
75
|
+
} else if (elementType === 'label') {
|
|
76
|
+
//label children [Text2, Rect2, Path2],
|
|
77
|
+
e1['data'] = { data: root.attributes.datum };
|
|
78
|
+
emitter.emit(`label:${eventType}`, e1);
|
|
79
|
+
emitter.emit(`${className}:${eventType}`, e1);
|
|
66
80
|
} else {
|
|
67
|
-
const e1 = { ...e, nativeEvent: true };
|
|
68
81
|
emitter.emit(`component:${eventType}`, e1);
|
|
69
82
|
emitter.emit(`${className}:${eventType}`, e1);
|
|
70
83
|
}
|
package/src/interaction/index.ts
CHANGED
|
@@ -33,6 +33,14 @@ export function legendsContinuousOf(root) {
|
|
|
33
33
|
return root.getElementsByClassName(CONTINUOUS_LEGEND_CLASS_NAME);
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
+
export function legendClearSetState(root, setState) {
|
|
37
|
+
const legends = [...legendsOf(root), ...legendsContinuousOf(root)];
|
|
38
|
+
|
|
39
|
+
legends.forEach((legend) => {
|
|
40
|
+
setState(legend, (v) => v);
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
|
|
36
44
|
export function dataOf(root) {
|
|
37
45
|
// legend -> layout -> container
|
|
38
46
|
let parent = root.parentNode;
|
|
@@ -27,6 +27,10 @@ export function ScrollbarFilter(options: any = {}) {
|
|
|
27
27
|
prefix: 'scrollbar',
|
|
28
28
|
hasState: true,
|
|
29
29
|
setValue: (component, values) => component.setValue(values[0]),
|
|
30
|
+
getInitValues: (scrollbar) => {
|
|
31
|
+
const values = scrollbar.slider.attributes.values;
|
|
32
|
+
if (values[0] !== 0) return values;
|
|
33
|
+
},
|
|
30
34
|
});
|
|
31
35
|
return interaction(context, _, emitter);
|
|
32
36
|
};
|
|
@@ -74,6 +74,10 @@ export function SliderFilter({
|
|
|
74
74
|
wait = 50,
|
|
75
75
|
leading = true,
|
|
76
76
|
trailing = false,
|
|
77
|
+
getInitValues = (slider) => {
|
|
78
|
+
const values = slider?.attributes?.values;
|
|
79
|
+
if (values[0] !== 0 || values[1] !== 1) return values;
|
|
80
|
+
},
|
|
77
81
|
}: any) {
|
|
78
82
|
return (context, _, emitter) => {
|
|
79
83
|
const { container, view, update, setState } = context;
|
|
@@ -134,7 +138,8 @@ export function SliderFilter({
|
|
|
134
138
|
|
|
135
139
|
const onValueChange = throttle(
|
|
136
140
|
async (event) => {
|
|
137
|
-
|
|
141
|
+
const { initValue = false } = event;
|
|
142
|
+
if (filtering && !initValue) return;
|
|
138
143
|
filtering = true;
|
|
139
144
|
|
|
140
145
|
const { nativeEvent = true } = event;
|
|
@@ -205,6 +210,21 @@ export function SliderFilter({
|
|
|
205
210
|
slider.addEventListener('valuechange', onValueChange);
|
|
206
211
|
sliderHandler.set(slider, onValueChange);
|
|
207
212
|
emitHandlers.add([eventName, emitHandler]);
|
|
213
|
+
|
|
214
|
+
const values = getInitValues(slider);
|
|
215
|
+
|
|
216
|
+
if (values) {
|
|
217
|
+
// Init values.
|
|
218
|
+
slider.dispatchEvent(
|
|
219
|
+
new CustomEvent('valuechange', {
|
|
220
|
+
detail: {
|
|
221
|
+
value: values,
|
|
222
|
+
},
|
|
223
|
+
nativeEvent: false,
|
|
224
|
+
initValue: true,
|
|
225
|
+
}),
|
|
226
|
+
);
|
|
227
|
+
}
|
|
208
228
|
}
|
|
209
229
|
|
|
210
230
|
// Update to async state such as scale.
|
|
@@ -33,8 +33,8 @@ function getContainer(
|
|
|
33
33
|
return canvas.parentElement as unknown as HTMLElement;
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
function getBounding(root): BBox {
|
|
37
|
-
const bbox = root.
|
|
36
|
+
function getBounding(root: DisplayObject): BBox {
|
|
37
|
+
const bbox = root.getRenderBounds();
|
|
38
38
|
const {
|
|
39
39
|
min: [x1, y1],
|
|
40
40
|
max: [x2, y2],
|
|
@@ -381,7 +381,7 @@ function updateMarker(root, { data, style, theme }) {
|
|
|
381
381
|
fill,
|
|
382
382
|
r: 4,
|
|
383
383
|
stroke: '#fff',
|
|
384
|
-
|
|
384
|
+
lineWidth: 2,
|
|
385
385
|
...style,
|
|
386
386
|
},
|
|
387
387
|
});
|