From e7d489bcee9b6b01c7dff58332e17053647e61fa Mon Sep 17 00:00:00 2001 From: Nikita Biziaev Date: Wed, 8 Jul 2026 15:49:42 +0500 Subject: [PATCH] the simplest chart tooltip --- .../history-chart/historyChartAvgLineSeries.ts | 2 +- src/features/history-chart/historyChartFormat.ts | 13 +++++++++---- src/styles/charts.css | 6 +----- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/features/history-chart/historyChartAvgLineSeries.ts b/src/features/history-chart/historyChartAvgLineSeries.ts index 9dd2080..a22e220 100644 --- a/src/features/history-chart/historyChartAvgLineSeries.ts +++ b/src/features/history-chart/historyChartAvgLineSeries.ts @@ -41,7 +41,7 @@ function createAvgLineData(points: HistoryPoint[], granulate: string, breakOnGap } const previousTime = new Date(finitePoints[index - 1].time).getTime(); - const hasAcceptableGap = currentTime - previousTime <= slotMs * 24; + const hasAcceptableGap = currentTime - previousTime <= slotMs * 50; return hasAcceptableGap ? [currentPoint] : [null, currentPoint]; }); diff --git a/src/features/history-chart/historyChartFormat.ts b/src/features/history-chart/historyChartFormat.ts index c7dd9ce..7dc2407 100644 --- a/src/features/history-chart/historyChartFormat.ts +++ b/src/features/history-chart/historyChartFormat.ts @@ -56,7 +56,12 @@ export function formatAxisDate(value: number, labelFormat: HistoryAxisLabelForma function formatChartValue(value: number): string { return new Intl.NumberFormat('ru-RU', { - maximumFractionDigits: Math.abs(value) >= 100 ? 2 : 3, + maximumFractionDigits: + Math.abs(value) >= 1000 ? 0 + : Math.abs(value) >= 100 ? 1 + : Math.abs(value) >= 10 ? 2 + : Math.abs(value) >= 1 ? 3 + : 4, }).format(value); } @@ -141,7 +146,8 @@ export function formatTooltip(params: unknown): string { return ''; } - const header = formatTooltipInterval(firstValue); + const time = firstValue[0]; + const header = formatTooltipDateTime(time); const rows = avgItems.map((item) => { const value = item.value as AvgPointValue; @@ -149,8 +155,7 @@ export function formatTooltip(params: unknown): string { '
', `${item.seriesName ?? ''}`, '', - formatTooltipValue(value), - value[4] > 1 ? ` · ${value[4]} точек` : '', + formatChartValue(value[1]), '', '
', ].join(''); diff --git a/src/styles/charts.css b/src/styles/charts.css index af8cd85..10d26dc 100644 --- a/src/styles/charts.css +++ b/src/styles/charts.css @@ -76,10 +76,6 @@ border-radius: var(--radius); } -.chart-tooltip { - min-width: 240px; -} - .chart-tooltip-title { margin-bottom: 8px; color: #e5e7eb; @@ -88,7 +84,7 @@ .chart-tooltip-row { display: grid; - grid-template-columns: minmax(90px, 1fr) auto; + grid-template-columns: 1fr auto; align-items: center; gap: 14px; margin-top: 5px;