import { Bar, BarChart, LabelList, Legend, ResponsiveContainer, Tooltip, XAxis, YAxis, } from 'recharts'; import { useState } from 'react'; import type { HydrogenMonthlyPoint } from '../../types'; import { buildMonthDrillPayload, formatYuan as fmtYuan, type OverviewDrillPayload, type OverviewDrillRequest, type OverviewScope, } from '../model'; import { OverviewDrillDialog } from './OverviewDrillDialog'; type MonthlyChartPoint = HydrogenMonthlyPoint & { monthLabel: string }; interface MonthlyChartsProps { activeYear: number; monthly: HydrogenMonthlyPoint[]; monthlyDual: MonthlyChartPoint[]; scope?: OverviewScope; scopeLabel?: string | null; onDrillRequest?: (request: OverviewDrillRequest) => void; } export function MonthlyCharts({ activeYear, monthly, monthlyDual, scope = 'global', scopeLabel, onDrillRequest }: MonthlyChartsProps) { const [drill, setDrill] = useState(null); const openMonthPoint = (point: MonthlyChartPoint | undefined) => { if (!point) return; if (onDrillRequest) onDrillRequest({ kind: 'month', key: point.month, label: `${point.month} 月度经营明细` }); else setDrill(buildMonthDrillPayload(point)); }; const openMonthFromChart = (state: unknown) => { openMonthPoint((state as { activePayload?: { payload?: MonthlyChartPoint }[] } | undefined)?.activePayload?.[0]?.payload); }; const openMonthFromBar = (entry: unknown) => { openMonthPoint((entry as { payload?: MonthlyChartPoint } | undefined)?.payload); }; const scopeText = scope === 'station' && scopeLabel ? ` · ${scopeLabel}` : ''; return ( <> {monthly.length > 0 && (
{activeYear} 年月度加氢量{scopeText}
单位:Kg
[`${Number(v ?? 0).toLocaleString('zh-CN', { maximumFractionDigits: 0 })} Kg`, '加氢量']} labelFormatter={(d) => `${d}`} contentStyle={{ borderRadius: 12, fontSize: 12 }} cursor={{ fill: 'rgba(34, 211, 238, 0.06)' }} /> { const total = Number(value ?? 0); return total >= 1000 ? `${(total / 1000).toFixed(1)}k` : total.toFixed(0); }} fill="#475569" fontSize={10} fontWeight={700} />
)} {monthly.length > 0 && (
{activeYear} 年月度收支对比{scopeText}
单位:元
{ const f = fmtYuan(Number(v ?? 0)); return [`¥${f.value} ${f.unit}`, name]; }} contentStyle={{ borderRadius: 12, fontSize: 12 }} cursor={{ fill: 'rgba(148, 163, 184, 0.06)' }} />
)} setDrill(null)} /> ); }