function enhanceGraph()

in src/SankeyDiagram.js [413:432]


function enhanceGraph(graph) {
  graph.nodes.forEach(node => {
    const sourceLinksSum = (node.sourceLinks || []).reduce(
      (sum, link) => sum + link.value,
      0,
    );
    node.terminalValue = Math.max(node.value - sourceLinksSum, 0);
  });
  graph.links.forEach(link => {
    link.valueSourceRelative = (link.value || 0) / get(link, 'source.value', 0);
    link.valueTargetRelative = (link.value || 0) / get(link, 'target.value', 0);
  });

  graph.maxDepth = maxBy(graph.nodes, 'depth');
  graph.maxDepth = graph.nodes.reduce(
    (max, node) => Math.max(node.depth || 0, max),
    0,
  );
  return graph;
}