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