@antv/hierarchy 0.6.8 → 0.6.9

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.
@@ -1,6 +1,5 @@
1
1
  /* eslint-disable no-cond-assign */
2
2
  var util = require('../util');
3
-
4
3
  var PEM = 18;
5
4
  var DEFAULT_HEIGHT = PEM * 2;
6
5
  var DEFAULT_GAP = PEM;
@@ -50,7 +49,6 @@ function Node(data, options) {
50
49
  * | |
51
50
  * -----------width------------
52
51
  */
53
-
54
52
  var hgap = options.getHGap(data);
55
53
  var vgap = options.getVGap(data);
56
54
  me.preH = options.getPreH(data);
@@ -62,15 +60,12 @@ function Node(data, options) {
62
60
  me.id = options.getId(data);
63
61
  me.x = me.y = 0;
64
62
  me.depth = 0;
65
-
66
63
  if (!me.children) {
67
64
  me.children = [];
68
65
  }
69
-
70
66
  me.addGap(hgap, vgap);
71
67
  return me;
72
68
  }
73
-
74
69
  util.assign(Node.prototype, {
75
70
  isRoot: function isRoot() {
76
71
  return this.depth === 0;
@@ -90,7 +85,6 @@ util.assign(Node.prototype, {
90
85
  var me = this;
91
86
  var nodes = [me];
92
87
  var current;
93
-
94
88
  while (current = nodes.shift()) {
95
89
  callback(current);
96
90
  nodes = current.children.concat(nodes);
@@ -105,7 +99,6 @@ util.assign(Node.prototype, {
105
99
  var me = this;
106
100
  var nodes = [me];
107
101
  var current;
108
-
109
102
  while (current = nodes.shift()) {
110
103
  callback(current);
111
104
  nodes = nodes.concat(current.children);
@@ -132,11 +125,9 @@ util.assign(Node.prototype, {
132
125
  if (tx === void 0) {
133
126
  tx = 0;
134
127
  }
135
-
136
128
  if (ty === void 0) {
137
129
  ty = 0;
138
130
  }
139
-
140
131
  this.eachNode(function (node) {
141
132
  node.x += tx;
142
133
  node.y += ty;
@@ -148,37 +139,37 @@ util.assign(Node.prototype, {
148
139
  var me = this;
149
140
  var bb = me.getBoundingBox();
150
141
  me.eachNode(function (node) {
151
- node.x = node.x - (node.x - bb.left) * 2 - node.width; // node.x = - node.x;
142
+ node.x = node.x - (node.x - bb.left) * 2 - node.width;
143
+ // node.x = - node.x;
152
144
  });
145
+
153
146
  me.translate(bb.width, 0);
154
147
  },
155
148
  bottom2top: function bottom2top() {
156
149
  var me = this;
157
150
  var bb = me.getBoundingBox();
158
151
  me.eachNode(function (node) {
159
- node.y = node.y - (node.y - bb.top) * 2 - node.height; // node.y = - node.y;
152
+ node.y = node.y - (node.y - bb.top) * 2 - node.height;
153
+ // node.y = - node.y;
160
154
  });
155
+
161
156
  me.translate(0, bb.height);
162
157
  }
163
158
  });
164
-
165
159
  function hierarchy(data, options, isolated) {
166
160
  if (options === void 0) {
167
161
  options = {};
168
162
  }
169
-
170
163
  options = util.assign({}, DEFAULT_OPTIONS, options);
171
164
  var root = new Node(data, options);
172
165
  var nodes = [root];
173
166
  var node;
174
-
175
167
  if (!isolated && !data.collapsed) {
176
168
  while (node = nodes.shift()) {
177
169
  if (!node.data.collapsed) {
178
170
  var children = options.getChildren(node.data);
179
171
  var length = children ? children.length : 0;
180
172
  node.children = new Array(length);
181
-
182
173
  if (children && length) {
183
174
  for (var i = 0; i < length; i++) {
184
175
  var child = new Node(children[i], options);
@@ -191,8 +182,6 @@ function hierarchy(data, options, isolated) {
191
182
  }
192
183
  }
193
184
  }
194
-
195
185
  return root;
196
186
  }
197
-
198
187
  module.exports = hierarchy;
@@ -1,7 +1,7 @@
1
- function positionNode(node, previousNode, indent, dropCap) {
1
+ var util = require('../util');
2
+ function positionNode(node, previousNode, indent, dropCap, align) {
2
3
  // caculate the node's horizontal offset DX, dx's type might be number or function
3
4
  var displacementX = typeof indent === 'function' ? indent(node) : indent * node.depth;
4
-
5
5
  if (!dropCap) {
6
6
  try {
7
7
  if (node.id === node.parent.children[0].id) {
@@ -9,19 +9,34 @@ function positionNode(node, previousNode, indent, dropCap) {
9
9
  node.y = previousNode ? previousNode.y : 0;
10
10
  return;
11
11
  }
12
- } catch (e) {// skip to normal when a node has no parent
12
+ } catch (e) {
13
+ // skip to normal when a node has no parent
13
14
  }
14
15
  }
15
-
16
16
  node.x += displacementX;
17
- node.y = previousNode ? previousNode.y + previousNode.height : 0;
17
+ if (previousNode) {
18
+ var _previousNode$parent;
19
+ node.y = previousNode.y + util.getHeight(previousNode, node, align);
20
+ if (node.parent.id !== ((_previousNode$parent = previousNode.parent) == null ? void 0 : _previousNode$parent.id)) {
21
+ // previous node has different parent
22
+ var index = node.parent.children.findIndex(function (n) {
23
+ return n.id === node.id;
24
+ });
25
+ var preNode = node.parent.children[index - 1];
26
+ if (preNode) {
27
+ var preY = preNode.y + util.getHeight(preNode, node, align);
28
+ node.y = preY > node.y ? preY : node.y;
29
+ }
30
+ }
31
+ } else {
32
+ node.y = 0;
33
+ }
18
34
  return;
19
35
  }
20
-
21
- module.exports = function (root, indent, dropCap) {
36
+ module.exports = function (root, indent, dropCap, align) {
22
37
  var previousNode = null;
23
38
  root.eachNode(function (node) {
24
- positionNode(node, previousNode, indent, dropCap);
39
+ positionNode(node, previousNode, indent, dropCap, align);
25
40
  previousNode = node;
26
41
  });
27
42
  };
@@ -1,8 +1,6 @@
1
1
  var util = require('../util');
2
-
3
2
  function secondWalk(node, options) {
4
3
  var totalHeight = 0;
5
-
6
4
  if (!node.children.length) {
7
5
  totalHeight = node.height;
8
6
  } else {
@@ -10,16 +8,13 @@ function secondWalk(node, options) {
10
8
  totalHeight += secondWalk(c, options);
11
9
  });
12
10
  }
13
-
14
11
  node._subTreeSep = options.getSubTreeSep(node.data);
15
12
  node.totalHeight = Math.max(node.height, totalHeight) + 2 * node._subTreeSep;
16
13
  return node.totalHeight;
17
14
  }
18
-
19
15
  function thirdWalk(node) {
20
16
  var children = node.children;
21
17
  var len = children.length;
22
-
23
18
  if (len) {
24
19
  children.forEach(function (c) {
25
20
  thirdWalk(c);
@@ -31,7 +26,6 @@ function thirdWalk(node) {
31
26
  children.forEach(function (child) {
32
27
  childrenTotalHeight += child.totalHeight;
33
28
  });
34
-
35
29
  if (childrenHeight > node.height) {
36
30
  // 当子节点总高度大于父节点高度
37
31
  node.y = first.y + childrenHeight / 2 - node.height / 2;
@@ -47,50 +41,44 @@ function thirdWalk(node) {
47
41
  }
48
42
  }
49
43
  }
50
-
51
44
  var DEFAULT_OPTIONS = {
52
45
  getSubTreeSep: function getSubTreeSep() {
53
46
  return 0;
54
47
  }
55
48
  };
56
-
57
49
  module.exports = function (root, options) {
58
50
  if (options === void 0) {
59
51
  options = {};
60
52
  }
61
-
62
53
  options = util.assign({}, DEFAULT_OPTIONS, options);
63
54
  root.parent = {
64
55
  x: 0,
65
56
  width: 0,
66
57
  height: 0,
67
58
  y: 0
68
- }; // first walk
69
-
59
+ };
60
+ // first walk
70
61
  root.BFTraverse(function (node) {
71
62
  node.x = node.parent.x + node.parent.width; // simply get x
72
63
  });
73
- root.parent = null; // second walk
74
64
 
65
+ root.parent = null;
66
+ // second walk
75
67
  secondWalk(root, options); // assign sub tree totalHeight
76
68
  // adjusting
77
69
  // separating nodes
78
-
79
70
  root.startY = 0;
80
71
  root.y = root.totalHeight / 2 - root.height / 2;
81
72
  root.eachNode(function (node) {
82
73
  var children = node.children;
83
74
  var len = children.length;
84
-
85
75
  if (len) {
86
76
  var first = children[0];
87
77
  first.startY = node.startY + node._subTreeSep;
88
-
89
78
  if (len === 1) {
90
79
  first.y = node.y + node.height / 2 - first.height / 2;
91
80
  } else {
92
81
  first.y = first.startY + first.totalHeight / 2 - first.height / 2;
93
-
94
82
  for (var i = 1; i < len; i++) {
95
83
  var c = children[i];
96
84
  c.startY = children[i - 1].startY + children[i - 1].totalHeight;
@@ -98,7 +86,8 @@ module.exports = function (root, options) {
98
86
  }
99
87
  }
100
88
  }
101
- }); // third walk
89
+ });
102
90
 
91
+ // third walk
103
92
  thirdWalk(root);
104
93
  };
@@ -3,33 +3,37 @@ function WrappedTree(w, h, y, c) {
3
3
  if (c === void 0) {
4
4
  c = [];
5
5
  }
6
-
7
- var me = this; // size
8
-
6
+ var me = this;
7
+ // size
9
8
  me.w = w || 0;
10
- me.h = h || 0; // position
9
+ me.h = h || 0;
11
10
 
11
+ // position
12
12
  me.y = y || 0;
13
- me.x = 0; // children
13
+ me.x = 0;
14
14
 
15
+ // children
15
16
  me.c = c || [];
16
- me.cs = c.length; // modified
17
+ me.cs = c.length;
17
18
 
19
+ // modified
18
20
  me.prelim = 0;
19
21
  me.mod = 0;
20
22
  me.shift = 0;
21
- me.change = 0; // left/right tree
23
+ me.change = 0;
22
24
 
25
+ // left/right tree
23
26
  me.tl = null;
24
- me.tr = null; // extreme left/right tree
27
+ me.tr = null;
25
28
 
29
+ // extreme left/right tree
26
30
  me.el = null;
27
- me.er = null; // modified left/right tree
31
+ me.er = null;
28
32
 
33
+ // modified left/right tree
29
34
  me.msel = 0;
30
35
  me.mser = 0;
31
36
  }
32
-
33
37
  WrappedTree.fromNode = function (root, isHorizontal) {
34
38
  if (!root) return null;
35
39
  var children = [];
@@ -38,21 +42,19 @@ WrappedTree.fromNode = function (root, isHorizontal) {
38
42
  });
39
43
  if (isHorizontal) return new WrappedTree(root.height, root.width, root.x, children);
40
44
  return new WrappedTree(root.width, root.height, root.y, children);
41
- }; // node utils
42
-
45
+ };
43
46
 
47
+ // node utils
44
48
  function moveRight(node, move, isHorizontal) {
45
49
  if (isHorizontal) {
46
50
  node.y += move;
47
51
  } else {
48
52
  node.x += move;
49
53
  }
50
-
51
54
  node.children.forEach(function (child) {
52
55
  moveRight(child, move, isHorizontal);
53
56
  });
54
57
  }
55
-
56
58
  function getMin(node, isHorizontal) {
57
59
  var res = isHorizontal ? node.y : node.x;
58
60
  node.children.forEach(function (child) {
@@ -60,33 +62,24 @@ function getMin(node, isHorizontal) {
60
62
  });
61
63
  return res;
62
64
  }
63
-
64
65
  function normalize(node, isHorizontal) {
65
66
  var min = getMin(node, isHorizontal);
66
67
  moveRight(node, -min, isHorizontal);
67
68
  }
68
-
69
- function convertBack(converted
70
- /* WrappedTree */
71
- , root
72
- /* TreeNode */
73
- , isHorizontal) {
69
+ function convertBack(converted /* WrappedTree */, root /* TreeNode */, isHorizontal) {
74
70
  if (isHorizontal) {
75
71
  root.y = converted.x;
76
72
  } else {
77
73
  root.x = converted.x;
78
74
  }
79
-
80
75
  converted.c.forEach(function (child, i) {
81
76
  convertBack(child, root.children[i], isHorizontal);
82
77
  });
83
78
  }
84
-
85
79
  function layer(node, isHorizontal, d) {
86
80
  if (d === void 0) {
87
81
  d = 0;
88
82
  }
89
-
90
83
  if (isHorizontal) {
91
84
  node.x = d;
92
85
  d += node.width;
@@ -94,39 +87,31 @@ function layer(node, isHorizontal, d) {
94
87
  node.y = d;
95
88
  d += node.height;
96
89
  }
97
-
98
90
  node.children.forEach(function (child) {
99
91
  layer(child, isHorizontal, d);
100
92
  });
101
93
  }
102
-
103
94
  module.exports = function (root, options) {
104
95
  if (options === void 0) {
105
96
  options = {};
106
97
  }
107
-
108
98
  var isHorizontal = options.isHorizontal;
109
-
110
99
  function firstWalk(t) {
111
100
  if (t.cs === 0) {
112
101
  setExtremes(t);
113
102
  return;
114
103
  }
115
-
116
104
  firstWalk(t.c[0]);
117
105
  var ih = updateIYL(bottom(t.c[0].el), 0, null);
118
-
119
106
  for (var i = 1; i < t.cs; ++i) {
120
107
  firstWalk(t.c[i]);
121
108
  var min = bottom(t.c[i].er);
122
109
  separate(t, i, ih);
123
110
  ih = updateIYL(min, i, ih);
124
111
  }
125
-
126
112
  positionRoot(t);
127
113
  setExtremes(t);
128
114
  }
129
-
130
115
  function setExtremes(t) {
131
116
  if (t.cs === 0) {
132
117
  t.el = t;
@@ -139,62 +124,50 @@ module.exports = function (root, options) {
139
124
  t.mser = t.c[t.cs - 1].mser;
140
125
  }
141
126
  }
142
-
143
127
  function separate(t, i, ih) {
144
128
  var sr = t.c[i - 1];
145
129
  var mssr = sr.mod;
146
130
  var cl = t.c[i];
147
131
  var mscl = cl.mod;
148
-
149
132
  while (sr !== null && cl !== null) {
150
133
  if (bottom(sr) > ih.low) ih = ih.nxt;
151
134
  var dist = mssr + sr.prelim + sr.w - (mscl + cl.prelim);
152
-
153
135
  if (dist > 0) {
154
136
  mscl += dist;
155
137
  moveSubtree(t, i, ih.index, dist);
156
138
  }
157
-
158
139
  var sy = bottom(sr);
159
140
  var cy = bottom(cl);
160
-
161
141
  if (sy <= cy) {
162
142
  sr = nextRightContour(sr);
163
143
  if (sr !== null) mssr += sr.mod;
164
144
  }
165
-
166
145
  if (sy >= cy) {
167
146
  cl = nextLeftContour(cl);
168
147
  if (cl !== null) mscl += cl.mod;
169
148
  }
170
149
  }
171
-
172
150
  if (!sr && !!cl) {
173
151
  setLeftThread(t, i, cl, mscl);
174
152
  } else if (!!sr && !cl) {
175
153
  setRightThread(t, i, sr, mssr);
176
154
  }
177
155
  }
178
-
179
156
  function moveSubtree(t, i, si, dist) {
180
157
  t.c[i].mod += dist;
181
158
  t.c[i].msel += dist;
182
159
  t.c[i].mser += dist;
183
160
  distributeExtra(t, i, si, dist);
184
161
  }
185
-
186
162
  function nextLeftContour(t) {
187
163
  return t.cs === 0 ? t.tl : t.c[0];
188
164
  }
189
-
190
165
  function nextRightContour(t) {
191
166
  return t.cs === 0 ? t.tr : t.c[t.cs - 1];
192
167
  }
193
-
194
168
  function bottom(t) {
195
169
  return t.y + t.h;
196
170
  }
197
-
198
171
  function setLeftThread(t, i, cl, modsumcl) {
199
172
  var li = t.c[0].el;
200
173
  li.tl = cl;
@@ -204,7 +177,6 @@ module.exports = function (root, options) {
204
177
  t.c[0].el = t.c[i].el;
205
178
  t.c[0].msel = t.c[i].msel;
206
179
  }
207
-
208
180
  function setRightThread(t, i, sr, modsumsr) {
209
181
  var ri = t.c[i].er;
210
182
  ri.tr = sr;
@@ -214,21 +186,17 @@ module.exports = function (root, options) {
214
186
  t.c[i].er = t.c[i - 1].er;
215
187
  t.c[i].mser = t.c[i - 1].mser;
216
188
  }
217
-
218
189
  function positionRoot(t) {
219
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;
220
191
  }
221
-
222
192
  function secondWalk(t, modsum) {
223
193
  modsum += t.mod;
224
194
  t.x = t.prelim + modsum;
225
195
  addChildSpacing(t);
226
-
227
196
  for (var i = 0; i < t.cs; i++) {
228
197
  secondWalk(t.c[i], modsum);
229
198
  }
230
199
  }
231
-
232
200
  function distributeExtra(t, i, si, dist) {
233
201
  if (si !== i - 1) {
234
202
  var nr = i - si;
@@ -237,31 +205,27 @@ module.exports = function (root, options) {
237
205
  t.c[i].change -= dist - dist / nr;
238
206
  }
239
207
  }
240
-
241
208
  function addChildSpacing(t) {
242
209
  var d = 0;
243
210
  var modsumdelta = 0;
244
-
245
211
  for (var i = 0; i < t.cs; i++) {
246
212
  d += t.c[i].shift;
247
213
  modsumdelta += d + t.c[i].change;
248
214
  t.c[i].mod += modsumdelta;
249
215
  }
250
216
  }
251
-
252
217
  function updateIYL(low, index, ih) {
253
218
  while (ih !== null && low >= ih.low) {
254
219
  ih = ih.nxt;
255
220
  }
256
-
257
221
  return {
258
222
  low: low,
259
223
  index: index,
260
224
  nxt: ih
261
225
  };
262
- } // do layout
263
-
226
+ }
264
227
 
228
+ // do layout
265
229
  layer(root, isHorizontal);
266
230
  var wt = WrappedTree.fromNode(root, isHorizontal);
267
231
  firstWalk(wt);
@@ -1,34 +1,27 @@
1
1
  var hierarchy = require('./hierarchy');
2
-
3
2
  module.exports = function (root, options) {
4
3
  // separate into left and right trees
5
4
  var left = hierarchy(root.data, options, true); // root only
6
-
7
5
  var right = hierarchy(root.data, options, true); // root only
8
6
  // automatically
9
-
10
7
  var treeSize = root.children.length;
11
- var rightTreeSize = Math.round(treeSize / 2); // separate left and right tree by meta data
12
-
8
+ var rightTreeSize = Math.round(treeSize / 2);
9
+ // separate left and right tree by meta data
13
10
  var getSide = options.getSide || function (child, index) {
14
11
  if (index < rightTreeSize) {
15
12
  return 'right';
16
13
  }
17
-
18
14
  return 'left';
19
15
  };
20
-
21
16
  for (var i = 0; i < treeSize; i++) {
22
17
  var child = root.children[i];
23
18
  var side = getSide(child, i);
24
-
25
19
  if (side === 'right') {
26
20
  right.children.push(child);
27
21
  } else {
28
22
  left.children.push(child);
29
23
  }
30
24
  }
31
-
32
25
  left.eachNode(function (node) {
33
26
  if (!node.isRoot()) {
34
27
  node.side = 'left';
package/lib/mindmap.js CHANGED
@@ -1,35 +1,24 @@
1
- function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; subClass.__proto__ = superClass; }
2
-
1
+ function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }
2
+ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
3
3
  var TreeLayout = require('./layout/base');
4
-
5
4
  var mindmap = require('./layout/mindmap');
6
-
7
5
  var doTreeLayout = require('./layout/do-layout');
8
-
9
6
  var util = require('./util');
10
-
11
7
  var MindmapLayout = /*#__PURE__*/function (_TreeLayout) {
12
8
  _inheritsLoose(MindmapLayout, _TreeLayout);
13
-
14
9
  function MindmapLayout() {
15
10
  return _TreeLayout.apply(this, arguments) || this;
16
11
  }
17
-
18
12
  var _proto = MindmapLayout.prototype;
19
-
20
13
  _proto.execute = function execute() {
21
14
  var me = this;
22
15
  return doTreeLayout(me.rootNode, me.options, mindmap);
23
16
  };
24
-
25
17
  return MindmapLayout;
26
18
  }(TreeLayout);
27
-
28
19
  var DEFAULT_OPTIONS = {};
29
-
30
20
  function mindmapLayout(root, options) {
31
21
  options = util.assign({}, DEFAULT_OPTIONS, options);
32
22
  return new MindmapLayout(root, options).execute();
33
23
  }
34
-
35
24
  module.exports = mindmapLayout;
package/lib/util.js CHANGED
@@ -1,6 +1,21 @@
1
1
  var _require = require('@antv/util'),
2
- mix = _require.mix;
2
+ mix = _require.mix;
3
3
 
4
+ /**
5
+ * Get average height or height for node's position calculation, according to align.
6
+ * @param {*} preNode previous node
7
+ * @param {*} node current node, whose position is going to be calculated
8
+ * @param {'center' | undefined} align 'center' means nodes align at the center, other value means align at the left-top
9
+ * @param {string} heightField field name for height value on preNode and node
10
+ * @return {number} the height for calculation
11
+ */
12
+ function getHeight(preNode, node, align, heightField) {
13
+ if (heightField === void 0) {
14
+ heightField = 'height';
15
+ }
16
+ return align === 'center' ? (preNode[heightField] + node[heightField]) / 2 : preNode.height;
17
+ }
4
18
  module.exports = {
5
- assign: mix
19
+ assign: mix,
20
+ getHeight: getHeight
6
21
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@antv/hierarchy",
3
- "version": "0.6.8",
3
+ "version": "0.6.9",
4
4
  "description": "layout algorithms for visualizing hierarchical data",
5
5
  "main": "build/hierarchy.js",
6
6
  "browser": "build/hierarchy.js",
@@ -32,7 +32,9 @@
32
32
  "connect": "~3.6.5",
33
33
  "d3-queue": "~3.0.7",
34
34
  "debug": "~3.1.0",
35
- "electron": "~2.0.6",
35
+ "spectron": "^13.0.0",
36
+ "electron-packager": "^15.2.0",
37
+ "electron": "^11.2.1",
36
38
  "eslint": "~3.19.0",
37
39
  "eslint-config-airbnb": "~15.0.1",
38
40
  "eslint-config-egg": "~4.2.0",
@@ -80,6 +82,9 @@
80
82
  "silent": false
81
83
  },
82
84
  "dependencies": {
83
- "@antv/util": "^2.0.7"
85
+ "@antv/util": "^2.0.7",
86
+ "electron": "^11.2.1",
87
+ "electron-packager": "^17.1.1",
88
+ "spectron": "^19.0.0"
84
89
  }
85
90
  }
package/src/indented.js CHANGED
@@ -18,22 +18,21 @@ class IndentedLayout extends TreeLayout {
18
18
  const root = me.rootNode;
19
19
  options.isHorizontal = true;
20
20
  // default indent 20 and sink first children;
21
- const { indent = 20, dropCap = true } = options;
22
- const direction = options.direction || DEFAULT_DIRECTION;
21
+ const { indent = 20, dropCap = true, direction = DEFAULT_DIRECTION, align } = options;
23
22
  if (direction && VALID_DIRECTIONS.indexOf(direction) === -1) {
24
23
  throw new TypeError(`Invalid direction: ${direction}`);
25
24
  }
26
25
  if (direction === VALID_DIRECTIONS[0]) { // LR
27
- indentedTree(root, indent, dropCap);
26
+ indentedTree(root, indent, dropCap, align);
28
27
  } else if (direction === VALID_DIRECTIONS[1]) { // RL
29
- indentedTree(root, indent, dropCap);
28
+ indentedTree(root, indent, dropCap, align);
30
29
  root.right2left();
31
30
  } else if (direction === VALID_DIRECTIONS[2]) { // H
32
31
  // separate into left and right trees
33
32
  const { left, right } = separateTree(root, options);
34
- indentedTree(left, indent, dropCap);
33
+ indentedTree(left, indent, dropCap, align);
35
34
  left.right2left();
36
- indentedTree(right, indent, dropCap);
35
+ indentedTree(right, indent, dropCap, align);
37
36
  const bbox = left.getBoundingBox();
38
37
  right.translate(bbox.width, 0);
39
38
  root.x = right.x - root.width / 2;