Skip to main content
100%

Collapsible tree diagram in v7

✓ Published0🌍 Public
Dd3noob
Last edited Jun 19, 2021
Created on Jun 19, 2021

This interactive tree diagram displays hierarchical data using D3 v7’s `d3.tree` layout, rendering parent-child relationships as linked circles and text labels. Clicking any parent node collapses its descendants, with smooth 750ms transitions animating the nodes and links to the clicked node’s position; clicking again expands the subtree. The SVG uses a simple dataset of labeled levels, and the code applies `d3.hierarchy` for data structuring and the `diagonal` path generator for curved links.

AI-generated description

This is a d3.js tree diagram that incldes an interactive element as used as an example in the book D3 Tips and Tricks v7.x.

Any parent node can be clicked on to collapse the portion of the tree below it, on itself. Conversly, it can be clicked on again to regrow.

It is derived from the Mike Bostock Collapsible tree example and updated to use v7.

Kudos and thanks also go out to Soumya Ranjan for steering me in the fight direction for the diagonal solution.

mit Licensed

Similar vizzes