@antv/hierarchy 0.6.13 → 0.7.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/README.md +51 -3
- package/dist/hierarchy.es.js +2 -0
- package/dist/hierarchy.es.js.map +1 -0
- package/dist/hierarchy.umd.js +2 -0
- package/dist/hierarchy.umd.js.map +1 -0
- package/lib/compact-box.d.ts +3 -0
- package/lib/compact-box.d.ts.map +1 -0
- package/lib/dendrogram.d.ts +3 -0
- package/lib/dendrogram.d.ts.map +1 -0
- package/lib/indented.d.ts +3 -0
- package/lib/indented.d.ts.map +1 -0
- package/lib/index.d.ts +15 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/layout/base.d.ts +8 -0
- package/lib/layout/base.d.ts.map +1 -0
- package/lib/layout/dendrogram.d.ts +3 -0
- package/lib/layout/dendrogram.d.ts.map +1 -0
- package/lib/layout/do-layout.d.ts +5 -0
- package/lib/layout/do-layout.d.ts.map +1 -0
- package/lib/layout/hierarchy.d.ts +3 -0
- package/lib/layout/hierarchy.d.ts.map +1 -0
- package/lib/layout/indented.d.ts +3 -0
- package/lib/layout/indented.d.ts.map +1 -0
- package/lib/layout/mindmap.d.ts +3 -0
- package/lib/layout/mindmap.d.ts.map +1 -0
- package/lib/layout/non-layered-tidy.d.ts +3 -0
- package/lib/layout/non-layered-tidy.d.ts.map +1 -0
- package/lib/layout/separate-root.d.ts +6 -0
- package/lib/layout/separate-root.d.ts.map +1 -0
- package/lib/mindmap.d.ts +3 -0
- package/lib/mindmap.d.ts.map +1 -0
- package/lib/types.d.ts +90 -0
- package/lib/types.d.ts.map +1 -0
- package/lib/util.d.ts +17 -0
- package/lib/util.d.ts.map +1 -0
- package/package.json +48 -53
- package/.babelrc +0 -14
- package/.editorconfig +0 -20
- package/.eslintignore +0 -7
- package/.eslintrc +0 -28
- package/.github/workflows/build.yml +0 -32
- package/CHANGELOG.md +0 -0
- package/CONTRIBUTING.md +0 -142
- package/CONTRIBUTING.zh-CN.md +0 -148
- package/assets/compact-box-bt.png +0 -0
- package/assets/compact-box-h.png +0 -0
- package/assets/compact-box-lr.png +0 -0
- package/assets/compact-box-rl.png +0 -0
- package/assets/compact-box-tb.png +0 -0
- package/assets/compact-box-v.png +0 -0
- package/assets/dendrogram-bt.png +0 -0
- package/assets/dendrogram-h.png +0 -0
- package/assets/dendrogram-lr.png +0 -0
- package/assets/dendrogram-rl.png +0 -0
- package/assets/dendrogram-tb.png +0 -0
- package/assets/dendrogram-v.png +0 -0
- package/assets/indented-h.png +0 -0
- package/assets/indented-lr.png +0 -0
- package/assets/indented-rl.png +0 -0
- package/assets/layered-tidy-bt.png +0 -0
- package/assets/layered-tidy-h.png +0 -0
- package/assets/layered-tidy-lr.png +0 -0
- package/assets/layered-tidy-rl.png +0 -0
- package/assets/layered-tidy-tb.png +0 -0
- package/assets/layered-tidy-v.png +0 -0
- package/assets/mindmap.png +0 -0
- package/bin/mkdir-dist.js +0 -8
- package/bin/screenshot.js +0 -81
- package/bin/win-dev.js +0 -14
- package/build/hierarchy.js +0 -1131
- package/build/hierarchy.js.map +0 -1
- package/dist/hierarchy.min.js +0 -1
- package/lib/compact-box.js +0 -24
- package/lib/dendrogram.js +0 -25
- package/lib/indented.js +0 -65
- package/lib/index.js +0 -7
- package/lib/layout/base.js +0 -17
- package/lib/layout/dendrogram.js +0 -108
- package/lib/layout/do-layout.js +0 -107
- package/lib/layout/hierarchy.js +0 -184
- package/lib/layout/indented.js +0 -36
- package/lib/layout/mindmap.js +0 -92
- package/lib/layout/non-layered-tidy.js +0 -236
- package/lib/layout/separate-root.js +0 -39
- package/lib/mindmap.js +0 -24
- package/lib/util.js +0 -18
- package/src/compact-box.js +0 -21
- package/src/dendrogram.js +0 -22
- package/src/indented.js +0 -52
- package/src/index.js +0 -9
- package/src/layout/base.js +0 -16
- package/src/layout/dendrogram.js +0 -105
- package/src/layout/do-layout.js +0 -106
- package/src/layout/hierarchy.js +0 -187
- package/src/layout/indented.js +0 -40
- package/src/layout/mindmap.js +0 -93
- package/src/layout/non-layered-tidy.js +0 -250
- package/src/layout/separate-root.js +0 -40
- package/src/mindmap.js +0 -21
- package/src/util.js +0 -16
|
@@ -1,250 +0,0 @@
|
|
|
1
|
-
// wrap tree node
|
|
2
|
-
function WrappedTree(w, h, y, c = []) {
|
|
3
|
-
const me = this;
|
|
4
|
-
// size
|
|
5
|
-
me.w = w || 0;
|
|
6
|
-
me.h = h || 0;
|
|
7
|
-
|
|
8
|
-
// position
|
|
9
|
-
me.y = y || 0;
|
|
10
|
-
me.x = 0;
|
|
11
|
-
|
|
12
|
-
// children
|
|
13
|
-
me.c = c || [];
|
|
14
|
-
me.cs = c.length;
|
|
15
|
-
|
|
16
|
-
// modified
|
|
17
|
-
me.prelim = 0;
|
|
18
|
-
me.mod = 0;
|
|
19
|
-
me.shift = 0;
|
|
20
|
-
me.change = 0;
|
|
21
|
-
|
|
22
|
-
// left/right tree
|
|
23
|
-
me.tl = null;
|
|
24
|
-
me.tr = null;
|
|
25
|
-
|
|
26
|
-
// extreme left/right tree
|
|
27
|
-
me.el = null;
|
|
28
|
-
me.er = null;
|
|
29
|
-
|
|
30
|
-
// modified left/right tree
|
|
31
|
-
me.msel = 0;
|
|
32
|
-
me.mser = 0;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
WrappedTree.fromNode = (root, isHorizontal) => {
|
|
36
|
-
if (!root) return null;
|
|
37
|
-
const children = [];
|
|
38
|
-
root.children.forEach(child => {
|
|
39
|
-
children.push(WrappedTree.fromNode(child, isHorizontal));
|
|
40
|
-
});
|
|
41
|
-
if (isHorizontal) return new WrappedTree(root.height, root.width, root.x, children);
|
|
42
|
-
return new WrappedTree(root.width, root.height, root.y, children);
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
// node utils
|
|
46
|
-
function moveRight(node, move, isHorizontal) {
|
|
47
|
-
if (isHorizontal) {
|
|
48
|
-
node.y += move;
|
|
49
|
-
} else {
|
|
50
|
-
node.x += move;
|
|
51
|
-
}
|
|
52
|
-
node.children.forEach(child => {
|
|
53
|
-
moveRight(child, move, isHorizontal);
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
function getMin(node, isHorizontal) {
|
|
58
|
-
let res = isHorizontal ? node.y : node.x;
|
|
59
|
-
node.children.forEach(child => {
|
|
60
|
-
res = Math.min(getMin(child, isHorizontal), res);
|
|
61
|
-
});
|
|
62
|
-
return res;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
function normalize(node, isHorizontal) {
|
|
66
|
-
const min = getMin(node, isHorizontal);
|
|
67
|
-
moveRight(node, -min, isHorizontal);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
function convertBack(converted/* WrappedTree */, root/* TreeNode */, isHorizontal) {
|
|
71
|
-
if (isHorizontal) {
|
|
72
|
-
root.y = converted.x;
|
|
73
|
-
} else {
|
|
74
|
-
root.x = converted.x;
|
|
75
|
-
}
|
|
76
|
-
converted.c.forEach((child, i) => {
|
|
77
|
-
convertBack(child, root.children[i], isHorizontal);
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
function layer(node, isHorizontal, d = 0) {
|
|
82
|
-
if (isHorizontal) {
|
|
83
|
-
node.x = d;
|
|
84
|
-
d += node.width;
|
|
85
|
-
} else {
|
|
86
|
-
node.y = d;
|
|
87
|
-
d += node.height;
|
|
88
|
-
}
|
|
89
|
-
node.children.forEach(child => {
|
|
90
|
-
layer(child, isHorizontal, d);
|
|
91
|
-
});
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
module.exports = (root, options = {}) => {
|
|
95
|
-
const isHorizontal = options.isHorizontal;
|
|
96
|
-
function firstWalk(t) {
|
|
97
|
-
if (t.cs === 0) {
|
|
98
|
-
setExtremes(t);
|
|
99
|
-
return;
|
|
100
|
-
}
|
|
101
|
-
firstWalk(t.c[0]);
|
|
102
|
-
let ih = updateIYL(bottom(t.c[0].el), 0, null);
|
|
103
|
-
for (let i = 1; i < t.cs; ++i) {
|
|
104
|
-
firstWalk(t.c[i]);
|
|
105
|
-
const min = bottom(t.c[i].er);
|
|
106
|
-
separate(t, i, ih);
|
|
107
|
-
ih = updateIYL(min, i, ih);
|
|
108
|
-
}
|
|
109
|
-
positionRoot(t);
|
|
110
|
-
setExtremes(t);
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
function setExtremes(t) {
|
|
114
|
-
if (t.cs === 0) {
|
|
115
|
-
t.el = t;
|
|
116
|
-
t.er = t;
|
|
117
|
-
t.msel = t.mser = 0;
|
|
118
|
-
} else {
|
|
119
|
-
t.el = t.c[0].el;
|
|
120
|
-
t.msel = t.c[0].msel;
|
|
121
|
-
t.er = t.c[t.cs - 1].er;
|
|
122
|
-
t.mser = t.c[t.cs - 1].mser;
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
function separate(t, i, ih) {
|
|
127
|
-
let sr = t.c[i - 1];
|
|
128
|
-
let mssr = sr.mod;
|
|
129
|
-
let cl = t.c[i];
|
|
130
|
-
let mscl = cl.mod;
|
|
131
|
-
while (sr !== null && cl !== null) {
|
|
132
|
-
if (bottom(sr) > ih.low) ih = ih.nxt;
|
|
133
|
-
const dist = (mssr + sr.prelim + sr.w) - (mscl + cl.prelim);
|
|
134
|
-
if (dist > 0) {
|
|
135
|
-
mscl += dist;
|
|
136
|
-
moveSubtree(t, i, ih.index, dist);
|
|
137
|
-
}
|
|
138
|
-
const sy = bottom(sr);
|
|
139
|
-
const cy = bottom(cl);
|
|
140
|
-
if (sy <= cy) {
|
|
141
|
-
sr = nextRightContour(sr);
|
|
142
|
-
if (sr !== null) mssr += sr.mod;
|
|
143
|
-
}
|
|
144
|
-
if (sy >= cy) {
|
|
145
|
-
cl = nextLeftContour(cl);
|
|
146
|
-
if (cl !== null) mscl += cl.mod;
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
if (!sr && !!cl) {
|
|
150
|
-
setLeftThread(t, i, cl, mscl);
|
|
151
|
-
} else if (!!sr && !cl) {
|
|
152
|
-
setRightThread(t, i, sr, mssr);
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
function moveSubtree(t, i, si, dist) {
|
|
157
|
-
t.c[i].mod += dist;
|
|
158
|
-
t.c[i].msel += dist;
|
|
159
|
-
t.c[i].mser += dist;
|
|
160
|
-
distributeExtra(t, i, si, dist);
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
function nextLeftContour(t) {
|
|
164
|
-
return t.cs === 0 ? t.tl : t.c[0];
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
function nextRightContour(t) {
|
|
168
|
-
return t.cs === 0 ? t.tr : t.c[t.cs - 1];
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
function bottom(t) {
|
|
172
|
-
return t.y + t.h;
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
function setLeftThread(t, i, cl, modsumcl) {
|
|
176
|
-
const li = t.c[0].el;
|
|
177
|
-
li.tl = cl;
|
|
178
|
-
const diff = (modsumcl - cl.mod) - t.c[0].msel;
|
|
179
|
-
li.mod += diff;
|
|
180
|
-
li.prelim -= diff;
|
|
181
|
-
t.c[0].el = t.c[i].el;
|
|
182
|
-
t.c[0].msel = t.c[i].msel;
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
function setRightThread(t, i, sr, modsumsr) {
|
|
186
|
-
const ri = t.c[i].er;
|
|
187
|
-
ri.tr = sr;
|
|
188
|
-
const diff = (modsumsr - sr.mod) - t.c[i].mser;
|
|
189
|
-
ri.mod += diff;
|
|
190
|
-
ri.prelim -= diff;
|
|
191
|
-
t.c[i].er = t.c[i - 1].er;
|
|
192
|
-
t.c[i].mser = t.c[i - 1].mser;
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
function positionRoot(t) {
|
|
196
|
-
t.prelim = (
|
|
197
|
-
t.c[0].prelim + t.c[0].mod + t.c[t.cs - 1].mod +
|
|
198
|
-
t.c[t.cs - 1].prelim + t.c[t.cs - 1].w
|
|
199
|
-
) / 2 - t.w / 2;
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
function secondWalk(t, modsum) {
|
|
203
|
-
modsum += t.mod;
|
|
204
|
-
t.x = t.prelim + modsum;
|
|
205
|
-
addChildSpacing(t);
|
|
206
|
-
for (let i = 0; i < t.cs; i++) {
|
|
207
|
-
secondWalk(t.c[i], modsum);
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
function distributeExtra(t, i, si, dist) {
|
|
212
|
-
if (si !== i - 1) {
|
|
213
|
-
const nr = i - si;
|
|
214
|
-
t.c[si + 1].shift += dist / nr;
|
|
215
|
-
t.c[i].shift -= dist / nr;
|
|
216
|
-
t.c[i].change -= dist - dist / nr;
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
function addChildSpacing(t) {
|
|
221
|
-
let d = 0;
|
|
222
|
-
let modsumdelta = 0;
|
|
223
|
-
for (let i = 0; i < t.cs; i++) {
|
|
224
|
-
d += t.c[i].shift;
|
|
225
|
-
modsumdelta += d + t.c[i].change;
|
|
226
|
-
t.c[i].mod += modsumdelta;
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
function updateIYL(low, index, ih) {
|
|
231
|
-
while (ih !== null && low >= ih.low) {
|
|
232
|
-
ih = ih.nxt;
|
|
233
|
-
}
|
|
234
|
-
return {
|
|
235
|
-
low,
|
|
236
|
-
index,
|
|
237
|
-
nxt: ih
|
|
238
|
-
};
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
// do layout
|
|
242
|
-
layer(root, isHorizontal);
|
|
243
|
-
const wt = WrappedTree.fromNode(root, isHorizontal);
|
|
244
|
-
firstWalk(wt);
|
|
245
|
-
secondWalk(wt, 0);
|
|
246
|
-
convertBack(wt, root, isHorizontal);
|
|
247
|
-
normalize(root, isHorizontal);
|
|
248
|
-
|
|
249
|
-
return root;
|
|
250
|
-
};
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
const hierarchy = require('./hierarchy');
|
|
2
|
-
|
|
3
|
-
module.exports = (root, options) => {
|
|
4
|
-
// separate into left and right trees
|
|
5
|
-
const left = hierarchy(root.data, options, true); // root only
|
|
6
|
-
const right = hierarchy(root.data, options, true); // root only
|
|
7
|
-
// automatically
|
|
8
|
-
const treeSize = root.children.length;
|
|
9
|
-
const rightTreeSize = Math.round(treeSize / 2);
|
|
10
|
-
// separate left and right tree by meta data
|
|
11
|
-
const getSide = options.getSide || function(child, index) {
|
|
12
|
-
if (index < rightTreeSize) {
|
|
13
|
-
return 'right';
|
|
14
|
-
}
|
|
15
|
-
return 'left';
|
|
16
|
-
};
|
|
17
|
-
for (let i = 0; i < treeSize; i++) {
|
|
18
|
-
const child = root.children[i];
|
|
19
|
-
const side = getSide(child, i);
|
|
20
|
-
if (side === 'right') {
|
|
21
|
-
right.children.push(child);
|
|
22
|
-
} else {
|
|
23
|
-
left.children.push(child);
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
left.eachNode(node => {
|
|
27
|
-
if (!node.isRoot()) {
|
|
28
|
-
node.side = 'left';
|
|
29
|
-
}
|
|
30
|
-
});
|
|
31
|
-
right.eachNode(node => {
|
|
32
|
-
if (!node.isRoot()) {
|
|
33
|
-
node.side = 'right';
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
return {
|
|
37
|
-
left,
|
|
38
|
-
right
|
|
39
|
-
};
|
|
40
|
-
};
|
package/src/mindmap.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
const TreeLayout = require('./layout/base');
|
|
2
|
-
const mindmap = require('./layout/mindmap');
|
|
3
|
-
const doTreeLayout = require('./layout/do-layout');
|
|
4
|
-
const util = require('./util');
|
|
5
|
-
|
|
6
|
-
class MindmapLayout extends TreeLayout {
|
|
7
|
-
execute() {
|
|
8
|
-
const me = this;
|
|
9
|
-
return doTreeLayout(me.rootNode, me.options, mindmap);
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
const DEFAULT_OPTIONS = {
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
function mindmapLayout(root, options) {
|
|
17
|
-
options = util.assign({}, DEFAULT_OPTIONS, options);
|
|
18
|
-
return new MindmapLayout(root, options).execute();
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
module.exports = mindmapLayout;
|
package/src/util.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Get average height or height for node's position calculation, according to align.
|
|
3
|
-
* @param {*} preNode previous node
|
|
4
|
-
* @param {*} node current node, whose position is going to be calculated
|
|
5
|
-
* @param {'center' | undefined} align 'center' means nodes align at the center, other value means align at the left-top
|
|
6
|
-
* @param {string} heightField field name for height value on preNode and node
|
|
7
|
-
* @return {number} the height for calculation
|
|
8
|
-
*/
|
|
9
|
-
function getHeight(preNode, node, align, heightField = 'height') {
|
|
10
|
-
return align === 'center' ? (preNode[heightField] + node[heightField]) / 2 : preNode.height;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
module.exports = {
|
|
14
|
-
assign: Object.assign,
|
|
15
|
-
getHeight
|
|
16
|
-
};
|