function addNeighbors()

in packages-ext/recoil-devtools/src/utils/sankey/SankeyGraphLayout.js [181:213]


  function addNeighbors(
    node: Node<N, L>,
    direction: 'target' | 'source',
    depth: number,
  ) {
    const neighborLinks =
      direction === 'target' ? node.targetLinks : node.sourceLinks;
    const neighbors = compactArray(
      neighborLinks.map(link =>
        direction === 'target' ? link.target : link.source,
      ),
    );
    const newNodes = [];
    for (const neighbor of neighbors) {
      if (!nodesSet.has(neighbor)) {
        newNodes.push(neighbor);
        neighbor.depth = depth;
        direction === 'target'
          ? (depthDomain[1] = Math.max(depthDomain[1], depth))
          : (depthDomain[0] = Math.min(depthDomain[0], depth));
        nodesSet.add(neighbor);
      }
    }
    if (Math.abs(depth) < layoutOptions.depthOfField) {
      for (const neighbor of newNodes) {
        addNeighbors(
          neighbor,
          direction,
          depth + (direction === 'target' ? 1 : -1),
        );
      }
    }
  }