leaves() is a hierarchy-node method that returns an array containing every node without children. Call it on the root returned by d3.stratify() or d3.hierarchy(). section 11.1.2 section 11.1.1
Collecting leaf nodes
After creating a hierarchy, store the terminal nodes alongside the root and all descendants: const root = hierarchy(data); const descendants = root.descendants(); const leaves = root.leaves(); With the language hierarchy, leaves include English, Mandarin Chinese, Hindi, Spanish, and French. section 11.1.2
{
"name": "Languages",
"children": [
{
"name": "Indo-European",
"children": [
{
"name": "Germanic",
"children": [
{
"name": "English"
}
]
},
{
"name": "Indo-Aryan",
"children": [
{
"name": "Hindi"
}
]
},
{
"name": "Romance",
"children": [
{
"name": "Spanish"
},
{
"name": "French"
}
]
},
]
},
{
"name": "Sino-Tibetan",
"children": [
{
"name": "Sinitic",
"children": [
{
"name": "Mandarin Chinese"
}
]
}
]
}
]
}
Inspect the nested JSON structure whose objects without children become the hierarchy's leaves. section 11.1.2
