import React, { useState } from 'react'; import ForceGraph2D from 'react-force-graph-2d'; import { useGraphData } from './useGraphData'; import { GraphNode, GraphLink } from '../../types'; interface GraphExplorerProps { initialId: string; initialType: string; } export function GraphExplorer({ initialId, initialType }: GraphExplorerProps) { const [depth, setDepth] = useState(1); const { data, isLoading, error } = useGraphData(initialId, initialType, depth); const getNodeColor = (node: GraphNode) => { const label = node.labels?.[0] || ''; switch (label) { case 'Anime': return '#ff7f0e'; case 'Character': return '#2ca02c'; case 'Game': return '#1f77b4'; case 'Movie': return '#d62728'; case 'Manga': return '#9467bd'; default: return '#7f7f7f'; } }; const getLabel = (node: GraphNode): string => { const val = node.properties?.title || node.properties?.name || node.id || 'Unknown'; if (Array.isArray(val)) { return val.join(', '); } return String(val); }; return (

Graph Explorer

setDepth(Number(e.target.value))} aria-label="Profondeur du graphe" className="w-32 cursor-pointer" />
{isLoading && (
Loading graph data...
)} {error && (
Error: {error.message}
)}
(node as GraphNode).labels?.[0]} nodeColor={(node) => getNodeColor(node as GraphNode)} nodeLabel={(node) => getLabel(node as GraphNode)} linkLabel={(link) => (link as GraphLink).type} backgroundColor="#111827" />
); }