From 82af33e80ed08dd5d88dec4a41978865f50eac94 Mon Sep 17 00:00:00 2001 From: water <672684719@qq.com> Date: Wed, 12 Aug 2026 02:07:54 +0800 Subject: [PATCH 1/5] fix(sankey): transpose node.x/node.y scaling for vertical orientation (Fixes #7947) --- src/traces/sankey/render.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/traces/sankey/render.js b/src/traces/sankey/render.js index a07d18a9c9e..42af645fd1d 100644 --- a/src/traces/sankey/render.js +++ b/src/traces/sankey/render.js @@ -246,7 +246,9 @@ function sankeyModel(layout, d, traceIndex) { 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]; + var pos = horizontal + ? [trace.node.x[i] * width, trace.node.y[i] * height] + : [trace.node.x[i] * height, trace.node.y[i] * width]; graph.nodes[i].x0 = pos[0] - nodeThickness / 2; graph.nodes[i].x1 = pos[0] + nodeThickness / 2; @@ -802,9 +804,13 @@ function persistFinalNodePositions(d, gd) { for(var i = 0; i < d.graph.nodes.length; i++) { var nodeX = (d.graph.nodes[i].x0 + d.graph.nodes[i].x1) / 2; var nodeY = (d.graph.nodes[i].y0 + d.graph.nodes[i].y1) / 2; - x.push(nodeX / d.figure.width); - y.push(nodeY / d.figure.height); - } + if(d.trace.orientation === 'h') { + x.push(nodeX / d.figure.width); + y.push(nodeY / d.figure.height); + } else { + x.push(nodeX / d.figure.height); + y.push(nodeY / d.figure.width); + } Registry.call('_guiRestyle', gd, { 'node.x': [x], 'node.y': [y] From c4412b15cb2bda45f99416dc3a76cdf5c064f052 Mon Sep 17 00:00:00 2001 From: Cameron DeCoster Date: Mon, 24 Aug 2026 18:20:39 -0600 Subject: [PATCH 2/5] Add missing paren and use existing prop Co-authored-by: Cameron DeCoster --- src/traces/sankey/render.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/traces/sankey/render.js b/src/traces/sankey/render.js index 42af645fd1d..31783d9d3e1 100644 --- a/src/traces/sankey/render.js +++ b/src/traces/sankey/render.js @@ -804,13 +804,14 @@ function persistFinalNodePositions(d, gd) { for(var i = 0; i < d.graph.nodes.length; i++) { var nodeX = (d.graph.nodes[i].x0 + d.graph.nodes[i].x1) / 2; var nodeY = (d.graph.nodes[i].y0 + d.graph.nodes[i].y1) / 2; - if(d.trace.orientation === 'h') { + if(d.horizontal) { x.push(nodeX / d.figure.width); y.push(nodeY / d.figure.height); } else { x.push(nodeX / d.figure.height); y.push(nodeY / d.figure.width); } + } Registry.call('_guiRestyle', gd, { 'node.x': [x], 'node.y': [y] From 3721a68a60ee4558189a69febd6f975058e1c520 Mon Sep 17 00:00:00 2001 From: Cameron DeCoster Date: Mon, 16 Nov 2026 11:02:30 -0700 Subject: [PATCH 3/5] Update attribute descriptions --- src/traces/sankey/attributes.js | 14 ++++++++++++-- src/types/generated/schema.d.ts | 4 ++-- test/plot-schema.json | 4 ++-- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/traces/sankey/attributes.js b/src/traces/sankey/attributes.js index 11003ada21d..60c5fefbbbb 100644 --- a/src/traces/sankey/attributes.js +++ b/src/traces/sankey/attributes.js @@ -110,12 +110,22 @@ var attrs = (module.exports = overrideAll( x: { valType: 'data_array', dflt: [], - description: 'The normalized horizontal position of the node.' + description: [ + 'The normalized position of the node center along the flow axis, measured from the source end.', + 'For `orientation` *h* the flow axis is horizontal.', + 'For `orientation` *v* the flow axis is vertical.', + 'With `direction` *reversed* the source end is the right or bottom edge.' + ].join(' ') }, y: { valType: 'data_array', dflt: [], - description: 'The normalized vertical position of the node.' + description: [ + 'The normalized position of the node center across the flow axis.', + 'For `orientation` *h* the value counts down from the top edge.', + 'For `orientation` *v* the value counts from the left edge.', + 'The value does not depend on `direction`.' + ].join(' ') }, color: { valType: 'color', diff --git a/src/types/generated/schema.d.ts b/src/types/generated/schema.d.ts index 8a855665e73..76d74b39ac6 100644 --- a/src/types/generated/schema.d.ts +++ b/src/types/generated/schema.d.ts @@ -7078,12 +7078,12 @@ export interface SankeyData { */ thickness?: number; /** - * The normalized horizontal position of the node. + * The normalized position of the node center along the flow axis, measured from the source end. For `orientation` *h* the flow axis is horizontal. For `orientation` *v* the flow axis is vertical. With `direction` *reversed* the source end is the right or bottom edge. * @default [] */ x?: Datum[] | Datum[][] | TypedArray; /** - * The normalized vertical position of the node. + * The normalized position of the node center across the flow axis. For `orientation` *h* the value counts down from the top edge. For `orientation` *v* the value counts from the left edge. The value does not depend on `direction`. * @default [] */ y?: Datum[] | Datum[][] | TypedArray; diff --git a/test/plot-schema.json b/test/plot-schema.json index 4d51312e82d..8d50cd671ea 100644 --- a/test/plot-schema.json +++ b/test/plot-schema.json @@ -52393,13 +52393,13 @@ "valType": "number" }, "x": { - "description": "The normalized horizontal position of the node.", + "description": "The normalized position of the node center along the flow axis, measured from the source end. For `orientation` *h* the flow axis is horizontal. For `orientation` *v* the flow axis is vertical. With `direction` *reversed* the source end is the right or bottom edge.", "dflt": [], "editType": "calc", "valType": "data_array" }, "y": { - "description": "The normalized vertical position of the node.", + "description": "The normalized position of the node center across the flow axis. For `orientation` *h* the value counts down from the top edge. For `orientation` *v* the value counts from the left edge. The value does not depend on `direction`.", "dflt": [], "editType": "calc", "valType": "data_array" From 464bfa8d763c84c45306358fb07bf51fc1acd6f2 Mon Sep 17 00:00:00 2001 From: Cameron DeCoster Date: Mon, 16 Nov 2026 11:05:09 -0700 Subject: [PATCH 4/5] Add test --- test/jasmine/tests/sankey_test.js | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/test/jasmine/tests/sankey_test.js b/test/jasmine/tests/sankey_test.js index d82ecdf9296..ca6b43f6d59 100644 --- a/test/jasmine/tests/sankey_test.js +++ b/test/jasmine/tests/sankey_test.js @@ -437,6 +437,36 @@ describe('sankey tests', function () { .then(done, done.fail); }); + it('scales node.x and node.y by the transposed extents for orientation v', async () => { + const nodeX = [0.2, 0.8]; + const nodeY = [0.5, 0.5]; + await Plotly.newPlot( + gd, + [ + { + type: 'sankey', + orientation: 'v', + arrangement: 'freeform', + node: { x: nodeX, y: nodeY }, + link: { source: [0], target: [1], value: [1] } + } + ], + { width: 900, height: 300, margin: { l: 0, r: 0, t: 0, b: 0 } } + ); + + // For 'v', the layout space carries the flow along x and spans [height, width] + d3SelectAll('.sankey .sankey-node').each((d) => { + const i = d.node.pointNumber; + expect((d.node.x0 + d.node.x1) / 2).toBeCloseTo(nodeX[i] * 300, 3); + expect((d.node.y0 + d.node.y1) / 2).toBeCloseTo(nodeY[i] * 900, 3); + }); + + // A drag writes back every node, so the node that stays put must keep its input coordinates + await drag({ node: document.getElementsByClassName('sankey-node').item(0), dpos: [0, 20] }); + expect(gd._fullData[0].node.x[1]).toBeCloseTo(nodeX[1], 3); + expect(gd._fullData[0].node.y[1]).toBeCloseTo(nodeY[1], 3); + }); + it('Plotly.deleteTraces with two traces removes the deleted plot', function (done) { var mockCopy = Lib.extendDeep({}, mock); var mockCopy2 = Lib.extendDeep({}, mockDark); From 18b7c867ec88abf4c83547b29c08e64c73364e9a Mon Sep 17 00:00:00 2001 From: Cameron DeCoster Date: Mon, 16 Nov 2026 11:29:08 -0700 Subject: [PATCH 5/5] Add draftlog --- draftlogs/7957_fix.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 draftlogs/7957_fix.md diff --git a/draftlogs/7957_fix.md b/draftlogs/7957_fix.md new file mode 100644 index 00000000000..ecf8da62315 --- /dev/null +++ b/draftlogs/7957_fix.md @@ -0,0 +1 @@ + - Fix `node.x` and `node.y` scaling for vertical `sankey` traces [[#7957](https://github.com/plotly/plotly.js/pull/7957)], with thanks to @waterWang for the contribution!