liveBook · Manning

Annotated dataset

As explained in D3.js in Action, Third Edition

An annotated dataset is a stack-layout output structure containing series arrays with stacked boundaries and references to the original data.

An annotated dataset is the output of a D3 layout function. Rather than drawing a chart itself, a layout preprocesses input data into a new structure containing the values needed to position and draw a chosen visualization. The output retains links to the original input data while adding layout-specific measurements. section 5.0 section 5.4

Treat the annotated dataset as the bridge between data preparation and SVG drawing. First format the input, configure a layout generator, then call that generator. Bind its result to chart elements or pass it to a shape generator; the added attributes determine where those elements appear. section 5.1.2 section 5.2

The annotations depend on the layout that produced them:

  • A pie layout returns one object per slice, including the original datum, slice value, index, startAngle, endAngle, and padAngle. An arc generator can use the two angles to calculate an SVG path. section 5.1.2 section 5.4
  • A stack layout returns a multidimensional structure: one array per series, containing one lower-and-upper-boundary pair per input row. Series IDs are available through key, and each pair retains its original row as d.data. section 5.2.1 section 5.4

From music sales to stacked bars

Configure d3.stack() with music-format keys and call it with yearly sales data. For each series, bind its boundary pairs to rectangles: use d.data.year for x, d[1] for y, and the difference between scaled d[0] and d[1] for height. The same annotated dataset can instead feed d3.area() to draw stacked paths for a streamgraph. section 5.2.1 section 5.2.2 section 5.2.3

Figure 5.13 Annotated dataset returned by the stack layout generator
figure

Inspect the stacked output structure to see how series arrays, boundary pairs, and original data are organized before binding them to SVG elements. section 5.2.1

Do not confuse a layout with a shape generator. The layout computes chart-ready values; drawing happens later. Pie annotations supply angular boundaries for arcs, while stack annotations supply vertical boundaries for rectangles or areas. section 5.0 section 5.2.3

How D3.js in Action, Third Edition covers it

How deep it goes
Explains pie angles and stack series boundaries through generator setup, returned structures, and SVG binding.
Examples
Uses music-format sales from 1973–2019 to produce pie slices, stacked bars, and a streamgraph.
What it assumes
Teaches the layout-output workflow from formatted datasets while relying on SVG shapes and D3 generators for rendering.
What you can do after
Apply it via D3 layout generators to bind calculated angles or stacked boundaries to SVG shapes.
How it connects
Connects D3 layouts to pie layouts, stack layouts, arc generators, area generators, scales, and SVG data binding.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of D3.js in Action, Third Edition. The section links point to the parts of the book it draws on.