From 555061b179b8ec034cb70f9a2dd6c823ced0f637 Mon Sep 17 00:00:00 2001 From: soryu Date: Tue, 23 Dec 2025 14:43:23 +0000 Subject: Add file body and initial tool call system --- .../src/components/charts/ChartRenderer.tsx | 181 +++++++++++++++++++++ 1 file changed, 181 insertions(+) create mode 100644 makima/frontend/src/components/charts/ChartRenderer.tsx (limited to 'makima/frontend/src/components/charts') diff --git a/makima/frontend/src/components/charts/ChartRenderer.tsx b/makima/frontend/src/components/charts/ChartRenderer.tsx new file mode 100644 index 0000000..276b170 --- /dev/null +++ b/makima/frontend/src/components/charts/ChartRenderer.tsx @@ -0,0 +1,181 @@ +import { useMemo } from "react"; +import { + LineChart, + Line, + BarChart, + Bar, + PieChart, + Pie, + AreaChart, + Area, + XAxis, + YAxis, + CartesianGrid, + Tooltip, + Legend, + ResponsiveContainer, + Cell, +} from "recharts"; +import type { ChartType } from "../../lib/api"; + +interface ChartRendererProps { + chartType: ChartType; + data: Record[]; + title?: string; + config?: Record; +} + +// Default color palette +const COLORS = [ + "#9bc3ff", + "#ff9b9b", + "#9bffb3", + "#ffeb9b", + "#d49bff", + "#9bfff0", + "#ff9beb", + "#b3ff9b", +]; + +export function ChartRenderer({ + chartType, + data, + title, + config, +}: ChartRendererProps) { + // Extract data keys (excluding 'name' which is used for labels) + const dataKeys = useMemo(() => { + if (data.length === 0) return []; + const keys = Object.keys(data[0]).filter((key) => key !== "name"); + return keys; + }, [data]); + + // Get colors from config or use defaults + const colors = (config?.colors as string[]) || COLORS; + + const renderChart = () => { + switch (chartType) { + case "line": + return ( + + + + + + + {dataKeys.map((key, i) => ( + + ))} + + ); + + case "bar": + return ( + + + + + + + {dataKeys.map((key, i) => ( + + ))} + + ); + + case "area": + return ( + + + + + + + {dataKeys.map((key, i) => ( + + ))} + + ); + + case "pie": + // For pie charts, use the first data key as value + const valueKey = dataKeys[0] || "value"; + return ( + + + `${name}: ${((percent ?? 0) * 100).toFixed(0)}%` + } + labelLine={{ stroke: "#9bc3ff" }} + > + {data.map((_, i) => ( + + ))} + + + + + ); + + default: + return
Unknown chart type: {chartType}
; + } + }; + + return ( +
+ {title && ( +

{title}

+ )} +
+ + {renderChart()} + +
+
+ ); +} -- cgit v1.2.3