From 6ab9cd1c75aef4b7f422fa1ed9123c91310edbf0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=B5=D1=80=D0=B2=D0=BE=D0=B2=20=D0=90=D1=80=D1=82?= =?UTF-8?q?=D0=B5=D0=BC?= Date: Mon, 22 Jun 2026 03:19:56 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9E=D0=B1=D0=BD=D0=BE=D0=B2=D0=B8=D0=BB=20?= =?UTF-8?q?=D0=BA=D0=BE=D0=BD=D1=82=D1=80=D0=B0=D0=BA=D1=82=20=D0=BF=D0=BE?= =?UTF-8?q?=20=D0=BF=D0=BE=D0=BB=D1=83=D1=87=D0=B5=D0=BD=D0=B8=D1=8E=20?= =?UTF-8?q?=D0=B4=D0=B0=D0=BD=D0=BD=D1=8B=D1=85=20=D0=B4=D0=BB=D1=8F=20?= =?UTF-8?q?=D0=B3=D1=80=D0=B0=D1=84=D0=B8=D0=BA=D0=B0.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/cloud.ts | 2 +- src/entities/history/types.ts | 23 ++++--------- src/features/edge-detail/EdgeHistoryPage.tsx | 2 +- .../edge-detail/components/ArchiveView.tsx | 1 + src/features/history-chart/HistoryChart.tsx | 14 ++++---- .../history-chart/historyChartOptions.ts | 9 ++---- .../history-chart/historyChartSeries.ts | 32 +++++++++---------- 7 files changed, 35 insertions(+), 48 deletions(-) diff --git a/src/api/cloud.ts b/src/api/cloud.ts index 5f042e1..ab891eb 100644 --- a/src/api/cloud.ts +++ b/src/api/cloud.ts @@ -5,6 +5,6 @@ export type { EdgeItem, EdgeResponse } from '../entities/edge/types'; export { getHealth } from '../entities/health/api'; export type { HealthResponse } from '../entities/health/types'; export { getHistory } from '../entities/history/api'; -export type { HistoryPoint, HistoryRequest, HistoryResponse, HistorySeries } from '../entities/history/types'; +export type { HistoryPoint, HistoryRequest, HistoryResponse } from '../entities/history/types'; export { getTags } from '../entities/tag/api'; export type { TagItem, TagResponse } from '../entities/tag/types'; diff --git a/src/entities/history/types.ts b/src/entities/history/types.ts index bd4f0e8..77b1af1 100644 --- a/src/entities/history/types.ts +++ b/src/entities/history/types.ts @@ -1,24 +1,13 @@ export type HistoryPoint = { - t: number; - min: number; - avg: number; - max: number; - count: number; -}; - -export type HistorySeries = { - edge: string; - tag: string; - points: HistoryPoint[]; + time: string; + min_value: number; + avg_value: number; + max_value: number; + point_count: number; }; export type HistoryResponse = { - edge: string; - tag: string; - granulate: string; - series: HistorySeries[]; - from: string; - to: string; + rows: HistoryPoint[]; }; export type HistoryRequest = { diff --git a/src/features/edge-detail/EdgeHistoryPage.tsx b/src/features/edge-detail/EdgeHistoryPage.tsx index 4c79391..498f77c 100644 --- a/src/features/edge-detail/EdgeHistoryPage.tsx +++ b/src/features/edge-detail/EdgeHistoryPage.tsx @@ -78,7 +78,7 @@ export function EdgeHistoryPage() { selectedTags={selectedTags} history={history.data} historyLoading={history.isPending && selectedTags.length > 0} - historyGranulate={history.data?.granulate ?? historyGranularity.granulate} + historyGranulate={historyGranularity.granulate} historyAxis={historyGranularity} range={range} onSearchChange={setSearch} diff --git a/src/features/edge-detail/components/ArchiveView.tsx b/src/features/edge-detail/components/ArchiveView.tsx index b080c81..338fc1a 100644 --- a/src/features/edge-detail/components/ArchiveView.tsx +++ b/src/features/edge-detail/components/ArchiveView.tsx @@ -253,6 +253,7 @@ export function ArchiveView({ to={toIsoFromInput(range.to)} tickIntervalMs={historyAxis.tickIntervalMs} labelFormat={historyAxis.labelFormat} + tag={selectedTags[0]} tagLabels={tagLabels} /> ) : ( diff --git a/src/features/history-chart/HistoryChart.tsx b/src/features/history-chart/HistoryChart.tsx index 418f004..6568cb5 100644 --- a/src/features/history-chart/HistoryChart.tsx +++ b/src/features/history-chart/HistoryChart.tsx @@ -31,6 +31,7 @@ type HistoryChartProps = { to?: string; tickIntervalMs?: number; labelFormat?: HistoryAxisLabelFormat; + tag?: string; tagLabels?: Record; }; @@ -42,13 +43,12 @@ export function HistoryChart({ to, tickIntervalMs, labelFormat, + tag, tagLabels = {}, }: HistoryChartProps) { const dataZoomRef = useRef(null); - const legendData = useMemo( - () => data?.series.map((series) => tagLabels[series.tag] ?? series.tag) ?? [], - [data?.series, tagLabels], - ); + const seriesLabel = tag ? tagLabels[tag] ?? tag : ''; + const legendData = useMemo(() => (data?.rows.length && seriesLabel ? [seriesLabel] : []), [data?.rows.length, seriesLabel]); const option = useMemo( () => @@ -59,10 +59,10 @@ export function HistoryChart({ to, labelFormat, legendData, - tagLabels, + seriesLabel, tickIntervalMs, }), - [data, from, labelFormat, legendData, tagLabels, tickIntervalMs, to], + [data, from, labelFormat, legendData, seriesLabel, tickIntervalMs, to], ); const onChartEvents = useMemo( @@ -84,7 +84,7 @@ export function HistoryChart({ return
Загрузка графика...
; } - if (!data?.series.length) { + if (!data?.rows.length) { return
Нет данных для выбранного диапазона
; } diff --git a/src/features/history-chart/historyChartOptions.ts b/src/features/history-chart/historyChartOptions.ts index 3b5cf2e..46c4c9d 100644 --- a/src/features/history-chart/historyChartOptions.ts +++ b/src/features/history-chart/historyChartOptions.ts @@ -12,7 +12,7 @@ export type HistoryChartOptionsInput = { to?: string; labelFormat?: HistoryAxisLabelFormat; legendData: string[]; - tagLabels: Record; + seriesLabel: string; tickIntervalMs?: number; }; @@ -23,7 +23,7 @@ export function createHistoryChartOptions({ to, labelFormat, legendData, - tagLabels, + seriesLabel, tickIntervalMs, }: HistoryChartOptionsInput): EChartsOption { const xMin = from ? new Date(from).getTime() : undefined; @@ -102,9 +102,6 @@ export function createHistoryChartOptions({ endValue: dataZoomState.endValue, }, ], - series: - data?.series.flatMap((series, index) => - createSeriesOptions(series, index, tagLabels[series.tag] ?? series.tag), - ) ?? [], + series: data?.rows.length ? createSeriesOptions(data.rows, 0, seriesLabel) : [], }; } diff --git a/src/features/history-chart/historyChartSeries.ts b/src/features/history-chart/historyChartSeries.ts index 2efed73..03b8c1f 100644 --- a/src/features/history-chart/historyChartSeries.ts +++ b/src/features/history-chart/historyChartSeries.ts @@ -1,5 +1,5 @@ import type { SeriesOption } from 'echarts'; -import type { HistorySeries } from '../../entities/history/types'; +import type { HistoryPoint } from '../../entities/history/types'; import type { AvgPointValue } from './chartTypes'; export const SERIES_COLORS = [ @@ -14,20 +14,20 @@ export const SERIES_COLORS = [ ]; /** Создает avg-линию, вертикальные min/max-отрезки и точки экстремумов для одной серии. */ -export function createSeriesOptions(series: HistorySeries, index: number, label: string): SeriesOption[] { +export function createSeriesOptions(points: HistoryPoint[], index: number, label: string): SeriesOption[] { const color = SERIES_COLORS[index % SERIES_COLORS.length]; - const avgData: AvgPointValue[] = series.points.map((point) => [ - point.t, - point.avg, - point.min, - point.max, - point.count, - ]); - const spreadData = series.points.flatMap((point) => [ - [point.t, point.min], - [point.t, point.max], - [point.t, null], - ]); + const avgData: AvgPointValue[] = points.map((point) => { + const time = new Date(point.time).getTime(); + return [time, point.avg_value, point.min_value, point.max_value, point.point_count]; + }); + const spreadData = points.flatMap((point) => { + const time = new Date(point.time).getTime(); + return [ + [time, point.min_value], + [time, point.max_value], + [time, null], + ]; + }); return [ { @@ -52,7 +52,7 @@ export function createSeriesOptions(series: HistorySeries, index: number, label: { name: `${label} min`, type: 'scatter', - data: series.points.map((point) => [point.t, point.min]), + data: points.map((point) => [new Date(point.time).getTime(), point.min_value]), symbolSize: 4, silent: true, tooltip: { show: false }, @@ -68,7 +68,7 @@ export function createSeriesOptions(series: HistorySeries, index: number, label: { name: `${label} max`, type: 'scatter', - data: series.points.map((point) => [point.t, point.max]), + data: points.map((point) => [new Date(point.time).getTime(), point.max_value]), symbolSize: 4, silent: true, tooltip: { show: false },