@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,153 @@
|
|
|
1
|
+
import { isArray, get } from '@antv/util';
|
|
2
|
+
import {
|
|
3
|
+
stratify,
|
|
4
|
+
hierarchy,
|
|
5
|
+
treemap as treemapLayout,
|
|
6
|
+
treemapBinary,
|
|
7
|
+
treemapDice,
|
|
8
|
+
treemapSlice,
|
|
9
|
+
treemapSliceDice,
|
|
10
|
+
treemapSquarify,
|
|
11
|
+
treemapResquarify,
|
|
12
|
+
} from 'd3-hierarchy';
|
|
13
|
+
import type { Node } from 'd3-hierarchy';
|
|
14
|
+
import { field } from '../mark/utils';
|
|
15
|
+
|
|
16
|
+
type Layout = {
|
|
17
|
+
tile?:
|
|
18
|
+
| 'treemapBinary'
|
|
19
|
+
| 'treemapDice'
|
|
20
|
+
| 'treemapSlice'
|
|
21
|
+
| 'treemapSliceDice'
|
|
22
|
+
| 'treemapSquarify'
|
|
23
|
+
| 'treemapResquarify';
|
|
24
|
+
size?: [number, number];
|
|
25
|
+
round?: boolean;
|
|
26
|
+
// Ignore the value of the parent node when calculating the total value.
|
|
27
|
+
ignoreParentValue?: boolean;
|
|
28
|
+
ratio?: number;
|
|
29
|
+
padding?: number;
|
|
30
|
+
paddingInner?: number;
|
|
31
|
+
paddingOuter?: number;
|
|
32
|
+
paddingTop?: number;
|
|
33
|
+
paddingRight?: number;
|
|
34
|
+
paddingBottom?: number;
|
|
35
|
+
paddingLeft?: number;
|
|
36
|
+
sort?(a: any, b: any): number;
|
|
37
|
+
path?: (d: any) => any;
|
|
38
|
+
/** The granularity of Display layer. */
|
|
39
|
+
layer?: number | ((d: any) => any);
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* @description Path need when the data is a flat json structure,
|
|
44
|
+
* and the tree object structure do not need.
|
|
45
|
+
*/
|
|
46
|
+
function generateHierarchyRoot(
|
|
47
|
+
data: any[] | Record<string, any>,
|
|
48
|
+
path: (d: any) => any,
|
|
49
|
+
): Node {
|
|
50
|
+
if (Array.isArray(data)) {
|
|
51
|
+
return typeof path === 'function'
|
|
52
|
+
? stratify().path(path)(data)
|
|
53
|
+
: stratify()(data);
|
|
54
|
+
}
|
|
55
|
+
return hierarchy(data);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function addObjectDataPath(root: Node, path = [root.data.name]) {
|
|
59
|
+
root.id = root.id || root.data.name;
|
|
60
|
+
root.path = path;
|
|
61
|
+
|
|
62
|
+
if (root.children) {
|
|
63
|
+
root.children.forEach((item) => {
|
|
64
|
+
item.id = `${root.id}/${item.data.name}`;
|
|
65
|
+
item.path = [...path, item.data.name];
|
|
66
|
+
addObjectDataPath(item, item.path);
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function addArrayDataPath(root: Node) {
|
|
72
|
+
const name = get(root, ['data', 'name']);
|
|
73
|
+
if (name.replaceAll) {
|
|
74
|
+
root.path = name.replaceAll('.', '/').split('/');
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
if (root.children) {
|
|
78
|
+
root.children.forEach((item) => {
|
|
79
|
+
addArrayDataPath(item);
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function getTileMethod(tile: string, ratio: number) {
|
|
85
|
+
const tiles = {
|
|
86
|
+
treemapBinary,
|
|
87
|
+
treemapDice,
|
|
88
|
+
treemapSlice,
|
|
89
|
+
treemapSliceDice,
|
|
90
|
+
treemapSquarify,
|
|
91
|
+
treemapResquarify,
|
|
92
|
+
};
|
|
93
|
+
const tileMethod =
|
|
94
|
+
tile === 'treemapSquarify' ? tiles[tile].ratio(ratio) : tiles[tile];
|
|
95
|
+
if (!tileMethod) {
|
|
96
|
+
throw new TypeError('Invalid tile method!');
|
|
97
|
+
}
|
|
98
|
+
return tileMethod;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export function treeDataTransform(
|
|
102
|
+
data,
|
|
103
|
+
layout: Layout,
|
|
104
|
+
encode,
|
|
105
|
+
): [Node[], Node[]] {
|
|
106
|
+
const { value } = encode;
|
|
107
|
+
const tileMethod = getTileMethod(layout.tile, layout.ratio);
|
|
108
|
+
|
|
109
|
+
const root = generateHierarchyRoot(data, layout.path);
|
|
110
|
+
|
|
111
|
+
if (isArray(data)) {
|
|
112
|
+
addArrayDataPath(root);
|
|
113
|
+
} else {
|
|
114
|
+
addObjectDataPath(root);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// Calculate the value and sort.
|
|
118
|
+
value
|
|
119
|
+
? root
|
|
120
|
+
.sum((d) =>
|
|
121
|
+
layout.ignoreParentValue && d.children ? 0 : field(value)(d),
|
|
122
|
+
)
|
|
123
|
+
.sort(layout.sort)
|
|
124
|
+
: root.count();
|
|
125
|
+
|
|
126
|
+
treemapLayout()
|
|
127
|
+
.tile(tileMethod)
|
|
128
|
+
// @ts-ignore
|
|
129
|
+
.size(layout.size)
|
|
130
|
+
.round(layout.round)
|
|
131
|
+
.paddingInner(layout.paddingInner)
|
|
132
|
+
.paddingOuter(layout.paddingOuter)
|
|
133
|
+
.paddingTop(layout.paddingTop)
|
|
134
|
+
.paddingRight(layout.paddingRight)
|
|
135
|
+
.paddingBottom(layout.paddingBottom)
|
|
136
|
+
.paddingLeft(layout.paddingLeft)(root);
|
|
137
|
+
|
|
138
|
+
const nodes = root.descendants().map((d) =>
|
|
139
|
+
Object.assign(d, {
|
|
140
|
+
id: d.id.replace(/^\//, ''),
|
|
141
|
+
x: [d.x0, d.x1],
|
|
142
|
+
y: [d.y0, d.y1],
|
|
143
|
+
}),
|
|
144
|
+
);
|
|
145
|
+
|
|
146
|
+
const filterData = nodes.filter(
|
|
147
|
+
typeof layout.layer === 'function'
|
|
148
|
+
? layout.layer
|
|
149
|
+
: (d) => d.height === layout.layer,
|
|
150
|
+
);
|
|
151
|
+
|
|
152
|
+
return [filterData, nodes];
|
|
153
|
+
}
|