-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Respect explicit node x/y positions in fixed-arrangement Sankey #7826
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
kyo5uke
wants to merge
2
commits into
plotly:master
Choose a base branch
from
kyo5uke:sankey-fixed-node-positions
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+18
−9
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| - Respect explicit `node.x`/`node.y` positions in Sankey traces that contain unlinked or grouped nodes, by indexing the forced positions by each node's `pointNumber` instead of its array position [[#7826](https://github.com/plotly/plotly.js/pull/7826)] |
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
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -244,15 +244,23 @@ function sankeyModel(layout, d, traceIndex) { | |||||
|
|
||||||
| // Force node position | ||||||
| if(trace.node.x.length && trace.node.y.length) { | ||||||
| for(i = 0; i < Math.min(trace.node.x.length, trace.node.y.length, graph.nodes.length); i++) { | ||||||
| if(trace.node.x[i] && trace.node.y[i]) { | ||||||
| var pos = [trace.node.x[i] * width, trace.node.y[i] * height]; | ||||||
| graph.nodes[i].x0 = pos[0] - nodeThickness / 2; | ||||||
| graph.nodes[i].x1 = pos[0] + nodeThickness / 2; | ||||||
|
|
||||||
| var nodeHeight = graph.nodes[i].y1 - graph.nodes[i].y0; | ||||||
| graph.nodes[i].y0 = pos[1] - nodeHeight / 2; | ||||||
| graph.nodes[i].y1 = pos[1] + nodeHeight / 2; | ||||||
| // graph.nodes omits unlinked nodes and may have transient group | ||||||
| // children unshifted to its front, so its order does not match | ||||||
| // trace.node.x/y. Index the explicit positions by each node's | ||||||
| // original pointNumber rather than by array position. | ||||||
| for(i = 0; i < graph.nodes.length; i++) { | ||||||
| var forcedNode = graph.nodes[i]; | ||||||
| if(forcedNode.partOfGroup) continue; | ||||||
|
|
||||||
| var p = forcedNode.pointNumber; | ||||||
| if(trace.node.x[p] && trace.node.y[p]) { | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think 0 coords will get dropped with the existing check (preexisting bug). Let's update it. This should take care of
Suggested change
|
||||||
| var pos = [trace.node.x[p] * width, trace.node.y[p] * height]; | ||||||
| forcedNode.x0 = pos[0] - nodeThickness / 2; | ||||||
| forcedNode.x1 = pos[0] + nodeThickness / 2; | ||||||
|
|
||||||
| var nodeHeight = forcedNode.y1 - forcedNode.y0; | ||||||
| forcedNode.y0 = pos[1] - nodeHeight / 2; | ||||||
| forcedNode.y1 = pos[1] + nodeHeight / 2; | ||||||
| } | ||||||
| } | ||||||
| if(trace.arrangement === 'snap') { | ||||||
|
|
||||||
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.