'use client' import { useTranslations, useLocale } from 'next-intl'; import { useMemo } from 'react'; import { BarChart, Bar, Cell, XAxis, Tooltip } from 'recharts'; import { pluralize } from '@/app/lib/pluralize'; import { useStoreWithDevtools } from '@/app/stores/useStoreWithDevtools'; type Files = { data: { name: string, checks: number, violations: number }[] } interface BarShapeProps { x: number; y: number; width: number; height: number; fill: string; radius?: number[]; } export const StackedBarChart = ({ data }: Files) => { const locale = useLocale(); const t = useTranslations('Global'); const CHECKS_COLOR = '#6366f1'; const VIOLATIONS_COLOR = '#f08c00' const BORDER_RADIUS = 5; const STROKE_COLOR = "#dfdede24"; const STROKE_WIDTH = 1; /* const { totalChecks, totalViolations } = useMemo(() => ({ totalChecks: data.reduce((sum, item) => sum + (item.checks || 0), 0), totalViolations: data.reduce((sum, item) => sum + (item.violations || 0), 0) }), [data]); */ const totalChecks = useStoreWithDevtools(s => s.value1); const totalViolations = useStoreWithDevtools(s => s.value2); const renderBarWithPartialBorder = (props: BarShapeProps) => { const { x, y, width, height, fill } = props; return ( <> {/* Основной прямоугольник с закругленными углами */} {/* Левая граница (центральная часть, без закруглений) */} {/* Правая граница (центральная часть, без закруглений) */} {/* Нижняя граница (прямая часть между закруглениями) */} {/* Верхняя граница (прямая часть между закруглениями) */} ); }; const renderBarWithTopBorder = (props: BarShapeProps) => { const { x, y, width, height, fill } = props; if (height <= 0 || width <= 0) return null; return ( <> {/* Основной прямоугольник с закругленными углами */} {/* Левая граница (центральная часть, без закруглений) */} {/* Правая граница (центральная часть, без закруглений) */} {/* Нижняя граница (прямая часть между закруглениями) */} {/* Верхняя граница (прямая часть между закруглениями) */} ); }; const pluralizeCheks = (number: number) => { const translate = [t('check'), t('checks-few'), t('checks')]; return pluralize(number, translate[0], translate[1], translate[2], locale); }; const pluralizeViolations = (number: number) => { const translate = [t('violation'), t('violations-few'), t('violations')]; return pluralize(number, translate[0], translate[1], translate[2], locale); }; return ( <>
{/* */} {data.map((_entry, index) => ( ))} {data.map((_entry, index) => ( ))}
{totalChecks} {pluralizeCheks(totalChecks)}
{totalViolations} {pluralizeViolations(totalViolations)}
); };