Skip to content

Fix plotly#5381: wrong x/y positions in Sankey with isolated nodes#5548

Open
FredericoMendes10 wants to merge 1 commit intoplotly:mainfrom
FredericoMendes10:issue-5381
Open

Fix plotly#5381: wrong x/y positions in Sankey with isolated nodes#5548
FredericoMendes10 wants to merge 1 commit intoplotly:mainfrom
FredericoMendes10:issue-5381

Conversation

@FredericoMendes10
Copy link
Copy Markdown

Link to issue

Closes #5381

Description of change

In Sankey diagrams with arrangement='fixed', Plotly.js builds an internal
node 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 so
that 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_arrangement that creates a
Sankey diagram with isolated nodes before connected nodes and verifies the
rendered x/y positions are correct.

Additional information (optional)

N/A

Guidelines

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Explicit node coordinates (x/y positions) not fully respected in Sankey diagram

1 participant