import { useCallback, useRef, useState } from "react"; import { importFigureHdf5, FigureView, type FigureState } from "numbl/graphics"; export function App() { const [figure, setFigure] = useState(null); const [fileName, setFileName] = useState(null); const [error, setError] = useState(null); const [loading, setLoading] = useState(false); const [dragOver, setDragOver] = useState(false); const inputRef = useRef(null); const loadBytes = useCallback(async (bytes: Uint8Array, name: string) => { setLoading(true); setError(null); try { const fig = await importFigureHdf5(bytes); setFigure(fig); setFileName(name); } catch (e) { setError(e instanceof Error ? e.message : String(e)); setFigure(null); setFileName(null); } finally { setLoading(false); } }, []); const loadFile = useCallback( async (file: File) => loadBytes(new Uint8Array(await file.arrayBuffer()), file.name), [loadBytes] ); const loadSample = useCallback(async () => { setLoading(true); setError(null); try { const resp = await fetch(`${import.meta.env.BASE_URL}sample.h5`); await loadBytes(new Uint8Array(await resp.arrayBuffer()), "sample.h5"); } catch (e) { setError(e instanceof Error ? e.message : String(e)); setLoading(false); } }, [loadBytes]); return (

numbl figure viewer

Open a .h5 figure file exported from{" "} numbl and view it here. Rendering uses numbl’s own figure components.

inputRef.current?.click()} onDragOver={e => { e.preventDefault(); setDragOver(true); }} onDragLeave={() => setDragOver(false)} onDrop={e => { e.preventDefault(); setDragOver(false); const f = e.dataTransfer.files[0]; if (f) loadFile(f); }} > { const f = e.target.files?.[0]; if (f) loadFile(f); }} /> {loading ? "Loading…" : fileName ? `Loaded: ${fileName} — click or drop to open another` : "Click to choose, or drag a .h5 figure file here"}
{error &&
Failed to open file: {error}
} {figure && (
)}
); }