Stalactite plots
Hierarchical data with two quantities per node: an additive one (here sales — a parent is the sum of its children) and a proportional one (here profit margin — a parent is the average of its children, weighted by sales).
Make one from your own CSV file →
How to read it
- Width is sales: every box is as wide as its share of its parent.
- Height is profit margin. Children hang directly below their parent.
- The average line under each group mirrors the parent's height onto its children: a child reaching below the line has an above-average margin, one ending above it is below average.
- Hover any box for its exact values; labels are only drawn where they fit.
Usage
import { stalactitePlot } from "d3-stalactite";
d3.select("svg").call(stalactitePlot, {
data, // {name, children} … leaves {name, add_val, ratio_val}
width: 960,
height: 500,
valueNames: ["Sales", "Profit margin"],
});
// Or just the layout, in the style of d3.treemap():
import { stalactite } from "d3-stalactite";
const { nodes, lines } = stalactite().size([960, 500])(data);