import { Ref, useEffect, useRef } from 'preact/hooks' import * as vis from 'vis-network' import { DbEntry } from '../datas.ts' export function DbGraph({ db }: { db: DbEntry[] }) { const graph = useRef(null) useEffect(() => { drawDb({ db, graph }) }, []) return
} function drawDb({ db, graph }: { db: DbEntry[]; graph: Ref }) { const nodes = db.map(({ id, title, links }) => ({ id, label: title, value: links.length, })) const edges = db.map(({ id, links }) => links.map((link) => ({ from: id, to: link, value: id + link })) ).flat() return new vis.Network(graph.current!, { nodes, edges, }, { nodes: { shape: 'dot', }, }) }