Make every stage transition accountable, including dropouts and unobserved destinations.
Sankey diagrams: reconcile flows before sizing links
A link represents a transfer
A Sankey diagram uses link width to encode quantity moving between stages. The visual claim is stronger than a list of counts: a unit leaving one stage must either enter a named next stage, exit the process, or remain unobserved under a declared cutoff. If 81 claims enter triage and 47 reach review, the other 34 need a visible destination, not an unexplained gap. Unit-of-analysis rules prevent one claim with multiple events from becoming several flows.
Give nodes stage-specific identities
The same label at two stages does not necessarily describe the same state. Use stable stage and state IDs, deduplicate by entity and transition, and decide how repeated or backward transitions are handled. A diagram that assumes a directed acyclic process can fail when work returns to triage. In that case, either aggregate one chosen journey window or use another graph view that represents loops. Network diagrams can show cycles, though they answer a different question.
Check conservation at intermediate stages
For a closed interval, incoming and outgoing measured quantities at a transit state should balance after explicit additions, losses and stock change. If 47 enter review and 42 leave, five may still be in progress; add a pending exit or annotate the stock. For a live interval, arrivals and departures can differ because the cohort has not matured. Attach extraction time and observation horizon to the flow, and never compare incoming of one cohort to outgoing of another. Provisional periods need separate handling.
Make ordering and scale inspectable
Link crossing is partly a layout choice. Reordering nodes can reduce crossings without changing the data, so visual proximity must not be treated as a causal relation. Show quantities, units and denominators in text or a companion table. Fixed link colors can track origin across stages, but blending may obscure a small branch; direct labels or hover summaries help. Accessible alternatives should list source, target and value. Large graphs may be better as a transition table.
Worked contract
from collections import defaultdict
def reconcile_flow(
links: list[tuple[str, str, int]], transit_nodes: set[str]
) -> dict[str, tuple[int, int]]:
incoming = defaultdict(int)
outgoing = defaultdict(int)
for source, target, quantity in links:
if not source or not target or quantity < 0:
raise ValueError("invalid flow link")
outgoing[source] += quantity
incoming[target] += quantity
balances = {node: (incoming[node], outgoing[node]) for node in transit_nodes}
if any(entered != left for entered, left in balances.values()):
raise ValueError(f"unreconciled transit node: {balances}")
return balances
journey = [("intake", "review", 47),
("intake", "unobserved-exit", 34),
("review", "closed", 42),
("review", "pending", 5)]
assert reconcile_flow(journey, {"review"}) == {"review": (47, 47)}
assert sum(value for source, _, value in journey if source == "intake") == 81Performance and operating cost
For E links and T transit nodes, accumulation and reconciliation take O(E + T) expected time and O(V) space for V encountered nodes. Layout can be substantially more expensive and depends on the rendering algorithm; do not mix that cost with the inexpensive accounting check. A real workflow also checks duplicate entity transitions and whether stock change belongs in the diagram. The example treats all links as counts in one cohort and one period.
Common Mistakes
- Hiding exits to make the main path look complete.
- Counting multiple events from one entity as separate stage transfers.
- Balancing one period's arrivals against another period's departures.
- Assuming node position or link crossing has business meaning.
Validation drill
Model 81 claims through intake, review and closure. Add a pending branch and an unobserved exit; fail the reconciliation when either is removed, then render a transition table beside the flow.
Read next
- Aggregation grain and denominator: make every plotted mark auditable
- Network graphs: define nodes and edges before trusting the layout
- Time-series charts: distinguish missing days, zeros and provisional periods
- Accessible charts: encode meaning without relying on color alone
