mirror of
https://github.com/supabase/supabase.git
synced 2026-05-09 02:09:50 -04:00
06190d15b9
## Problem When you have many tables, it's hard to follow the relations between them in the Schema Visualiser ## Solution When selecting an edge (the line between tables), highlight it along with the related tables and columns to make it easier. Also, if there is enough space, display a popover showing the relation details ## Screencasts https://github.com/user-attachments/assets/11d35fa7-3674-4f13-b77f-8ebe25c66b04
46 lines
1.2 KiB
TypeScript
46 lines
1.2 KiB
TypeScript
import dagre from '@dagrejs/dagre'
|
|
import { Edge, Node, Position } from '@xyflow/react'
|
|
|
|
import { NODE_WIDTH } from './Nodes'
|
|
|
|
const NODE_SEP = 0
|
|
const NODE_ROW_HEIGHT = 200
|
|
|
|
export const getDagreGraphLayout = (nodes: Node[], edges: Edge[]) => {
|
|
const dagreGraph = new dagre.graphlib.Graph()
|
|
dagreGraph.setDefaultEdgeLabel(() => ({}))
|
|
dagreGraph.setGraph({
|
|
rankdir: 'LR',
|
|
ranksep: 200,
|
|
nodesep: NODE_SEP,
|
|
align: nodes.length <= 2 ? 'UL' : undefined,
|
|
})
|
|
|
|
nodes.forEach((node) => {
|
|
dagreGraph.setNode(node.id, {
|
|
width: NODE_WIDTH / 2,
|
|
height: NODE_ROW_HEIGHT / 2,
|
|
})
|
|
})
|
|
|
|
edges.forEach((edge) => dagreGraph.setEdge(edge.source, edge.target))
|
|
|
|
dagre.layout(dagreGraph)
|
|
|
|
nodes.forEach((node) => {
|
|
const nodeWithPosition = dagreGraph.node(node.id)
|
|
node.sourcePosition = Position.Right
|
|
node.targetPosition = Position.Left
|
|
// 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 }
|
|
}
|