import React, { useEffect, useState, useRef } from 'react'; import ReactEChartsCore from 'echarts-for-react'; import * as echarts from 'echarts'; import { useChart } from '../api/hooks'; import { useUIStore } from '../store/ui'; import { getChartType } from '../lib/chartTypes'; interface Props { cellId: string; config: Record; } export function ChartCellView({ cellId, config }: Props) { const [chartSpec, setChartSpec] = useState | null>(null); const [chartType, setChartType] = useState(config.chartType || ''); const { create, loading, error } = useChart(); const { addError } = useUIStore(); const containerRef = useRef(null); useEffect(() => { if (config.chartType && config.params) { loadChart(config.chartType, config.params); } }, [config]); const loadChart = async (type: string, params: Record) => { const result = await create(type, params); if (result) { setChartSpec(result.spec); setChartType(result.chart_type); } else if (error) { addError(`Chart error: ${error}`); } }; if (!chartSpec && !loading) { const ct = getChartType(config.chartType || ''); return (

{ct ? `${ct.label} — use the Visualize tab to configure` : 'Use the Visualize tab to create charts'}

); } return (
{loading && (
Computing chart...
)} {chartSpec && (
)} {error &&

{error}

}
); }