'use client'; import { useMemo, useState } from 'react'; import { useGraphStore } from '@/store/graph'; import { entityColor } from '@/lib/constants'; import { cn } from '@/lib/utils'; export function GraphLegend() { const data = useGraphStore((s) => s.data); const visibleTypes = useGraphStore((s) => s.visibleTypes); const toggleType = useGraphStore((s) => s.toggleType); const [open, setOpen] = useState(true); const typeCounts = useMemo(() => { const counts: Record = {}; data.nodes.forEach((n) => (counts[n.type] = (counts[n.type] || 0) + 1)); return counts; }, [data.nodes]); const sortedTypes = useMemo( () => Object.entries(typeCounts).sort((a, b) => b[1] - a[1]), [typeCounts] ); return (
{open && ( )}
); }