Fix sankey nodes clipped at bottom edge with user-positioned nodes#7725
Open
jdonaldson wants to merge 2 commits intoplotly:masterfrom
Open
Fix sankey nodes clipped at bottom edge with user-positioned nodes#7725jdonaldson wants to merge 2 commits intoplotly:masterfrom
jdonaldson wants to merge 2 commits intoplotly:masterfrom
Conversation
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.
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.
Overview
When sankey nodes are positioned near
y=1.0viatrace.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) computesyCenter = y * heightand places the node around that center. Whenyis close to 1.0 and the node has non-trivial height,y1exceedsheight.Fix: Clamp
yCenterso the node stays within[0, height].Problem 2:
resolveCollisionsTopToBottompushes nodes out of boundsWhen
arrangement="snap", collision resolution pushes overlapping nodes downward but never checks if the last node'sy1exceedsheight. 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
test/image/mocks/sankey_x_y_bottom_clipping.jsonwith nodes positioned neary=0.95sankey_test.jsthat verifies all node rects stay within the sankey area boundsNotes