Parent count
olivierpons opened this issue · comments
Just a suggestion, I dont know how to make it on github. When you want to open up to a certain level, it's not the number of children that counts, it's the number of parents. There should be something the developper could write like this:
tree.expand(function(node) {
return node.parents.length < depth;
}
Here's a working thing that you can easily include in your source code like parents() with a "s" or something:
var get_nb_parents = function(node) {
var n = node,
retour = 0;
while (n.parent !== null) {
n = n.parent;
retour++
}
return retour;
};
tree.expand(function (node) {
return get_nb_parents(node) < max_level;
});
Hi.
Do you mean count of ancestors?
I think, expanding of root node by depth is more useful.
And it is working faster.
Thank for your idea. I will add this feature in next release.
You're right: your solution is faster. Expanding of root node by depth can be very useful sometimes. Maybe renaming my function like expandFromRoot()
(or something)...
Yes, maybe I will create a separate function for this