A D3 layout prepares data for a particular visualization. It takes a dataset and produces annotated data containing values needed to draw the chart. The layout does not draw anything: drawing comes afterward, using the calculated values. section 5.0
Choose a layout for the values your chart needs:
- Use d3.pie() to calculate each slice’s start and end angles. Pass those angles to an arc generator to draw pie or donut slices. section 5.4
- Use d3.stack() to calculate each series’ lower and upper boundaries. Those boundaries position stacked bars or guide an area generator for a streamgraph. section 5.4
- Use pack() with hierarchical data to calculate circle centers and radii for a circle pack. section 11.2.1
Prepare a circle pack
Start with a hierarchical root. Call root.sum(d => d.total_speakers) to calculate sizes, configure pack().size([innerWidth, innerHeight]).padding(3), then pass the root to the generator. Its nodes now have x, y, and r values you can use to place SVG circles. section 11.2.1
Figure 11.5 To create a circle pack visualization with D3, we start with hierarchical data, often named root. To compute the layout, we call the root sum() method to calculate the size of the circles. Then we pass the root data structure to D3’s pack() layout generator. This generator appends each circle’s position and radius into the data. Finally, we append circles to an SVG container and set their position and size with the appended data.
Follow the full handoff from hierarchical data, through computed circle positions and radii, to SVG circles. section 11.2.1
