Skip to content

fix(sankey): transpose node.x/node.y scaling for vertical orientation (Fixes #7947) - #7957

Open
waterWang wants to merge 1 commit into
plotly:masterfrom
waterWang:fix/sankey-node-xy-orientation
Open

fix(sankey): transpose node.x/node.y scaling for vertical orientation (Fixes #7947)#7957
waterWang wants to merge 1 commit into
plotly:masterfrom
waterWang:fix/sankey-node-xy-orientation

Conversation

@waterWang

Copy link
Copy Markdown

Problem

For vertical Sankey traces (orientation: 'v'), user-supplied node.x / node.y are normalized against the wrong extent. The d3-sankey layout space always carries the flow along its x axis, but for vertical orientation that space is transposed onto the screen. When the plotting area is non-square, nodes are placed outside the bounding box and the values written back after a drag can exceed the documented [0, 1] range.

Root cause

In src/traces/sankey/render.js, sankeyModel():

sankey.size(horizontal ? [width, height] : [height, width]);   // (1) correctly transposed
...
var pos = [trace.node.x[i] * width, trace.node.y[i] * height]; // (2) NOT transposed

The user coordinates at (2) are scaled by the un-transposed extents, while the d3-sankey layout at (1) uses the transposed extents. The same asymmetry exists in the write-back path persistFinalNodePositions().

Fix

  1. In sankeyModel(): scale node.x by the flow-axis extent and node.y by the cross-axis extent, matching the sankey.size() transposition
  2. In persistFinalNodePositions(): divide by the same transposed extents on write-back

Closes #7947

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.

[BUG]: sankey: node.x / node.y are normalized against the wrong extent when orientation: 'v'

1 participant