import { useMemo } from 'react'; import { useTradingMetricsHistory } from '../../api/tradingHooks'; import { Card, LoadingSpinner } from '../../components/ui'; import { LineChart, Line, BarChart, Bar, AreaChart, Area, XAxis, YAxis, Tooltip, ResponsiveContainer, CartesianGrid, Cell, } from 'recharts'; const tooltipStyle = { backgroundColor: '#1e293b', border: '1px solid #334155', borderRadius: 8, }; export function PerformanceCharts() { const { data: snapshots, isLoading } = useTradingMetricsHistory(); const chartData = useMemo(() => { if (!snapshots) return []; return snapshots.map((s) => ({ date: new Date(s.snapshot_date).toLocaleDateString(undefined, { month: 'short', day: 'numeric' }), portfolioValue: s.portfolio_value, cumulativeReturn: (s.cumulative_return ?? 0) * 100, dailyReturn: (s.daily_return ?? 0) * 100, drawdown: (s.current_drawdown_pct ?? 0) * 100, maxDrawdown: (s.max_drawdown ?? 0) * 100, })); }, [snapshots]); if (isLoading) return ; if (chartData.length === 0) { return (

No performance history available yet

); } return (
{/* Cumulative P&L */}

Cumulative P&L

`${v.toFixed(1)}%`} /> [`${Number(value).toFixed(2)}%`, 'Cumulative Return']} />
{/* Daily Returns */}

Daily Returns

`${v.toFixed(1)}%`} /> [`${Number(value).toFixed(2)}%`, 'Daily Return']} /> {chartData.map((entry, i) => ( = 0 ? '#22c55e' : '#ef4444'} /> ))}
{/* Drawdown */}

Drawdown

`${v.toFixed(1)}%`} /> [`${Number(value).toFixed(2)}%`, 'Drawdown']} />
); }