From 685b259f6f7d3385b4dac26b9d0dd1699a6beada Mon Sep 17 00:00:00 2001 From: Richard Fogaca Nienkotter <63572350+richardfogaca@users.noreply.github.com> Date: Fri, 23 May 2025 17:52:58 -0300 Subject: [PATCH] fix(sankey): incorrect nodeValues (#33431) Co-authored-by: richardfn (cherry picked from commit 38868f9ff40a3a7be57c03a99751c56d732be4a0) --- .../src/Sankey/transformProps.ts | 22 ++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/superset-frontend/plugins/plugin-chart-echarts/src/Sankey/transformProps.ts b/superset-frontend/plugins/plugin-chart-echarts/src/Sankey/transformProps.ts index c3db5052bf1..9ef7389660a 100644 --- a/superset-frontend/plugins/plugin-chart-echarts/src/Sankey/transformProps.ts +++ b/superset-frontend/plugins/plugin-chart-echarts/src/Sankey/transformProps.ts @@ -73,13 +73,25 @@ export default function transformProps( })); // stores a map with the total values for each node considering the links - const nodeValues = new Map(); + const incomingFlows = new Map(); + const outgoingFlows = new Map(); + const allNodeNames = new Set(); + links.forEach(link => { const { source, target, value } = link; - const sourceValue = nodeValues.get(source) || 0; - const targetValue = nodeValues.get(target) || 0; - nodeValues.set(source, sourceValue + value); - nodeValues.set(target, targetValue + value); + allNodeNames.add(source); + allNodeNames.add(target); + incomingFlows.set(target, (incomingFlows.get(target) || 0) + value); + outgoingFlows.set(source, (outgoingFlows.get(source) || 0) + value); + }); + + const nodeValues = new Map(); + + allNodeNames.forEach(nodeName => { + const totalIncoming = incomingFlows.get(nodeName) || 0; + const totalOutgoing = outgoingFlows.get(nodeName) || 0; + + nodeValues.set(nodeName, Math.max(totalIncoming, totalOutgoing)); }); const tooltipFormatter = (params: CallbackDataParams) => {