MCPcopy Create free account
hub / github.com/WardAnalytics/WardGraph / getLayoutedElements

Function getLayoutedElements

src/components/graph/layout.tsx:4–29  ·  view source on GitHub ↗
(
  graph: Dagre.graphlib.Graph,
  nodes: Node[],
  edges: Edge[],
)

Source from the content-addressed store, hash-verified

2import { Node, Edge } from "reactflow";
3
4function 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
31export default getLayoutedElements;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected