import React from 'react'; import { useUserStore } from '@/store/userStore'; import { ResponsiveContainer, LineChart, Line, AreaChart, Area, BarChart, Bar, XAxis, YAxis, CartesianGrid, Tooltip, Legend, ReferenceLine, } from 'recharts'; interface SimulatorChartProps { data: any[]; type?: 'line' | 'area' | 'bar'; height?: number; lines?: Array<{ dataKey: string; color: string; name?: string; strokeDasharray?: string; type?: 'monotone' | 'linear'; dot?: boolean; fill?: boolean; }>; xDataKey?: string; showGrid?: boolean; showLegend?: boolean; showTooltip?: boolean; referenceLineY?: number; referenceLabel?: string; formatY?: (v: any) => string; formatX?: (v: any) => string; } const SimulatorChart: React.FC = ({ data, type = 'area', height = 300, lines = [], xDataKey = 'period', showGrid = true, showLegend = true, showTooltip = true, referenceLineY, referenceLabel, formatY, formatX, }) => { const { isDark } = useUserStore(); const gridColor = isDark ? 'rgba(255,255,255,0.04)' : 'rgba(0,0,0,0.04)'; const axisColor = isDark ? '#64748b' : '#94a3b8'; const tooltipBg = isDark ? '#1e1e2e' : '#ffffff'; const tooltipBorder = isDark ? '#2e2e3e' : '#e2e8f0'; const CustomTooltip = ({ active, payload, label }: any) => { if (!active || !payload?.length) return null; return (

{label}

{payload.map((entry: any, i: number) => (
{entry.name}: {formatY ? formatY(entry.value) : entry.value?.toLocaleString()}
))}
); }; const commonProps = { data, margin: { top: 5, right: 10, left: 5, bottom: 5 }, }; const commonAxisProps = { xAxis: ( ), yAxis: ( v >= 10000000 ? `${(v / 10000000).toFixed(0)} Cr` : v >= 100000 ? `${(v / 100000).toFixed(0)} L` : v.toLocaleString())} width={55} /> ), }; const renderLines = () => lines.map((line, i) => { if (type === 'area' || line.fill) { return ( ); } return ( ); }); if (type === 'bar') { return ( {showGrid && } {commonAxisProps.xAxis} {commonAxisProps.yAxis} {showTooltip && } />} {showLegend && } {lines.map((line, i) => ( ))} ); } return ( {lines.map((line, i) => ( ))} {showGrid && } {commonAxisProps.xAxis} {commonAxisProps.yAxis} {showTooltip && } />} {showLegend && } {referenceLineY !== undefined && ( )} {renderLines()} ); }; export default SimulatorChart;