@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.
Files changed (100) hide show
  1. package/README.md +51 -3
  2. package/dist/hierarchy.es.js +2 -0
  3. package/dist/hierarchy.es.js.map +1 -0
  4. package/dist/hierarchy.umd.js +2 -0
  5. package/dist/hierarchy.umd.js.map +1 -0
  6. package/lib/compact-box.d.ts +3 -0
  7. package/lib/compact-box.d.ts.map +1 -0
  8. package/lib/dendrogram.d.ts +3 -0
  9. package/lib/dendrogram.d.ts.map +1 -0
  10. package/lib/indented.d.ts +3 -0
  11. package/lib/indented.d.ts.map +1 -0
  12. package/lib/index.d.ts +15 -0
  13. package/lib/index.d.ts.map +1 -0
  14. package/lib/layout/base.d.ts +8 -0
  15. package/lib/layout/base.d.ts.map +1 -0
  16. package/lib/layout/dendrogram.d.ts +3 -0
  17. package/lib/layout/dendrogram.d.ts.map +1 -0
  18. package/lib/layout/do-layout.d.ts +5 -0
  19. package/lib/layout/do-layout.d.ts.map +1 -0
  20. package/lib/layout/hierarchy.d.ts +3 -0
  21. package/lib/layout/hierarchy.d.ts.map +1 -0
  22. package/lib/layout/indented.d.ts +3 -0
  23. package/lib/layout/indented.d.ts.map +1 -0
  24. package/lib/layout/mindmap.d.ts +3 -0
  25. package/lib/layout/mindmap.d.ts.map +1 -0
  26. package/lib/layout/non-layered-tidy.d.ts +3 -0
  27. package/lib/layout/non-layered-tidy.d.ts.map +1 -0
  28. package/lib/layout/separate-root.d.ts +6 -0
  29. package/lib/layout/separate-root.d.ts.map +1 -0
  30. package/lib/mindmap.d.ts +3 -0
  31. package/lib/mindmap.d.ts.map +1 -0
  32. package/lib/types.d.ts +90 -0
  33. package/lib/types.d.ts.map +1 -0
  34. package/lib/util.d.ts +17 -0
  35. package/lib/util.d.ts.map +1 -0
  36. package/package.json +48 -53
  37. package/.babelrc +0 -14
  38. package/.editorconfig +0 -20
  39. package/.eslintignore +0 -7
  40. package/.eslintrc +0 -28
  41. package/.github/workflows/build.yml +0 -32
  42. package/CHANGELOG.md +0 -0
  43. package/CONTRIBUTING.md +0 -142
  44. package/CONTRIBUTING.zh-CN.md +0 -148
  45. package/assets/compact-box-bt.png +0 -0
  46. package/assets/compact-box-h.png +0 -0
  47. package/assets/compact-box-lr.png +0 -0
  48. package/assets/compact-box-rl.png +0 -0
  49. package/assets/compact-box-tb.png +0 -0
  50. package/assets/compact-box-v.png +0 -0
  51. package/assets/dendrogram-bt.png +0 -0
  52. package/assets/dendrogram-h.png +0 -0
  53. package/assets/dendrogram-lr.png +0 -0
  54. package/assets/dendrogram-rl.png +0 -0
  55. package/assets/dendrogram-tb.png +0 -0
  56. package/assets/dendrogram-v.png +0 -0
  57. package/assets/indented-h.png +0 -0
  58. package/assets/indented-lr.png +0 -0
  59. package/assets/indented-rl.png +0 -0
  60. package/assets/layered-tidy-bt.png +0 -0
  61. package/assets/layered-tidy-h.png +0 -0
  62. package/assets/layered-tidy-lr.png +0 -0
  63. package/assets/layered-tidy-rl.png +0 -0
  64. package/assets/layered-tidy-tb.png +0 -0
  65. package/assets/layered-tidy-v.png +0 -0
  66. package/assets/mindmap.png +0 -0
  67. package/bin/mkdir-dist.js +0 -8
  68. package/bin/screenshot.js +0 -81
  69. package/bin/win-dev.js +0 -14
  70. package/build/hierarchy.js +0 -1131
  71. package/build/hierarchy.js.map +0 -1
  72. package/dist/hierarchy.min.js +0 -1
  73. package/lib/compact-box.js +0 -24
  74. package/lib/dendrogram.js +0 -25
  75. package/lib/indented.js +0 -65
  76. package/lib/index.js +0 -7
  77. package/lib/layout/base.js +0 -17
  78. package/lib/layout/dendrogram.js +0 -108
  79. package/lib/layout/do-layout.js +0 -107
  80. package/lib/layout/hierarchy.js +0 -184
  81. package/lib/layout/indented.js +0 -36
  82. package/lib/layout/mindmap.js +0 -92
  83. package/lib/layout/non-layered-tidy.js +0 -236
  84. package/lib/layout/separate-root.js +0 -39
  85. package/lib/mindmap.js +0 -24
  86. package/lib/util.js +0 -18
  87. package/src/compact-box.js +0 -21
  88. package/src/dendrogram.js +0 -22
  89. package/src/indented.js +0 -52
  90. package/src/index.js +0 -9
  91. package/src/layout/base.js +0 -16
  92. package/src/layout/dendrogram.js +0 -105
  93. package/src/layout/do-layout.js +0 -106
  94. package/src/layout/hierarchy.js +0 -187
  95. package/src/layout/indented.js +0 -40
  96. package/src/layout/mindmap.js +0 -93
  97. package/src/layout/non-layered-tidy.js +0 -250
  98. package/src/layout/separate-root.js +0 -40
  99. package/src/mindmap.js +0 -21
  100. package/src/util.js +0 -16
@@ -1,184 +0,0 @@
1
- /* eslint-disable no-cond-assign */
2
- var util = require('../util');
3
- var PEM = 18;
4
- var DEFAULT_HEIGHT = PEM * 2;
5
- var DEFAULT_GAP = PEM;
6
- var DEFAULT_OPTIONS = {
7
- getId: function getId(d) {
8
- return d.id || d.name;
9
- },
10
- getPreH: function getPreH(d) {
11
- return d.preH || 0;
12
- },
13
- getPreV: function getPreV(d) {
14
- return d.preV || 0;
15
- },
16
- getHGap: function getHGap(d) {
17
- return d.hgap || DEFAULT_GAP;
18
- },
19
- getVGap: function getVGap(d) {
20
- return d.vgap || DEFAULT_GAP;
21
- },
22
- getChildren: function getChildren(d) {
23
- return d.children;
24
- },
25
- getHeight: function getHeight(d) {
26
- return d.height || DEFAULT_HEIGHT;
27
- },
28
- getWidth: function getWidth(d) {
29
- var label = d.label || ' ';
30
- return d.width || label.split('').length * PEM; // FIXME DO NOT get width like this
31
- }
32
- };
33
- function Node(data, options) {
34
- var me = this;
35
- me.vgap = me.hgap = 0;
36
- if (data instanceof Node) return data;
37
- me.data = data;
38
- /*
39
- * Gaps: filling space between nodes
40
- * (x, y) ----------------------
41
- * | vgap |
42
- * | -------------------- h
43
- * | h | | e
44
- * | g | | i
45
- * | a | | g
46
- * | p | | h
47
- * | --------------------- t
48
- * | |
49
- * -----------width------------
50
- */
51
- var hgap = options.getHGap(data);
52
- var vgap = options.getVGap(data);
53
- me.preH = options.getPreH(data);
54
- me.preV = options.getPreV(data);
55
- me.width = options.getWidth(data);
56
- me.height = options.getHeight(data);
57
- me.width += me.preH;
58
- me.height += me.preV;
59
- me.id = options.getId(data);
60
- me.x = me.y = 0;
61
- me.depth = 0;
62
- if (!me.children) {
63
- me.children = [];
64
- }
65
- me.addGap(hgap, vgap);
66
- return me;
67
- }
68
- util.assign(Node.prototype, {
69
- isRoot: function isRoot() {
70
- return this.depth === 0;
71
- },
72
- isLeaf: function isLeaf() {
73
- return this.children.length === 0;
74
- },
75
- addGap: function addGap(hgap, vgap) {
76
- var me = this;
77
- me.hgap += hgap;
78
- me.vgap += vgap;
79
- me.width += 2 * hgap;
80
- me.height += 2 * vgap;
81
- },
82
- eachNode: function eachNode(callback) {
83
- // Depth First traverse
84
- var me = this;
85
- var nodes = [me];
86
- var current;
87
- while (current = nodes.shift()) {
88
- callback(current);
89
- nodes = current.children.concat(nodes);
90
- }
91
- },
92
- DFTraverse: function DFTraverse(callback) {
93
- // Depth First traverse
94
- this.eachNode(callback);
95
- },
96
- BFTraverse: function BFTraverse(callback) {
97
- // Breadth First traverse
98
- var me = this;
99
- var nodes = [me];
100
- var current;
101
- while (current = nodes.shift()) {
102
- callback(current);
103
- nodes = nodes.concat(current.children);
104
- }
105
- },
106
- getBoundingBox: function getBoundingBox() {
107
- // BBox for just one tree node
108
- var bb = {
109
- left: Number.MAX_VALUE,
110
- top: Number.MAX_VALUE,
111
- width: 0,
112
- height: 0
113
- };
114
- this.eachNode(function (node) {
115
- bb.left = Math.min(bb.left, node.x);
116
- bb.top = Math.min(bb.top, node.y);
117
- bb.width = Math.max(bb.width, node.x + node.width);
118
- bb.height = Math.max(bb.height, node.y + node.height);
119
- });
120
- return bb;
121
- },
122
- // translate
123
- translate: function translate(tx, ty) {
124
- if (tx === void 0) {
125
- tx = 0;
126
- }
127
- if (ty === void 0) {
128
- ty = 0;
129
- }
130
- this.eachNode(function (node) {
131
- node.x += tx;
132
- node.y += ty;
133
- node.x += node.preH;
134
- node.y += node.preV;
135
- });
136
- },
137
- right2left: function right2left() {
138
- var me = this;
139
- var bb = me.getBoundingBox();
140
- me.eachNode(function (node) {
141
- node.x = node.x - (node.x - bb.left) * 2 - node.width;
142
- // node.x = - node.x;
143
- });
144
- me.translate(bb.width, 0);
145
- },
146
- bottom2top: function bottom2top() {
147
- var me = this;
148
- var bb = me.getBoundingBox();
149
- me.eachNode(function (node) {
150
- node.y = node.y - (node.y - bb.top) * 2 - node.height;
151
- // node.y = - node.y;
152
- });
153
- me.translate(0, bb.height);
154
- }
155
- });
156
- function hierarchy(data, options, isolated) {
157
- if (options === void 0) {
158
- options = {};
159
- }
160
- options = util.assign({}, DEFAULT_OPTIONS, options);
161
- var root = new Node(data, options);
162
- var nodes = [root];
163
- var node;
164
- if (!isolated && !data.collapsed) {
165
- while (node = nodes.shift()) {
166
- if (!node.data.collapsed) {
167
- var children = options.getChildren(node.data);
168
- var length = children ? children.length : 0;
169
- node.children = new Array(length);
170
- if (children && length) {
171
- for (var i = 0; i < length; i++) {
172
- var child = new Node(children[i], options);
173
- node.children[i] = child;
174
- nodes.push(child);
175
- child.parent = node;
176
- child.depth = node.depth + 1;
177
- }
178
- }
179
- }
180
- }
181
- }
182
- return root;
183
- }
184
- module.exports = hierarchy;
@@ -1,36 +0,0 @@
1
- var util = require("../util");
2
- function positionNode(node, previousNode, indent, dropCap, align) {
3
- // caculate the node's horizontal offset DX, dx's type might be number or function
4
- var displacementX = typeof indent === "function" ? indent(node) : indent * node.depth;
5
- if (!dropCap) {
6
- try {
7
- if (node.id === node.parent.children[0].id) {
8
- node.x += displacementX;
9
- node.y = previousNode ? previousNode.y : 0;
10
- return;
11
- }
12
- } catch (e) {
13
- // skip to normal when a node has no parent
14
- }
15
- }
16
- node.x += displacementX;
17
- if (previousNode) {
18
- node.y = previousNode.y + util.getHeight(previousNode, node, align);
19
- if (previousNode.parent && node.parent.id !== previousNode.parent.id) {
20
- // previous node has different parent
21
- var prevParent = previousNode.parent;
22
- var preY = prevParent.y + util.getHeight(prevParent, node, align);
23
- node.y = preY > node.y ? preY : node.y;
24
- }
25
- } else {
26
- node.y = 0;
27
- }
28
- return;
29
- }
30
- module.exports = function (root, indent, dropCap, align) {
31
- var previousNode = null;
32
- root.eachNode(function (node) {
33
- positionNode(node, previousNode, indent, dropCap, align);
34
- previousNode = node;
35
- });
36
- };
@@ -1,92 +0,0 @@
1
- var util = require('../util');
2
- function secondWalk(node, options) {
3
- var totalHeight = 0;
4
- if (!node.children.length) {
5
- totalHeight = node.height;
6
- } else {
7
- node.children.forEach(function (c) {
8
- totalHeight += secondWalk(c, options);
9
- });
10
- }
11
- node._subTreeSep = options.getSubTreeSep(node.data);
12
- node.totalHeight = Math.max(node.height, totalHeight) + 2 * node._subTreeSep;
13
- return node.totalHeight;
14
- }
15
- function thirdWalk(node) {
16
- var children = node.children;
17
- var len = children.length;
18
- if (len) {
19
- children.forEach(function (c) {
20
- thirdWalk(c);
21
- });
22
- var first = children[0];
23
- var last = children[len - 1];
24
- var childrenHeight = last.y - first.y + last.height;
25
- var childrenTotalHeight = 0;
26
- children.forEach(function (child) {
27
- childrenTotalHeight += child.totalHeight;
28
- });
29
- if (childrenHeight > node.height) {
30
- // 当子节点总高度大于父节点高度
31
- node.y = first.y + childrenHeight / 2 - node.height / 2;
32
- } else if (children.length !== 1 || node.height > childrenTotalHeight) {
33
- // 多于一个子节点或者父节点大于所有子节点的总高度
34
- var offset = node.y + (node.height - childrenHeight) / 2 - first.y;
35
- children.forEach(function (c) {
36
- c.translate(0, offset);
37
- });
38
- } else {
39
- // 只有一个子节点
40
- node.y = (first.y + first.height / 2 + last.y + last.height / 2) / 2 - node.height / 2;
41
- }
42
- }
43
- }
44
- var DEFAULT_OPTIONS = {
45
- getSubTreeSep: function getSubTreeSep() {
46
- return 0;
47
- }
48
- };
49
- module.exports = function (root, options) {
50
- if (options === void 0) {
51
- options = {};
52
- }
53
- options = util.assign({}, DEFAULT_OPTIONS, options);
54
- root.parent = {
55
- x: 0,
56
- width: 0,
57
- height: 0,
58
- y: 0
59
- };
60
- // first walk
61
- root.BFTraverse(function (node) {
62
- node.x = node.parent.x + node.parent.width; // simply get x
63
- });
64
- root.parent = null;
65
- // second walk
66
- secondWalk(root, options); // assign sub tree totalHeight
67
- // adjusting
68
- // separating nodes
69
- root.startY = 0;
70
- root.y = root.totalHeight / 2 - root.height / 2;
71
- root.eachNode(function (node) {
72
- var children = node.children;
73
- var len = children.length;
74
- if (len) {
75
- var first = children[0];
76
- first.startY = node.startY + node._subTreeSep;
77
- if (len === 1) {
78
- first.y = node.y + node.height / 2 - first.height / 2;
79
- } else {
80
- first.y = first.startY + first.totalHeight / 2 - first.height / 2;
81
- for (var i = 1; i < len; i++) {
82
- var c = children[i];
83
- c.startY = children[i - 1].startY + children[i - 1].totalHeight;
84
- c.y = c.startY + c.totalHeight / 2 - c.height / 2;
85
- }
86
- }
87
- }
88
- });
89
-
90
- // third walk
91
- thirdWalk(root);
92
- };
@@ -1,236 +0,0 @@
1
- // wrap tree node
2
- function WrappedTree(w, h, y, c) {
3
- if (c === void 0) {
4
- c = [];
5
- }
6
- var me = this;
7
- // size
8
- me.w = w || 0;
9
- me.h = h || 0;
10
-
11
- // position
12
- me.y = y || 0;
13
- me.x = 0;
14
-
15
- // children
16
- me.c = c || [];
17
- me.cs = c.length;
18
-
19
- // modified
20
- me.prelim = 0;
21
- me.mod = 0;
22
- me.shift = 0;
23
- me.change = 0;
24
-
25
- // left/right tree
26
- me.tl = null;
27
- me.tr = null;
28
-
29
- // extreme left/right tree
30
- me.el = null;
31
- me.er = null;
32
-
33
- // modified left/right tree
34
- me.msel = 0;
35
- me.mser = 0;
36
- }
37
- WrappedTree.fromNode = function (root, isHorizontal) {
38
- if (!root) return null;
39
- var children = [];
40
- root.children.forEach(function (child) {
41
- children.push(WrappedTree.fromNode(child, isHorizontal));
42
- });
43
- if (isHorizontal) return new WrappedTree(root.height, root.width, root.x, children);
44
- return new WrappedTree(root.width, root.height, root.y, children);
45
- };
46
-
47
- // node utils
48
- function moveRight(node, move, isHorizontal) {
49
- if (isHorizontal) {
50
- node.y += move;
51
- } else {
52
- node.x += move;
53
- }
54
- node.children.forEach(function (child) {
55
- moveRight(child, move, isHorizontal);
56
- });
57
- }
58
- function getMin(node, isHorizontal) {
59
- var res = isHorizontal ? node.y : node.x;
60
- node.children.forEach(function (child) {
61
- res = Math.min(getMin(child, isHorizontal), res);
62
- });
63
- return res;
64
- }
65
- function normalize(node, isHorizontal) {
66
- var min = getMin(node, isHorizontal);
67
- moveRight(node, -min, isHorizontal);
68
- }
69
- function convertBack(converted /* WrappedTree */, root /* TreeNode */, isHorizontal) {
70
- if (isHorizontal) {
71
- root.y = converted.x;
72
- } else {
73
- root.x = converted.x;
74
- }
75
- converted.c.forEach(function (child, i) {
76
- convertBack(child, root.children[i], isHorizontal);
77
- });
78
- }
79
- function layer(node, isHorizontal, d) {
80
- if (d === void 0) {
81
- d = 0;
82
- }
83
- if (isHorizontal) {
84
- node.x = d;
85
- d += node.width;
86
- } else {
87
- node.y = d;
88
- d += node.height;
89
- }
90
- node.children.forEach(function (child) {
91
- layer(child, isHorizontal, d);
92
- });
93
- }
94
- module.exports = function (root, options) {
95
- if (options === void 0) {
96
- options = {};
97
- }
98
- var isHorizontal = options.isHorizontal;
99
- function firstWalk(t) {
100
- if (t.cs === 0) {
101
- setExtremes(t);
102
- return;
103
- }
104
- firstWalk(t.c[0]);
105
- var ih = updateIYL(bottom(t.c[0].el), 0, null);
106
- for (var i = 1; i < t.cs; ++i) {
107
- firstWalk(t.c[i]);
108
- var min = bottom(t.c[i].er);
109
- separate(t, i, ih);
110
- ih = updateIYL(min, i, ih);
111
- }
112
- positionRoot(t);
113
- setExtremes(t);
114
- }
115
- function setExtremes(t) {
116
- if (t.cs === 0) {
117
- t.el = t;
118
- t.er = t;
119
- t.msel = t.mser = 0;
120
- } else {
121
- t.el = t.c[0].el;
122
- t.msel = t.c[0].msel;
123
- t.er = t.c[t.cs - 1].er;
124
- t.mser = t.c[t.cs - 1].mser;
125
- }
126
- }
127
- function separate(t, i, ih) {
128
- var sr = t.c[i - 1];
129
- var mssr = sr.mod;
130
- var cl = t.c[i];
131
- var mscl = cl.mod;
132
- while (sr !== null && cl !== null) {
133
- if (bottom(sr) > ih.low) ih = ih.nxt;
134
- var dist = mssr + sr.prelim + sr.w - (mscl + cl.prelim);
135
- if (dist > 0) {
136
- mscl += dist;
137
- moveSubtree(t, i, ih.index, dist);
138
- }
139
- var sy = bottom(sr);
140
- var cy = bottom(cl);
141
- if (sy <= cy) {
142
- sr = nextRightContour(sr);
143
- if (sr !== null) mssr += sr.mod;
144
- }
145
- if (sy >= cy) {
146
- cl = nextLeftContour(cl);
147
- if (cl !== null) mscl += cl.mod;
148
- }
149
- }
150
- if (!sr && !!cl) {
151
- setLeftThread(t, i, cl, mscl);
152
- } else if (!!sr && !cl) {
153
- setRightThread(t, i, sr, mssr);
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
- function nextLeftContour(t) {
163
- return t.cs === 0 ? t.tl : t.c[0];
164
- }
165
- function nextRightContour(t) {
166
- return t.cs === 0 ? t.tr : t.c[t.cs - 1];
167
- }
168
- function bottom(t) {
169
- return t.y + t.h;
170
- }
171
- function setLeftThread(t, i, cl, modsumcl) {
172
- var li = t.c[0].el;
173
- li.tl = cl;
174
- var diff = modsumcl - cl.mod - t.c[0].msel;
175
- li.mod += diff;
176
- li.prelim -= diff;
177
- t.c[0].el = t.c[i].el;
178
- t.c[0].msel = t.c[i].msel;
179
- }
180
- function setRightThread(t, i, sr, modsumsr) {
181
- var ri = t.c[i].er;
182
- ri.tr = sr;
183
- var diff = modsumsr - sr.mod - t.c[i].mser;
184
- ri.mod += diff;
185
- ri.prelim -= diff;
186
- t.c[i].er = t.c[i - 1].er;
187
- t.c[i].mser = t.c[i - 1].mser;
188
- }
189
- function positionRoot(t) {
190
- t.prelim = (t.c[0].prelim + t.c[0].mod + t.c[t.cs - 1].mod + t.c[t.cs - 1].prelim + t.c[t.cs - 1].w) / 2 - t.w / 2;
191
- }
192
- function secondWalk(t, modsum) {
193
- modsum += t.mod;
194
- t.x = t.prelim + modsum;
195
- addChildSpacing(t);
196
- for (var i = 0; i < t.cs; i++) {
197
- secondWalk(t.c[i], modsum);
198
- }
199
- }
200
- function distributeExtra(t, i, si, dist) {
201
- if (si !== i - 1) {
202
- var nr = i - si;
203
- t.c[si + 1].shift += dist / nr;
204
- t.c[i].shift -= dist / nr;
205
- t.c[i].change -= dist - dist / nr;
206
- }
207
- }
208
- function addChildSpacing(t) {
209
- var d = 0;
210
- var modsumdelta = 0;
211
- for (var i = 0; i < t.cs; i++) {
212
- d += t.c[i].shift;
213
- modsumdelta += d + t.c[i].change;
214
- t.c[i].mod += modsumdelta;
215
- }
216
- }
217
- function updateIYL(low, index, ih) {
218
- while (ih !== null && low >= ih.low) {
219
- ih = ih.nxt;
220
- }
221
- return {
222
- low: low,
223
- index: index,
224
- nxt: ih
225
- };
226
- }
227
-
228
- // do layout
229
- layer(root, isHorizontal);
230
- var wt = WrappedTree.fromNode(root, isHorizontal);
231
- firstWalk(wt);
232
- secondWalk(wt, 0);
233
- convertBack(wt, root, isHorizontal);
234
- normalize(root, isHorizontal);
235
- return root;
236
- };
@@ -1,39 +0,0 @@
1
- var hierarchy = require('./hierarchy');
2
- module.exports = function (root, options) {
3
- // separate into left and right trees
4
- var left = hierarchy(root.data, options, true); // root only
5
- var right = hierarchy(root.data, options, true); // root only
6
- // automatically
7
- var treeSize = root.children.length;
8
- var rightTreeSize = Math.round(treeSize / 2);
9
- // separate left and right tree by meta data
10
- var getSide = options.getSide || function (child, index) {
11
- if (index < rightTreeSize) {
12
- return 'right';
13
- }
14
- return 'left';
15
- };
16
- for (var i = 0; i < treeSize; i++) {
17
- var child = root.children[i];
18
- var side = getSide(child, i);
19
- if (side === 'right') {
20
- right.children.push(child);
21
- } else {
22
- left.children.push(child);
23
- }
24
- }
25
- left.eachNode(function (node) {
26
- if (!node.isRoot()) {
27
- node.side = 'left';
28
- }
29
- });
30
- right.eachNode(function (node) {
31
- if (!node.isRoot()) {
32
- node.side = 'right';
33
- }
34
- });
35
- return {
36
- left: left,
37
- right: right
38
- };
39
- };
package/lib/mindmap.js DELETED
@@ -1,24 +0,0 @@
1
- function _inheritsLoose(t, o) { t.prototype = Object.create(o.prototype), t.prototype.constructor = t, _setPrototypeOf(t, o); }
2
- function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); }
3
- var TreeLayout = require('./layout/base');
4
- var mindmap = require('./layout/mindmap');
5
- var doTreeLayout = require('./layout/do-layout');
6
- var util = require('./util');
7
- var MindmapLayout = /*#__PURE__*/function (_TreeLayout) {
8
- function MindmapLayout() {
9
- return _TreeLayout.apply(this, arguments) || this;
10
- }
11
- _inheritsLoose(MindmapLayout, _TreeLayout);
12
- var _proto = MindmapLayout.prototype;
13
- _proto.execute = function execute() {
14
- var me = this;
15
- return doTreeLayout(me.rootNode, me.options, mindmap);
16
- };
17
- return MindmapLayout;
18
- }(TreeLayout);
19
- var DEFAULT_OPTIONS = {};
20
- function mindmapLayout(root, options) {
21
- options = util.assign({}, DEFAULT_OPTIONS, options);
22
- return new MindmapLayout(root, options).execute();
23
- }
24
- module.exports = mindmapLayout;
package/lib/util.js DELETED
@@ -1,18 +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) {
10
- if (heightField === void 0) {
11
- heightField = 'height';
12
- }
13
- return align === 'center' ? (preNode[heightField] + node[heightField]) / 2 : preNode.height;
14
- }
15
- module.exports = {
16
- assign: Object.assign,
17
- getHeight: getHeight
18
- };
@@ -1,21 +0,0 @@
1
- const TreeLayout = require('./layout/base');
2
- const nonLayeredTidyTree = require('./layout/non-layered-tidy');
3
- const doTreeLayout = require('./layout/do-layout');
4
- const util = require('./util');
5
-
6
- class CompactBoxTreeLayout extends TreeLayout {
7
- execute() {
8
- const me = this;
9
- return doTreeLayout(me.rootNode, me.options, nonLayeredTidyTree);
10
- }
11
- }
12
-
13
- const DEFAULT_OPTIONS = {
14
- };
15
-
16
- function compactBoxLayout(root, options) {
17
- options = util.assign({}, DEFAULT_OPTIONS, options);
18
- return new CompactBoxTreeLayout(root, options).execute();
19
- }
20
-
21
- module.exports = compactBoxLayout;
package/src/dendrogram.js DELETED
@@ -1,22 +0,0 @@
1
- const TreeLayout = require('./layout/base');
2
- const dendrogram = require('./layout/dendrogram');
3
- const doTreeLayout = require('./layout/do-layout');
4
- const util = require('./util');
5
-
6
- class DendrogramLayout extends TreeLayout {
7
- execute() {
8
- const me = this;
9
- me.rootNode.width = 0;
10
- return doTreeLayout(me.rootNode, me.options, dendrogram);
11
- }
12
- }
13
-
14
- const DEFAULT_OPTIONS = {
15
- };
16
-
17
- function dendrogramLayout(root, options) {
18
- options = util.assign({}, DEFAULT_OPTIONS, options);
19
- return new DendrogramLayout(root, options).execute();
20
- }
21
-
22
- module.exports = dendrogramLayout;