You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am working with some large-ish hierarchies, with over 10,000 nodes, and a bit of custom data. Too large to be in the DOM all at once, so they need to be queried. I am finding that I often need to be able to traverse a hierarchy, starting from a given node, looking for a node that satisfies some condition. This is straightforward to do manually, but in results in a lot of for loops, which aren't really in the D3 idiom. The existing each-* methods have the slight performance disadvantage that there is no way early-exit the loop once the target node has been found. It might be nice to have that option as an API refinement.
Another option could be jQuery-esque .closest and .find methods that looked up and down the hierarchy, respectively, and returned the first "matching" node.
Thanks.
The text was updated successfully, but these errors were encountered:
You can extend d3.hierarchy.prototype to define new methods on hierarchy nodes, as noted in the README. You can see the existing method implementations in src/hierarchy. The name node.find(filter) sounds fine for finding the first descendant in breadth-first order (I like the similarity to array.find), but I’d probably use the name node.findAncestor(filter) rather than node.closest since that’s more self-explanatory.
I don’t have any immediate plans to implement new methods, but if you implement something useful, feel free to send a pull request.
I am working with some large-ish hierarchies, with over 10,000 nodes, and a bit of custom data. Too large to be in the DOM all at once, so they need to be queried. I am finding that I often need to be able to traverse a hierarchy, starting from a given node, looking for a node that satisfies some condition. This is straightforward to do manually, but in results in a lot of
for
loops, which aren't really in the D3 idiom. The existing each-* methods have the slight performance disadvantage that there is no way early-exit the loop once the target node has been found. It might be nice to have that option as an API refinement.Another option could be jQuery-esque
.closest
and.find
methods that looked up and down the hierarchy, respectively, and returned the first "matching" node.Thanks.
The text was updated successfully, but these errors were encountered: