function computeNodeStructure()

in app/assets/javascripts/sankey.js [283:332]


  function computeNodeStructure() {
    var nodeStack = [], 
        index = 0;

    nodes.forEach(function(node) {
      if (!node.index) {
        connect(node);
      }
      
    });

    function connect(node) {
      node.index = index++;
      node.lowIndex = node.index;
      node.onStack = true;
      nodeStack.push(node);

      if (node.sourceLinks) {
        node.sourceLinks.forEach(function(sourceLink){
          var target = sourceLink.target;
          if (!target.hasOwnProperty('index')) {
            connect(target);
            node.lowIndex = Math.min(node.lowIndex, target.lowIndex);
          } else if (target.onStack) {
            node.lowIndex = Math.min(node.lowIndex, target.index);
          }
        });

        if (node.lowIndex === node.index) {
          var component = [], currentNode;
          do { 
            currentNode = nodeStack.pop()
            currentNode.onStack = false;
            component.push(currentNode);
          } while (currentNode != node);
          components.push({
            root: node,
            scc: component
          });
        }
      }
    }

    components.forEach(function(component, i){
      component.index = i;
      component.scc.forEach(function(node) {
        node.component = i;
      });
    });
  }