-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTreeNodeAdapter.js
More file actions
51 lines (46 loc) · 1.61 KB
/
TreeNodeAdapter.js
File metadata and controls
51 lines (46 loc) · 1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
class TreeNodeAdapter {
static convertFuncDefault(node) {
const layoutNode = new LayoutTreeNode();
layoutNode.setValue(node);
layoutNode.setAncestor(layoutNode);
return layoutNode;
}
static createLayoutTreeVec(root, convertFunc) {
// 1. Create layout tree
const layoutRoot = convertFunc(root);
layoutRoot.setAncestor(layoutRoot);
if (root.getChildren().length !== 0)
this._createLayoutTree(layoutRoot, convertFunc);
// 2. Put nodes into array
const nodes = [layoutRoot];
for (let i = 0; i < nodes.length; i++)
for (const childNode of nodes[i].getChildren())
nodes.push(childNode);
return nodes;
}
static createLayoutTreeVec_outVec(outVec, root, convertFunc) {
// 1. Create layout tree
const layoutRoot = convertFunc(root);
layoutRoot.setAncestor(layoutRoot);
if (root.getChildren().length !== 0)
this._createLayoutTree(layoutRoot, convertFunc);
// 2. Put nodes into array
outVec.push(layoutRoot);
for (let i = 0; i < outVec.length; i++)
for (const childNode of outVec[i].getChildren())
outVec.push(childNode);
}
static _createLayoutTree(layoutNode, convertFunc) {
for (let i = 0; i < layoutNode.getValue().getChildren().length; i++) {
const childNode = layoutNode.getValue().getChildren()[i];
const childLayoutNode = convertFunc(childNode);
childLayoutNode.setParent(layoutNode);
childLayoutNode.setNumber(i);
childLayoutNode.setLevel(layoutNode.getLevel() + 1);
childLayoutNode.setAncestor(childLayoutNode);
layoutNode.addChild(childLayoutNode);
if (childNode.getChildren().length !== 0)
this._createLayoutTree(childLayoutNode, convertFunc);
}
}
}