Skip to content

Fix sankey nodes clipped at bottom edge with user-positioned nodes#7725

Open
jdonaldson wants to merge 2 commits intoplotly:masterfrom
jdonaldson:fix-sankey-bottom-clipping
Open

Fix sankey nodes clipped at bottom edge with user-positioned nodes#7725
jdonaldson wants to merge 2 commits intoplotly:masterfrom
jdonaldson:fix-sankey-bottom-clipping

Conversation

@jdonaldson
Copy link

Overview

When sankey nodes are positioned near y=1.0 via trace.node.x/trace.node.y, they can extend past the bottom of the plot area and get visually clipped. This happens in two places:

Problem 1: No clamping in "Force node position"

The node centering code (render.js ~line 254) computes yCenter = y * height and places the node around that center. When y is close to 1.0 and the node has non-trivial height, y1 exceeds height.

Fix: Clamp yCenter so the node stays within [0, height].

Problem 2: resolveCollisionsTopToBottom pushes nodes out of bounds

When arrangement="snap", collision resolution pushes overlapping nodes downward but never checks if the last node's y1 exceeds height. Dense columns near the bottom edge get pushed past the visible area.

Fix: After resolving collisions, check if the last node in each column extends past height. If so, shift the entire column upward.

Test plan

  • Added mock data file test/image/mocks/sankey_x_y_bottom_clipping.json with nodes positioned near y=0.95
  • Added test "prevents nodes from being clipped at the bottom edge" in sankey_test.js that verifies all node rects stay within the sankey area bounds
  • Ran full sankey test suite — new test passes, no regressions (pre-existing hover/drag failures unrelated)

Notes

  • Draftlog will be added once PR number is assigned

When nodes are positioned near y=1.0 via trace.node.x/y, they can extend
past the bottom of the plot area. Additionally, resolveCollisionsTopToBottom
pushes overlapping nodes downward without checking if the last node exceeds
the available height.

This fix:
1. Clamps yCenter when positioning nodes so they stay within [0, height]
2. Shifts columns upward after collision resolution if the bottom node
   extends past the plot height

Fixes bottom clipping in sankey diagrams with arrangement="snap" and
user-specified node positions.
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.

1 participant