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) => {