Home / Function/ getLayoutedElementsViaDagre() — supabase Function Reference

getLayoutedElementsViaDagre() — supabase Function Reference

Architecture documentation for the getLayoutedElementsViaDagre() function in Schemas.utils.ts from the supabase codebase.

Entity Profile

Dependency Diagram

graph TD
  6afd133c_f4fa_d02d_b814_82224fed4bf4["getLayoutedElementsViaDagre()"]
  2f23e199_5215_d9cd_0558_237d0dc2652f["SchemaGraph()"]
  2f23e199_5215_d9cd_0558_237d0dc2652f -->|calls| 6afd133c_f4fa_d02d_b814_82224fed4bf4
  c873669a_f88c_bb16_2076_ffa1fc0fc1a7["getGraphDataFromTables()"]
  c873669a_f88c_bb16_2076_ffa1fc0fc1a7 -->|calls| 6afd133c_f4fa_d02d_b814_82224fed4bf4
  style 6afd133c_f4fa_d02d_b814_82224fed4bf4 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

apps/studio/components/interfaces/Database/Schemas/Schemas.utils.ts lines 162–200

export const getLayoutedElementsViaDagre = (nodes: Node[], edges: Edge[]) => {
  const dagreGraph = new dagre.graphlib.Graph()
  dagreGraph.setDefaultEdgeLabel(() => ({}))
  dagreGraph.setGraph({
    rankdir: 'LR',
    align: 'UR',
    nodesep: NODE_SEP,
    ranksep: RANK_SEP,
  })

  nodes.forEach((node) => {
    dagreGraph.setNode(node.id, {
      width: TABLE_NODE_WIDTH / 2,
      height: (TABLE_NODE_ROW_HEIGHT / 2) * (node.data.columns.length + 1), // columns + header
    })
  })

  edges.forEach((edge) => {
    dagreGraph.setEdge(edge.source, edge.target)
  })

  dagre.layout(dagreGraph)

  nodes.forEach((node) => {
    const nodeWithPosition = dagreGraph.node(node.id)
    node.targetPosition = Position.Left
    node.sourcePosition = Position.Right
    // We are shifting the dagre node position (anchor=center center) to the top left
    // so it matches the React Flow node anchor point (top left).
    node.position = {
      x: nodeWithPosition.x - nodeWithPosition.width / 2,
      y: nodeWithPosition.y - nodeWithPosition.height / 2,
    }

    return node
  })

  return { nodes, edges }
}

Subdomains

Frequently Asked Questions

What does getLayoutedElementsViaDagre() do?
getLayoutedElementsViaDagre() is a function in the supabase codebase.
What calls getLayoutedElementsViaDagre()?
getLayoutedElementsViaDagre() is called by 2 function(s): SchemaGraph, getGraphDataFromTables.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free