"use client" import React, { useState, useCallback } from 'react' import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card' import { Tabs, TabsContent, TabsList, TabsTrigger } from '@/components/ui/tabs' import { Badge } from '@/components/ui/badge' import { Button } from '@/components/ui/button' import { Switch } from '@/components/ui/switch' import { Zap, Cpu, Eye, Settings } from 'lucide-react' import { ForceGraphWrapper } from './force-graph-wrapper' import { PyGraphistryViewer } from './pygraphistry-viewer' import type { Triple } from '@/utils/text-processing' interface GraphData { nodes: Array<{ id: string name: string group?: string [key: string]: any }> links: Array<{ source: string target: string name: string [key: string]: any }> } interface EnhancedGraphVisualizationProps { graphData?: GraphData jsonData?: any // For backward compatibility with existing ForceGraphWrapper triples?: Triple[] fullscreen?: boolean layoutType?: string highlightedNodes?: string[] onError?: (error: Error) => void } export function EnhancedGraphVisualization({ graphData, jsonData, triples, fullscreen = false, layoutType, highlightedNodes, onError }: EnhancedGraphVisualizationProps) { const [activeTab, setActiveTab] = useState<'threejs' | 'pygraphistry'>('threejs') const [gpuPreferred, setGpuPreferred] = useState(false) // Convert triples to graph data format if needed const processedGraphData = React.useMemo(() => { if (graphData) { return graphData } if (triples && triples.length > 0) { const nodes = new Map() const links: any[] = [] triples.forEach((triple, index) => { // Triple interface has simple string properties const subjectId = triple.subject const subjectName = triple.subject const objectId = triple.object const objectName = triple.object const predicateName = triple.predicate // Add nodes if (!nodes.has(subjectId)) { nodes.set(subjectId, { id: subjectId, name: subjectName, group: 'entity' }) } if (!nodes.has(objectId)) { nodes.set(objectId, { id: objectId, name: objectName, group: 'entity' }) } // Add link links.push({ source: subjectId, target: objectId, name: predicateName }) }) return { nodes: Array.from(nodes.values()), links: links } } return null }, [graphData, triples]) const handleTabChange = useCallback((value: string) => { setActiveTab(value as 'threejs' | 'pygraphistry') }, []) const handleError = useCallback((error: Error) => { console.error('Graph visualization error:', error) if (onError) { onError(error) } }, [onError]) const nodeCount = processedGraphData?.nodes?.length || jsonData?.nodes?.length || 0 const linkCount = processedGraphData?.links?.length || jsonData?.links?.length || 0 return (
Knowledge Graph Visualization
{nodeCount} nodes {linkCount} edges
{ setGpuPreferred(checked) if (checked && activeTab === 'threejs') { setActiveTab('pygraphistry') } }} />
Client-Side (Three.js) WebGPU Server-Side (PyGraphistry) GPU
{processedGraphData ? ( ) : (
No graph data available for PyGraphistry visualization
Please load graph data to enable GPU-accelerated visualization
)}
) }