Discussion about this post

User's avatar
Pablo's avatar

I recently built a chart with d3.js where users can drill down by clicking on the different slices to see the sub-slices. I had to use recursion and a tree-like structure. Luckily I discovered that d3 gives you a hierarchy function (https://d3js.org/d3-hierarchy/hierarchy) that takes a structure like the example data structure you shared, and returns a tree of nodes with some very useful stuff. Things like the depth, a reference to the parent node, and multiple methods to get the ancestors, the shortest path between two nodes, etc. It was fun!

Expand full comment
2 more comments...

No posts