-
Notifications
You must be signed in to change notification settings - Fork 19.8k
[Feature] Sankey: allow disabling automatic node sorting while still using positioning iterations #21561
Description
What problem does this feature solve?
Currently, the Sankey layout algorithm automatically sorts nodes within each depth level to optimize link crossings and visual clarity. While this behavior is generally helpful, it makes it difficult to enforce a custom semantic ordering of nodes within the same level.
In certain use cases, the order of nodes within a level carries meaning (for example: logical flow, ranking, process stages, or domain-specific grouping). When the layout algorithm reorders nodes, this meaning can be lost or the diagram may become harder to interpret.
One workaround is to set layoutIterations: 0, which prevents the collision resolution steps that modify node positioning. However, this also disables desirable layout improvements such as:
- vertical alignment optimization
- improved edge positioning
- collision resolution adjustments
- balanced spacing between nodes
As a result, all nodes in each level become aligned at the top, producing a suboptimal layout that often requires manual positioning adjustments.
This feature would allow developers to:
- preserve the input order of nodes within each depth level
- still benefit from automatic layout improvements
- maintain predictable and stable diagram structures across updates
- apply domain-specific ordering logic without losing layout quality
This capability is particularly useful for dashboards, reports, and analytical tools where the vertical order communicates meaning beyond topology alone.
The goal is to provide a way to disable intra-level sorting while keeping all other layout optimizations active.
What does the proposed API look like?
Add a new optional configuration property on Sankey series:
series: {
type: "sankey",
sortNodes: false
}Default behavior
sortNodes: trueThis ensures full backward compatibility and preserves the current layout behavior unless explicitly disabled.
Behavior when sortNodes: false
When disabled:
- the vertical order of nodes within each depth level follows the original order defined in
data - the layout algorithm still performs:
- node depth calculation
- node scaling
- collision resolution
- Gauss–Seidel relaxation
- link positioning
- link thickness calculation
Only the per-level sorting step is skipped.
Example
option = {
series: {
type: "sankey",
sortNodes: false,
data: [
{ name: "A" },
{ name: "B" },
{ name: "C" }
],
links: [
{ source: "A", target: "C", value: 5 },
{ source: "B", target: "C", value: 3 }
]
}
}In this case, nodes A, B, C remain in the specified order within their levels, while layout optimization still improves spacing and link placement.
This feature provides a balance between:
- deterministic layout control
- automatic visual optimization
It solves a common need when working with structured or semantically ordered data, without requiring manual layout or disabling iterative refinement entirely.
The API remains minimal and consistent with existing configuration patterns in ECharts, and provides a nicer alternative to setting layoutIterations to 0.