liveBook · Manning

Composite tooltip

As explained in D3.js in Action, Third Edition

A compound tooltip is a tooltip that presents multiple related values or data fields together.

A composite tooltip presents several related values together. On a streamgraph, it follows the mouse and reveals the selected year plus sales for each music format, making stacked areas easier to read precisely. section 7.3.2

Build the tooltip progressively:

  • Append a grouped SVG element with the class tooltip, then add a dashed vertical guide line. section 7.3.2
  • Add a formatted year label and a text group positioned above the chart. section 7.3.2
  • Create one text span for each format so every value has its own selectable class and line. section 7.3.2
  • On mouse movement, read the pointer’s x-position, translate the tooltip, invert the x-scale, and update the year and values. section 7.3.2

Streamgraph sales breakdown

A streamgraph showing 40 years of music sales can use a composite tooltip to connect the hovered position with the corresponding year and sales breakdown. Matching the streamgraph’s stacking order to the tooltip labels helps users map visual layers to values. section 7.3.2

Figure 7.12 Streamgraph visualizing 40 years of music sales per format. The tooltip follows the mouse over the visualization, revealing the corresponding year and the breakdown of sales per format.
figure

View the tooltip following the mouse over the streamgraph and revealing the year and format breakdown. section 7.3.2

How D3.js in Action, Third Edition covers it

How deep it goes
Explains construction, SVG elements, pointer positioning, scale inversion, and data updates, stopping short of broader interaction types.
Examples
Demonstrates music-format sales over forty years with a guided line, year label, and per-format values.
What it assumes
Assumes familiarity with D3 building blocks, datasets, scales, and an existing streamgraph chart.
What you can do after
Build it from scratch by assembling and updating a D3 tooltip over an existing streamgraph.
How it connects
Connects streamgraphs, tooltips, mouse events, SVG text, data lookup, and D3 scales.

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.