// modules/dashboard/components/ChartWidget.tsx import React from "react"; import { LineChart, Line, BarChart, Bar, AreaChart, Area, PieChart, Pie, Cell, XAxis, YAxis, CartesianGrid, Tooltip, ResponsiveContainer, Legend, } from "recharts"; import { FaChartLine, FaChartBar, FaChartArea, FaChartPie, FaCog, FaEye, FaEyeSlash, } from "react-icons/fa"; import { motion } from "framer-motion"; import type { ChartWidget as ChartWidgetType, MetricData } from "../types"; interface ChartWidgetProps { widget: ChartWidgetType; data: MetricData[]; onEdit: () => void; onToggleVisibility: () => void; } // Все возможные уровни логов (метрики) const METRICS = ["INFO", "WARN", "ERROR", "DEBUG"]; // Цвета для каждой метрики const METRIC_COLORS: Record = { INFO: "#10b981", // зеленый WARN: "#f59e0b", // оранжевый ERROR: "#ef4444", // красный DEBUG: "#3b82f6", // синий }; export const ChartWidget: React.FC = ({ widget, data, onEdit, onToggleVisibility, }) => { const renderChart = () => { if (!data || !Array.isArray(data) || data.length === 0) { return (
Нет данных
); } const normalizedData = data.map((point) => { const normalized: MetricData = { timestamp: point.timestamp }; METRICS.forEach((metric) => { normalized[metric] = point[metric] || 0; }); return normalized; }); const commonProps = { data: normalizedData, margin: { top: 5, right: 10, left: 0, bottom: 5 }, }; switch (widget.type) { case "line": return ( {METRICS.map((metric) => ( ))} ); case "bar": return ( {METRICS.map((metric) => ( ))} ); case "area": return ( {METRICS.map((metric) => ( ))} ); case "pie": // Для круговой диаграммы берем последнюю точку const lastPoint = normalizedData[normalizedData.length - 1]; const pieData = METRICS.map((metric) => ({ name: metric, value: lastPoint[metric] || 0, })).filter((item) => Number(item.value) > 0); return ( {pieData.map((entry, index) => ( ))} ); default: return null; } }; const getIcon = () => { switch (widget.type) { case "line": return ; case "bar": return ; case "area": return ; case "pie": return ; default: return null; } }; return (
{getIcon()}

{widget.title}

{renderChart()}
); };