fix(sankey): incorrect nodeValues (#33431)

Co-authored-by: richardfn <richard.fogaca@appsilon.com>
This commit is contained in:
Richard Fogaca Nienkotter
2025-05-23 17:52:58 -03:00
committed by GitHub
parent 8013b32f0e
commit 38868f9ff4

View File

@@ -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<string, number>();
const incomingFlows = new Map<string, number>();
const outgoingFlows = new Map<string, number>();
const allNodeNames = new Set<string>();
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<string, number>();
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) => {