import { useMemo } from 'react' import Plot from 'react-plotly.js' import type { ChartSpec } from '@/api' interface Props { spec: ChartSpec title?: string } export default function ChartPanel({ spec, title }: Props) { const darkLayout = useMemo(() => { const base = (spec.plotly_json?.layout ?? {}) as Record return { ...base, title: title || base.title || '', paper_bgcolor: 'rgba(0,0,0,0)', plot_bgcolor: 'rgba(0,0,0,0)', font: { color: '#e2e8f0', family: 'Inter, sans-serif', size: 12 }, xaxis: { ...((base.xaxis as object) ?? {}), gridcolor: '#374151', linecolor: '#374151', tickfont: { color: '#9ca3af' } }, yaxis: { ...((base.yaxis as object) ?? {}), gridcolor: '#374151', linecolor: '#374151', tickfont: { color: '#9ca3af' } }, margin: { l: 50, r: 20, t: 40, b: 50 }, legend: { font: { color: '#9ca3af' } }, } }, [spec, title]) if (spec.type === 'table' && spec.data && spec.columns) { return (
{spec.columns.map((col) => ( ))} {(spec.data as Record[]).slice(0, 100).map((row, i) => ( {(spec.columns ?? []).map((col) => ( ))} ))}
{col}
{String(row[col] ?? '')}
{(spec.data?.length ?? 0) > 100 && (

Showing 100 of {spec.data!.length} rows

)}
) } if (!spec.plotly_json) return null return ( } config={{ displayModeBar: true, responsive: true, displaylogo: false }} style={{ width: '100%', height: '320px' }} useResizeHandler /> ) }