1 | function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; subClass.__proto__ = superClass; }
|
2 |
|
3 | var TreeLayout = require('./layout/base');
|
4 |
|
5 | var indentedTree = require('./layout/indented');
|
6 |
|
7 | var separateTree = require('./layout/separate-root');
|
8 |
|
9 | var util = require('./util');
|
10 |
|
11 | var VALID_DIRECTIONS = ['LR',
|
12 | 'RL',
|
13 | 'H'
|
14 | ];
|
15 | var DEFAULT_DIRECTION = VALID_DIRECTIONS[0];
|
16 |
|
17 | var IndentedLayout = function (_TreeLayout) {
|
18 | _inheritsLoose(IndentedLayout, _TreeLayout);
|
19 |
|
20 | function IndentedLayout() {
|
21 | return _TreeLayout.apply(this, arguments) || this;
|
22 | }
|
23 |
|
24 | var _proto = IndentedLayout.prototype;
|
25 |
|
26 | _proto.execute = function execute() {
|
27 | var me = this;
|
28 | var options = me.options;
|
29 | var root = me.rootNode;
|
30 | options.isHorizontal = true;
|
31 |
|
32 | var _options$indent = options.indent,
|
33 | indent = _options$indent === void 0 ? 20 : _options$indent,
|
34 | _options$dropCap = options.dropCap,
|
35 | dropCap = _options$dropCap === void 0 ? true : _options$dropCap;
|
36 | var direction = options.direction || DEFAULT_DIRECTION;
|
37 |
|
38 | if (direction && VALID_DIRECTIONS.indexOf(direction) === -1) {
|
39 | throw new TypeError("Invalid direction: " + direction);
|
40 | }
|
41 |
|
42 | if (direction === VALID_DIRECTIONS[0]) {
|
43 |
|
44 | indentedTree(root, indent, dropCap);
|
45 | } else if (direction === VALID_DIRECTIONS[1]) {
|
46 |
|
47 | indentedTree(root, indent, dropCap);
|
48 | root.right2left();
|
49 | } else if (direction === VALID_DIRECTIONS[2]) {
|
50 |
|
51 |
|
52 | var _separateTree = separateTree(root, options),
|
53 | left = _separateTree.left,
|
54 | right = _separateTree.right;
|
55 |
|
56 | indentedTree(left, indent, dropCap);
|
57 | left.right2left();
|
58 | indentedTree(right, indent, dropCap);
|
59 | var bbox = left.getBoundingBox();
|
60 | right.translate(bbox.width, 0);
|
61 | root.x = right.x - root.width / 2;
|
62 | }
|
63 |
|
64 | return root;
|
65 | };
|
66 |
|
67 | return IndentedLayout;
|
68 | }(TreeLayout);
|
69 |
|
70 | var DEFAULT_OPTIONS = {};
|
71 |
|
72 | function indentedLayout(root, options) {
|
73 | options = util.assign({}, DEFAULT_OPTIONS, options);
|
74 | return new IndentedLayout(root, options).execute();
|
75 | }
|
76 |
|
77 | module.exports = indentedLayout; |
\ | No newline at end of file |