Skip to main content
100%

D3.js Drag and Drop, Zoomable, Panning, Collapsible Tree with auto-sizing.

✓ Published0🌍 Public
PPacsangon
Last edited Mar 2, 2016
Created on Jul 27, 2016

This interactive tree visualization demonstrates a collapsible, draggable hierarchy using D3.js v3 with SVG rendering and animated transitions. The root "flare" node is fixed, while any other node can be dragged and dropped onto a new parent, changing the tree structure. Panning occurs by dragging empty space or pushing nodes toward the edge, while zooming uses double-clicks or the mouse wheel, with shift+double-click to zoom out. The tree auto-sizes to fit the viewport, and the code builds the diagram with `d3.layout.tree`, `d3.svg.diagonal`, and JSON data from `flare.json`.

AI-generated description

This example pulls together various examples of work with trees in D3.js.

The panning functionality can certainly be improved in my opinion and I would be thrilled to see better solutions contributed.

One can do all manner of housekeeping or server related calls on the drop event to manage a remote tree dataset for example.

Dragging can be performed on any node other than root (flare). Dropping can be done on any node.

Panning can either be done by dragging an empty part of the SVG around or dragging a node towards an edge.

Zooming is performed by either double clicking on an empty part of the SVG or by scrolling the mouse-wheel. To Zoom out hold shift when double-clicking.

Expanding and collapsing of nodes is achieved by clicking on the desired node.

The tree auto-calculates its sizes both horizontally and vertically so it can adapt between many nodes being present in the view to very few whilst making the view managable and pleasing on the eye.

For any help/queries, http://www.robschmuecker.com @robschmuecker or robert.schmuecker at gmail dot com

Similar vizzes