function layoutModelGraph()

in toolings/tfjs-debugger/src/app/layout_generator/layout_generator.worker.ts [30:52]


function layoutModelGraph(modelGraph: ModelGraph) {
  const graph = new dagre.graphlib.Graph<ModelGraphNode>();
  // Separation between nodes.
  graph.setGraph({nodesep: 10});
  // We don't need to show edge labels.
  graph.setDefaultEdgeLabel(() => ({}));

  // Add all nodes and edges to the dagre graph.
  for (const node of Object.values(modelGraph)) {
    graph.setNode(node.id, node);

    if (node.inputNodeIds) {
      for (const parentNodeId of node.inputNodeIds) {
        if (modelGraph[parentNodeId]) {
          graph.setEdge(parentNodeId, node.id);
        }
      }
    }
  }

  // Layout.
  dagre.layout(graph);
}