The D3 examples I've seen use an old version of D3 with tree.nodes(root).reverse()
to retrieve nodes array.
It does not work with the latest version of D3. How do I get nodes array in the new version?
CodePudding user response:
Create a tree layout object:
const layout = d3.tree();
Build a root object from your data:
const root = d3.hierarchy(data, d => d.children);
Extract nodes from the tree:
const tree = layout(root);
const nodes = tree.descendants();
Should work for D3 V7 (see a working example here)