2025-12-16 15:03:32 +07:00
|
|
|
import { useTranslations } from 'next-intl';
|
|
|
|
|
import { BarChart, Bar, Cell, XAxis, Tooltip } from 'recharts';
|
|
|
|
|
|
|
|
|
|
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 t = useTranslations('Global');
|
|
|
|
|
|
2025-12-16 20:33:06 +07:00
|
|
|
const strokeColor = "#dfdede24";
|
2025-12-16 15:03:32 +07:00
|
|
|
const strokeWidth = 1;
|
|
|
|
|
|
|
|
|
|
const renderBarWithPartialBorder = (props: BarShapeProps) => {
|
|
|
|
|
const { x, y, width, height, fill } = props;
|
2025-12-17 12:50:01 +07:00
|
|
|
const borderRadius = 10;
|
2025-12-16 15:03:32 +07:00
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<>
|
2025-12-17 12:50:01 +07:00
|
|
|
{/* Основной прямоугольник с закругленными углами */}
|
2025-12-16 15:03:32 +07:00
|
|
|
<rect
|
|
|
|
|
x={x}
|
|
|
|
|
y={y}
|
|
|
|
|
width={width}
|
|
|
|
|
height={height}
|
|
|
|
|
fill={fill}
|
2025-12-17 12:50:01 +07:00
|
|
|
rx={borderRadius}
|
|
|
|
|
ry={borderRadius}
|
2025-12-16 15:03:32 +07:00
|
|
|
/>
|
|
|
|
|
|
2025-12-17 12:50:01 +07:00
|
|
|
{/* Левая граница (центральная часть, без закруглений) */}
|
2025-12-16 15:03:32 +07:00
|
|
|
<line
|
|
|
|
|
x1={x}
|
2025-12-17 12:50:01 +07:00
|
|
|
y1={y + borderRadius}
|
2025-12-16 15:03:32 +07:00
|
|
|
x2={x}
|
2025-12-17 12:50:01 +07:00
|
|
|
y2={y + height - borderRadius}
|
2025-12-16 15:03:32 +07:00
|
|
|
/>
|
|
|
|
|
|
2025-12-17 12:50:01 +07:00
|
|
|
{/* Правая граница (центральная часть, без закруглений) */}
|
2025-12-16 15:03:32 +07:00
|
|
|
<line
|
|
|
|
|
x1={x + width}
|
2025-12-17 12:50:01 +07:00
|
|
|
y1={y + borderRadius}
|
2025-12-16 15:03:32 +07:00
|
|
|
x2={x + width}
|
2025-12-17 12:50:01 +07:00
|
|
|
y2={y + height - borderRadius}
|
2025-12-16 15:03:32 +07:00
|
|
|
/>
|
|
|
|
|
|
2025-12-17 12:50:01 +07:00
|
|
|
{/* Нижняя граница (прямая часть между закруглениями) */}
|
2025-12-16 15:03:32 +07:00
|
|
|
<line
|
2025-12-17 12:50:01 +07:00
|
|
|
x1={x + borderRadius}
|
2025-12-16 15:03:32 +07:00
|
|
|
y1={y + height}
|
2025-12-17 12:50:01 +07:00
|
|
|
x2={x + width - borderRadius}
|
2025-12-16 15:03:32 +07:00
|
|
|
y2={y + height}
|
2025-12-17 12:50:01 +07:00
|
|
|
/>
|
|
|
|
|
|
|
|
|
|
{/* Верхняя граница (прямая часть между закруглениями) */}
|
|
|
|
|
<line
|
|
|
|
|
x1={x + borderRadius}
|
|
|
|
|
y1={y}
|
|
|
|
|
x2={x + width - borderRadius}
|
|
|
|
|
y2={y}
|
2025-12-16 15:03:32 +07:00
|
|
|
/>
|
|
|
|
|
</>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const renderBarWithTopBorder = (props: BarShapeProps) => {
|
|
|
|
|
const { x, y, width, height, fill } = props;
|
|
|
|
|
const borderRadius = 10;
|
|
|
|
|
|
|
|
|
|
if (height <= 0 || width <= 0) return null;
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<>
|
2025-12-17 12:50:01 +07:00
|
|
|
{/* Основной прямоугольник с закругленными углами */}
|
|
|
|
|
<rect
|
|
|
|
|
x={x}
|
|
|
|
|
y={y}
|
|
|
|
|
width={width}
|
|
|
|
|
height={height}
|
2025-12-16 15:03:32 +07:00
|
|
|
fill={fill}
|
2025-12-17 12:50:01 +07:00
|
|
|
rx={borderRadius}
|
|
|
|
|
ry={borderRadius}
|
2025-12-16 15:03:32 +07:00
|
|
|
/>
|
|
|
|
|
|
2025-12-17 12:50:01 +07:00
|
|
|
{/* Левая граница (центральная часть, без закруглений) */}
|
2025-12-16 15:03:32 +07:00
|
|
|
<line
|
|
|
|
|
x1={x}
|
|
|
|
|
y1={y + borderRadius}
|
|
|
|
|
x2={x}
|
2025-12-17 12:50:01 +07:00
|
|
|
y2={y + height - borderRadius}
|
2025-12-16 15:03:32 +07:00
|
|
|
stroke={strokeColor}
|
|
|
|
|
strokeWidth={strokeWidth}
|
|
|
|
|
/>
|
|
|
|
|
|
2025-12-17 12:50:01 +07:00
|
|
|
{/* Правая граница (центральная часть, без закруглений) */}
|
2025-12-16 15:03:32 +07:00
|
|
|
<line
|
|
|
|
|
x1={x + width}
|
|
|
|
|
y1={y + borderRadius}
|
|
|
|
|
x2={x + width}
|
2025-12-17 12:50:01 +07:00
|
|
|
y2={y + height - borderRadius}
|
|
|
|
|
stroke={strokeColor}
|
|
|
|
|
strokeWidth={strokeWidth}
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
|
|
{/* Нижняя граница (прямая часть между закруглениями) */}
|
|
|
|
|
<line
|
|
|
|
|
x1={x + borderRadius}
|
|
|
|
|
y1={y + height}
|
|
|
|
|
x2={x + width - borderRadius}
|
2025-12-16 15:03:32 +07:00
|
|
|
y2={y + height}
|
|
|
|
|
stroke={strokeColor}
|
|
|
|
|
strokeWidth={strokeWidth}
|
|
|
|
|
/>
|
|
|
|
|
|
2025-12-17 12:50:01 +07:00
|
|
|
{/* Верхняя граница (прямая часть между закруглениями) */}
|
|
|
|
|
<line
|
|
|
|
|
x1={x + borderRadius}
|
|
|
|
|
y1={y}
|
|
|
|
|
x2={x + width - borderRadius}
|
|
|
|
|
y2={y}
|
2025-12-16 15:03:32 +07:00
|
|
|
stroke={strokeColor}
|
|
|
|
|
strokeWidth={strokeWidth}
|
|
|
|
|
/>
|
|
|
|
|
</>
|
2025-12-17 12:50:01 +07:00
|
|
|
);
|
2025-12-16 15:03:32 +07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<BarChart
|
2025-12-17 12:50:01 +07:00
|
|
|
style={{ width: '100%', maxWidth: '600px', maxHeight: '210px', aspectRatio: 1.618 }}
|
2025-12-16 15:03:32 +07:00
|
|
|
responsive
|
2025-12-17 12:50:01 +07:00
|
|
|
data={data}
|
|
|
|
|
barCategoryGap={15}
|
2025-12-16 15:03:32 +07:00
|
|
|
margin={{
|
|
|
|
|
top: 20,
|
|
|
|
|
right: 0,
|
|
|
|
|
left: 0,
|
|
|
|
|
bottom: 5,
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
{/* <Tooltip /> */}
|
|
|
|
|
<XAxis
|
|
|
|
|
dataKey="name"
|
|
|
|
|
stroke="#fff"
|
2025-12-16 20:26:17 +07:00
|
|
|
fontSize={12}
|
2025-12-16 15:03:32 +07:00
|
|
|
axisLine={false}
|
|
|
|
|
/>
|
|
|
|
|
<Bar
|
|
|
|
|
dataKey="checks"
|
|
|
|
|
stackId="a"
|
2025-12-16 20:26:17 +07:00
|
|
|
label={{ position: 'top', fill: '#fff', fontSize: 12 }}
|
2025-12-17 12:50:01 +07:00
|
|
|
radius={5}
|
2025-12-16 15:03:32 +07:00
|
|
|
shape={renderBarWithPartialBorder as any}
|
|
|
|
|
>
|
|
|
|
|
{data.map((_entry, index) => (
|
2025-12-17 12:50:01 +07:00
|
|
|
<Cell key={`cell-${index}`} fill={'#fff'} />
|
2025-12-16 15:03:32 +07:00
|
|
|
))}
|
|
|
|
|
</Bar>
|
|
|
|
|
<Bar
|
|
|
|
|
dataKey="violations"
|
2025-12-17 12:50:01 +07:00
|
|
|
stackId="b"
|
2025-12-16 20:26:17 +07:00
|
|
|
label={{ position: 'top', fill: '#fff', fontSize: 12 }}
|
2025-12-17 12:50:01 +07:00
|
|
|
radius={5}
|
2025-12-16 15:03:32 +07:00
|
|
|
shape={renderBarWithTopBorder as any}
|
|
|
|
|
>
|
|
|
|
|
{data.map((_entry, index) => (
|
2025-12-17 12:50:01 +07:00
|
|
|
<Cell key={`cell-${index}`} fill={'#f08c00'} />
|
2025-12-16 15:03:32 +07:00
|
|
|
))}
|
|
|
|
|
</Bar>
|
|
|
|
|
</BarChart>
|
|
|
|
|
);
|
|
|
|
|
};
|