d3.hierarchy() converts nested JSON data into a D3 hierarchy, commonly stored as root. The hierarchy represents parent-child relationships for hierarchical visualizations. section 11.1.2 section 11.5
Import hierarchy from d3-hierarchy, pass the nested data to hierarchy(data), and use the returned root object to inspect or lay out the tree. section 11.1.2
The resulting root structure provides useful node collections:
- root.descendants() returns every node in the hierarchy. section 11.1.2
- root.leaves() returns nodes without children, such as individual languages. section 11.1.2
- The same root structure can feed pack, treemap, tree, or partition layout generators. section 11.4 section 11.5
Convert nested language data
Given JSON beginning with {"name":"Languages","children":[...]}, call const root = hierarchy(jsonData). Then derive const descendants = root.descendants() and const leaves = root.leaves(). Pass root to a layout such as tree() and use the resulting node information to draw the visualization.
