|
1 | | -import Layout from './layout' |
2 | | -import Node from '../structure/node' |
3 | | -import autoLayout from '../algorithms/auto-layout' |
| 1 | +import Layout from "./layout"; |
| 2 | +import Node from "../structure/node"; |
| 3 | +import autoLayout from "../algorithms/auto-layout"; |
4 | 4 |
|
5 | 5 | class Standard extends Layout { |
6 | 6 | isHorizontal() { |
7 | | - return true |
| 7 | + return true; |
8 | 8 | } |
9 | 9 |
|
10 | 10 | doLayout() { |
11 | | - const me = this |
12 | | - const root = me.root |
13 | | - const options = me.options |
| 11 | + const me = this; |
| 12 | + const root = me.root; |
| 13 | + const options = me.options; |
14 | 14 | // separate into left and right trees |
15 | | - const leftTree = new Node(root.data, options, true) |
16 | | - const rightTree = new Node(root.data, options, true) |
17 | | - const treeSize = root.children.length |
18 | | - const rightTreeSize = Math.round(treeSize / 2) |
| 15 | + const leftTree = new Node(root.data, options, true); |
| 16 | + const rightTree = new Node(root.data, options, true); |
| 17 | + const treeSize = root.children.length; |
| 18 | + const rightTreeSize = Math.round(treeSize / 2); |
19 | 19 | for (let i = 0; i < treeSize; i++) { |
20 | | - const child = root.children[i] |
| 20 | + const child = root.children[i]; |
21 | 21 | if (i < rightTreeSize) { |
22 | | - rightTree.children.push(child) |
| 22 | + rightTree.children.push(child); |
23 | 23 | } else { |
24 | | - leftTree.children.push(child) |
| 24 | + leftTree.children.push(child); |
25 | 25 | } |
26 | 26 | } |
| 27 | + |
| 28 | + leftTree.children.reverse(); |
27 | 29 | // do layout for left and right trees |
28 | | - autoLayout(rightTree, true) |
29 | | - autoLayout(leftTree, true) |
30 | | - leftTree.right2left() |
| 30 | + autoLayout(rightTree, true); |
| 31 | + autoLayout(leftTree, true); |
| 32 | + leftTree.right2left(); |
31 | 33 | // combine left and right trees |
32 | | - rightTree.translate(leftTree.x - rightTree.x, leftTree.y - rightTree.y) |
| 34 | + rightTree.translate(leftTree.x - rightTree.x, leftTree.y - rightTree.y); |
33 | 35 | // translate root |
34 | | - root.x = leftTree.x |
35 | | - root.y = rightTree.y |
36 | | - const bb = root.getBoundingBox() |
| 36 | + root.x = leftTree.x; |
| 37 | + root.y = rightTree.y; |
| 38 | + const bb = root.getBoundingBox(); |
37 | 39 | if (bb.top < 0) { |
38 | | - root.translate(0, -bb.top) |
| 40 | + root.translate(0, -bb.top); |
39 | 41 | } |
40 | | - return root |
| 42 | + return root; |
41 | 43 | } |
42 | 44 | } |
43 | 45 |
|
44 | | -export default Standard |
| 46 | +export default Standard; |
0 commit comments