"use client"; import { motion } from "motion/react"; import { ChartFrame } from "@/components/charts/chart-frame"; export type Entity = { id: string; title: string; fields: string[]; x: number; y: number; w?: number }; export type Relation = { from: string; to: string; label?: string }; type ERDiagramProps = { entities: Entity[]; relations: Relation[]; width?: number; height?: number; className?: string; }; const ROW_H = 24; const HEAD_H = 30; /** ERDiagram — entity cards (title + field rows) reveal; relations draw between card centers with a cardinality label. */ export function ERDiagram({ entities, relations, width = 720, height = 420, className }: ERDiagramProps) { const byId = new Map(entities.map((e) => [e.id, e])); const dims = (e: Entity) => ({ w: e.w ?? 160, h: HEAD_H + e.fields.length * ROW_H }); const center = (e: Entity) => { const { w, h } = dims(e); return { x: e.x + w / 2, y: e.y + h / 2 }; }; return ( {({ inView, reduce }) => ( <> {relations.map((r, i) => { const a = byId.get(r.from); const b = byId.get(r.to); if (!a || !b) return null; const ca = center(a); const cb = center(b); return ( {r.label && ( {r.label} )} ); })} {entities.map((e, i) => { const { w, h } = dims(e); return ( {e.title} {e.fields.map((f, fi) => ( {f} ))} ); })} )} ); }