Viewing a saved revision (read-only)
7d2640QuRbzFSHvyIJSzk
Random Tree Circle Packing
A recursive random tree visualized with D3 circle packing inside a responsive React component.
App.jsxgenerates a tree with three levels below its root and a random integer from two to five children independently sampled for each internal node.viz.jsis the D3 rendering entry point.renderCircles.jscomputes a D3 hierarchy and pack layout, then renders nested SVG circles.useContainerDimensions.jstracks the available space.
Change the depth, minimum children, or maximum children arguments to generateTree in App.jsx to explore other tree structures. Each leaf receives a random weight between 1 and 10 when the tree is generated. D3 packs the leaves proportionally by area, with enclosing circles sized by the layout. Weights stay fixed during panning, zooming, selection, and resizing. Click a circle to highlight its outline. Drag to pan, scroll or pinch to zoom, and double-click to zoom in. Zoom ranges from 0.5× to 32× and is preserved when selecting a circle.