import React, { useEffect, useState } from "react"; import Image from "next/image"; import { AlertCircle } from "lucide-react"; import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert"; import { Skeleton } from "@/components/ui/skeleton"; import { getGraphUrl } from "@/lib/simulation-service"; interface GraphViewerProps { simulation: any; parameters: any; graphType: string; fullscreen?: boolean; } export function GraphViewer({ simulation, parameters, graphType, fullscreen = false }: GraphViewerProps) { const [loading, setLoading] = useState(true); const [error, setError] = useState(null); const [graphUrl, setGraphUrl] = useState(null); useEffect(() => { const fetchGraph = async () => { try { setLoading(true); setError(null); const url = await getGraphUrl( simulation.id, parameters.numberNodes, parameters.failureRate, parameters.blockSize, parameters.netDegree, parameters.chi, parameters.run, graphType, ); setGraphUrl(url); } catch (err) { console.error("Error loading graph:", err); setError("Failed to load graph. Please try again later."); } finally { setLoading(false); } }; fetchGraph(); }, [simulation.id, parameters, graphType]); return (
{loading ? ( ) : error ? ( Error {error} ) : !graphUrl ? ( No data available No graph data available for the selected parameters. ) : ( {`${graphType} setError("Failed to load graph image.")} /> )}
); }