import { PieChart, Pie, Cell, Tooltip, ResponsiveContainer, } from 'recharts'; import type { ByCategoryItem } from '@family-budget/shared'; import { formatAmount } from '../utils/format'; import { useMediaQuery } from '../hooks/useMediaQuery'; interface Props { data: ByCategoryItem[]; } const COLORS = [ '#3b82f6', '#ef4444', '#10b981', '#f59e0b', '#8b5cf6', '#ec4899', '#06b6d4', '#84cc16', '#f97316', '#6366f1', '#14b8a6', '#e11d48', '#0ea5e9', '#a855f7', '#22c55e', ]; const rubFormatter = new Intl.NumberFormat('ru-RU', { style: 'currency', currency: 'RUB', maximumFractionDigits: 0, }); export function CategoryChart({ data }: Props) { const isMobile = useMediaQuery('(max-width: 600px)'); const chartHeight = isMobile ? 250 : 300; if (data.length === 0) { return
Нет данных за период
; } const chartData = data.map((item) => ({ name: item.categoryName, value: Math.abs(item.amount) / 100, txCount: item.txCount, share: item.share, })); return (
`${name} ${(share * 100).toFixed(0)}%` } labelLine > {chartData.map((_, idx) => ( ))} rubFormatter.format(value)} /> {data.map((item, idx) => ( ))}
Категория Сумма Операций Доля
{item.categoryName} {formatAmount(item.amount)} {item.txCount} {(item.share * 100).toFixed(1)}%
); }