( graph: Dagre.graphlib.Graph, nodes: Node[], edges: Edge[], )
| 2 | import { Node, Edge } from "reactflow"; |
| 3 | |
| 4 | function getLayoutedElements( |
| 5 | graph: Dagre.graphlib.Graph, |
| 6 | nodes: Node[], |
| 7 | edges: Edge[], |
| 8 | ): { nodes: Node[]; edges: Edge[] } { |
| 9 | // Apply horizontal display settings to the graph |
| 10 | graph.setGraph({ rankdir: "LR", ranksep: 150 }); |
| 11 | |
| 12 | // Set edges and nodes for the entire graph |
| 13 | // Maybe we can apply a set height and width to all nodes here? |
| 14 | edges.forEach((edge) => graph.setEdge(edge.source, edge.target)); |
| 15 | nodes.forEach((node) => graph.setNode(node.id, node.id)); // What type am I supposed to put here? Why does this work? Wth is going on? |
| 16 | |
| 17 | // Apply the layout to the graph |
| 18 | Dagre.layout(graph); |
| 19 | |
| 20 | // Return the coordinates of the nodes |
| 21 | return { |
| 22 | nodes: nodes.map((node) => { |
| 23 | const { x, y } = graph.node(node.id); |
| 24 | |
| 25 | return { ...node, position: { x, y } }; |
| 26 | }), |
| 27 | edges, |
| 28 | }; |
| 29 | } |
| 30 | |
| 31 | export default getLayoutedElements; |
nothing calls this directly
no outgoing calls
no test coverage detected