Use a centered stack for shape exploration, but give readers a separate way to inspect the total.
Streamgraphs: preserve totals behind a moving baseline
The baseline is a layout choice
A streamgraph stacks nonnegative category values over time around a moving or centered baseline. Its flowing shape can help reveal broad category shifts, but the vertical position of a layer is partly an artifact of the baseline calculation. Layer thickness represents value; the upper edge alone does not. Do not label the vertical axis like an ordinary zero-based stacked area chart unless it actually has a fixed zero. Stacked composition explains why categories and their denominator must be stable enough to compare.
Totals still need a view
Centering a total of 47 and a total of 188 both around the same midpoint can make the chart attractive while hiding the operational difference. Include a separate total line, a compact table or a conventional zero-based stacked view when volume matters. A streamgraph is a poor sole view for audit questions such as whether all categories reconcile to the source total. Waterfall reconciliation handles additive changes with a more explicit baseline. For each time bin, validate that layer values sum to the reported total before calculating any layout offset.
Order controls readability
A layer buried in the middle may be easier to follow than one whose boundaries both move erratically, but changing the order between frames makes categories impossible to track. Select a stable order and color identity for the whole time range. If categories enter or leave, distinguish true zero from missing data; an absent category record should not silently become a zero-thickness layer. Missing periods and provisional bins require an explicit display state, even in a decorative-looking flow chart.
Keep the raw table accessible
Layer thickness is hard to read precisely, particularly on a narrow viewport. Provide a table with period, category, value, total and any excluded share. Label categories directly where possible and offer keyboard-accessible inspection for the rest. Interactive chart access should preserve each period and category ID when focus moves. Export the stacking order and baseline algorithm so an updated chart library cannot silently change the shape while the underlying observations stay fixed.
Worked contract
from math import isfinite
def centered_stack(categories: list[str],
periods: list[dict[str, float]]
) -> list[dict[str, tuple[float, float]]]:
if not categories or len(categories) != len(set(categories)):
raise ValueError("ordered categories must be unique")
output = []
for period in periods:
if set(period) != set(categories):
raise ValueError("each period needs every category, including real zeros")
if any(not isfinite(value) or value < 0 for value in period.values()):
raise ValueError("values must be finite and nonnegative")
baseline = -sum(period.values()) / 2
layers = {}
for category in categories:
upper = baseline + period[category]
layers[category] = (baseline, upper)
baseline = upper
output.append(layers)
return output
service_mix = centered_stack(
["routine", "urgent"],
[{"routine": 47, "urgent": 59}, {"routine": 81, "urgent": 97}],
)
assert service_mix[0] == {
"routine": (-53.0, -6.0), "urgent": (-6.0, 53.0)
}
assert service_mix[1]["urgent"][1] == 89.0Performance and operating cost
For T periods and C categories, validation and centered stacking take O(TC) time and O(TC) output space. This code uses a simple centered baseline, not an optimized wiggle offset; those two layouts differ. It requires a complete category set per period and rejects negative measures. Keep the original values and totals for accessibility and reconciliation. For large C, crowded labels and thin layers may make small multiples or a ranked table clearer.
Common Mistakes
- Reading the moving layer boundary as a zero-based value.
- Using a centered streamgraph alone when the decision depends on total volume.
- Changing category order across periods and making colors switch identity.
- Replacing missing category records with zero without a recorded rule.
Validation drill
Show 47 reporting periods and eight service classes. Reconcile each total, hold category order fixed and place a separate total-volume line beside the centered streamgraph.
