stackLayout
Compute stacked baselines from multiple data series.
stackLayout(series: number[][]): StackEntry[][]
series — Array of series, where each series is an array of numeric values. All series must have the same length (one value per category). The first series sits at the bottom (baseline 0), and each subsequent series stacks on top.
Returns — Array of series, each containing StackEntry objects with:
y0: number— Bottom baseline for this value.y1: number— Top edge for this value (y0 + value).
The output has the same shape as the input: result[seriesIndex][categoryIndex].
// Three categories, two series
const stacked = pathRite.stackLayout([
[10, 20, 30], // bottom series
[5, 10, 15], // stacked on top
]);
// stacked[0][0]: { y0: 0, y1: 10 }
// stacked[0][1]: { y0: 0, y1: 20 }
// stacked[1][0]: { y0: 10, y1: 15 }
// stacked[1][1]: { y0: 20, y1: 30 }
// Use with areaPathStacked for a stacked area chart
const scaleY = (v) => 200 - v * 4;
stacked.forEach((series, si) => {
const top = series.map((d, i) => [i * 100, scaleY(d.y1)]);
const bottom = series.map((d, i) => [i * 100, scaleY(d.y0)]);
const d = pathRite.areaPathStacked(top, bottom, { type: "MonotoneX" });
});