Skip to content

Commit 7037257

Browse files
committed
feat: Add depthOffset attribute
1 parent b1092a4 commit 7037257

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ The data object should have the following structure:
2828
name: "Father",
2929
class: "overriding-css-class",
3030
textClass: "overriding-css-class",
31+
depthOffset: 1,
3132
marriage: {
3233
spouse: {
3334
name: "Mother",

src/dtree.js

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,24 @@ const dTree = {
6767
class: person.class
6868
};
6969

70+
// hide linages to the hidden root node
71+
if (parent == root) {
72+
node.noParent = true;
73+
}
74+
75+
// apply depth offset
76+
for (var i = 0; i < person.depthOffset; i++) {
77+
var pushNode = {
78+
name: '',
79+
id: id++,
80+
hidden: true,
81+
children: [],
82+
noParent: node.noParent
83+
};
84+
parent.children.push(pushNode);
85+
parent = pushNode;
86+
}
87+
7088
// sort children
7189
dTree._sortPersons(person.children, opts);
7290

@@ -125,10 +143,6 @@ const dTree = {
125143
reconstructTree(person, root);
126144
});
127145

128-
_.forEach(root.children, function(child) {
129-
child.noParent = true;
130-
});
131-
132146
return {
133147
root: root,
134148
siblings: siblings

0 commit comments

Comments
 (0)