feat(sankey): support disabling node sorting. close #21561#21562
feat(sankey): support disabling node sorting. close #21561#21562konewka17 wants to merge 3 commits intoapache:masterfrom
Conversation
|
Thanks for your contribution! Please DO NOT commit the files in dist, i18n, and ssr/client/dist folders in a non-release pull request. These folders are for release use only. |
|
Document changes are required in this PR. Please also make a PR to apache/echarts-doc for document changes and update the issue id in the PR description. When the doc PR is merged, the maintainers will remove the |
Ovilia
left a comment
There was a problem hiding this comment.
Thanks for your contribution.
I think the name of the new option could comply with sunburst.sort, whose default value is 'desc'. You don't need to implement 'asc' or function value in this PR until such requirement is raised up. When it is set to be null, it won't sort. When it's undefined, it should be taken as 'desc' for compatibility.
|
The changes brought by this PR can be previewed at: https://echarts.apache.org/examples/editor?version=PR-21562@6418ca2 |
…st.sort method. Only null and `desc` implemented as suggested
|
Nice suggestion @Ovilia, I've implemented it. Documentation is updated accordingly |
Brief Information
This pull request is in the type of:
What does this PR do?
Adds a new Sankey series option
sortNodes?: booleanthat allows disabling automatic node sorting within each depth level while preserving all other layout optimizations.Fixed issues
Details
Before: What was the problem?
Currently, the Sankey layout automatically sorts nodes within each depth level to reduce edge crossings and improve visual clarity. While this generally produces good layouts, it prevents developers from enforcing a custom semantic ordering of nodes within the same level.
In many practical use cases, node order within a level conveys meaning (e.g. ranking, process steps, grouped categories, or domain-specific logic). The automatic sorting step overrides the input order, making diagrams harder to interpret or inconsistent with external logic.
A common workaround is to set:
layoutIterations: 0However, this disables useful layout behaviors such as:
As a result, nodes in each depth column remain aligned at the top, often producing visually suboptimal layouts.
Developers currently lack a way to preserve node order while still benefiting from layout optimization.
After: How does it behave after the fixing?
A new optional series configuration property is introduced:
sortNodes?: booleanDefault:
sortNodes: trueWhen set to:
the layout algorithm:
This enables deterministic node ordering without sacrificing layout quality.
A visual test case was added to
test/sankey.htmldemonstrating the preserved ordering behavior.Implementation details:
sortNodes?: booleantoSankeySeriesOptiontrueto ensure backward compatibilitysortNodesinto the layout pipelineresolveCollisionsDocument Info
One of the following should be checked.
Misc
Security Checking
ZRender Changes
Related test cases or examples to use the new APIs
Added manual visual test in:
Test demonstrates that:
preserves input node ordering within each depth level while keeping layout iterations active.
Merging options
Other information
This feature provides a minimal API addition that enables deterministic ordering of nodes within Sankey depth levels, while preserving existing layout improvements.
It serves as a practical alternative to
layoutIterations: 0, which disables useful layout refinements.Demonstration of the fix