Fix plotly#5381: wrong x/y positions in Sankey with isolated nodes#5548
Open
FredericoMendes10 wants to merge 1 commit intoplotly:mainfrom
Open
Fix plotly#5381: wrong x/y positions in Sankey with isolated nodes#5548FredericoMendes10 wants to merge 1 commit intoplotly:mainfrom
FredericoMendes10 wants to merge 1 commit intoplotly:mainfrom
Conversation
In Sankey diagrams with arrangement='fixed', Plotly.js builds an internal node array excluding isolated nodes (nodes not referenced by any valid link). The fixed-arrangement loop maps position array indices directly to this internal array, assuming a 1:1 correspondence. When isolated nodes appear before connected nodes in the original array, positions shift and are applied to the wrong nodes. Fix: in plotly/io/_kaleido.py, reorder per-node arrays before rendering so that isolated nodes appear last. This aligns the Plotly.js internal array with the x/y position arrays for all connected nodes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Link to issue
Closes #5381
Description of change
In Sankey diagrams with
arrangement='fixed', Plotly.js builds an internalnode array excluding isolated nodes. The fixed-arrangement loop maps position
array indices directly to this internal array assuming a 1:1 correspondence.
When isolated nodes appear before connected nodes in the original array,
positions shift and are applied to the wrong nodes.
Fix: in
plotly/io/_kaleido.py, reorder per-node arrays before rendering sothat isolated nodes appear last, aligning the Plotly.js internal array with
the x/y position arrays for all connected nodes.
Demo
https://youtu.be/y5ueoOPuKto
Testing strategy
Added a new test
test_sankey_isolated_nodes_fixed_arrangementthat creates aSankey diagram with isolated nodes before connected nodes and verifies the
rendered x/y positions are correct.
Additional information (optional)
N/A
Guidelines