From de379e28bf04b286bfdd2eecd2b4a37d879ea556 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BB=D0=B5=D0=BA=D1=81=D0=B5=D0=B9=20=D0=A1=D0=B0?= =?UTF-8?q?=D0=B1=D0=B8=D0=BB=D0=B8=D0=BD?= Date: Mon, 13 Jul 2026 17:55:24 +0300 Subject: [PATCH] =?UTF-8?q?fix(charts):=20=D0=B5=D0=B4=D0=B8=D0=BD=D1=8B?= =?UTF-8?q?=D0=B9=20=D1=81=D1=82=D0=B8=D0=BB=D1=8C=20AreaChart=20=D1=81=20?= =?UTF-8?q?=D0=B3=D1=80=D0=B0=D0=B4=D0=B8=D0=B5=D0=BD=D1=82=D0=BE=D0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Общий AreaTrendChart для мониторинга и daily-графиков, StatisticSparklineCard на дашборде. Co-authored-by: Cursor --- src/components/AreaTrendChart.tsx | 68 +++++++++++++++++++++++ src/components/DailyLineChartCard.tsx | 28 +++------- src/components/StatisticSparklineCard.tsx | 65 ++++++++++++++++++++++ src/pages/monitoring/MonitoringPage.tsx | 24 +------- 4 files changed, 143 insertions(+), 42 deletions(-) create mode 100644 src/components/AreaTrendChart.tsx create mode 100644 src/components/StatisticSparklineCard.tsx diff --git a/src/components/AreaTrendChart.tsx b/src/components/AreaTrendChart.tsx new file mode 100644 index 0000000..7f1d45e --- /dev/null +++ b/src/components/AreaTrendChart.tsx @@ -0,0 +1,68 @@ +import React from 'react'; +import { + AreaChart, + Area, + XAxis, + YAxis, + CartesianGrid, + Tooltip, + Legend, + ResponsiveContainer, +} from 'recharts'; + +export interface AreaTrendSeries { + key: string; + color: string; + name: string; +} + +interface Props { + data: Record[]; + xKey: string; + series: AreaTrendSeries[]; + height?: number; + xMinTickGap?: number; + yAllowDecimals?: boolean; +} + +const AreaTrendChart: React.FC = ({ + data, + xKey, + series, + height = 280, + xMinTickGap = 30, + yAllowDecimals = true, +}) => ( + + + + {series.map((s) => ( + + + + + ))} + + + + + + + {series.map((s) => ( + + ))} + + +); + +export default AreaTrendChart; diff --git a/src/components/DailyLineChartCard.tsx b/src/components/DailyLineChartCard.tsx index 304d3f8..790faf2 100644 --- a/src/components/DailyLineChartCard.tsx +++ b/src/components/DailyLineChartCard.tsx @@ -1,16 +1,7 @@ import React from 'react'; import { Card, Col } from 'antd'; -import { - LineChart, - Line, - XAxis, - YAxis, - CartesianGrid, - Tooltip, - Legend, - ResponsiveContainer, -} from 'recharts'; import { DayCount } from '../types/api'; +import AreaTrendChart from './AreaTrendChart'; interface Props { title: string; @@ -32,16 +23,13 @@ const DailyLineChartCard: React.FC = ({ title, data, color, lg = 12 }) => return ( - - - - - - - - - - + ); diff --git a/src/components/StatisticSparklineCard.tsx b/src/components/StatisticSparklineCard.tsx new file mode 100644 index 0000000..200aa7b --- /dev/null +++ b/src/components/StatisticSparklineCard.tsx @@ -0,0 +1,65 @@ +import React from 'react'; +import { Card, Statistic } from 'antd'; +import { AreaChart, Area, XAxis, Tooltip } from 'recharts'; + +interface SparklinePoint { + date: string; + value: number; +} + +interface Props { + title: string; + value: number; + prefix?: React.ReactNode; + data?: SparklinePoint[]; + color?: string; + gradientId: string; +} + +const StatisticSparklineCard: React.FC = ({ + title, + value, + prefix, + data, + color = '#1890ff', + gradientId, +}) => ( + +
+ + {data && data.length > 0 && ( + + + + + + + + + `Дата: ${label}`} /> + + + )} +
+
+); + +export default StatisticSparklineCard; diff --git a/src/pages/monitoring/MonitoringPage.tsx b/src/pages/monitoring/MonitoringPage.tsx index aa814cb..8e76b56 100644 --- a/src/pages/monitoring/MonitoringPage.tsx +++ b/src/pages/monitoring/MonitoringPage.tsx @@ -1,18 +1,9 @@ import React, { useEffect, useMemo, useState } from 'react'; import { Card, Col, Row, Select, Table, Tabs } from 'antd'; -import { - LineChart, - Line, - XAxis, - YAxis, - CartesianGrid, - Tooltip, - Legend, - ResponsiveContainer, -} from 'recharts'; import dayjs from 'dayjs'; import { useMetricsStore, NodeMetric } from '../../store/metricsStore'; import { monitoringApi } from '../../api/monitoringApi'; +import AreaTrendChart from '../../components/AreaTrendChart'; const NODE_COLORS = ['#1677ff', '#52c41a', '#fa8c16', '#eb2f96', '#722ed1', '#13c2c2']; const TIME_RANGES = [ @@ -51,18 +42,7 @@ const MetricChart: React.FC<{ data: ReturnType; lines: Array<{ key: string; color: string; name: string }>; }> = ({ data, lines }) => ( - - - - - - - - {lines.map((line) => ( - - ))} - - + ); const MonitoringPage: React.FC = () => {