diff --git a/apps/web/src/components/reui-kit/uptime-chart.tsx b/apps/web/src/components/reui-kit/uptime-chart.tsx
index 82fcc49..e968022 100644
--- a/apps/web/src/components/reui-kit/uptime-chart.tsx
+++ b/apps/web/src/components/reui-kit/uptime-chart.tsx
@@ -1,4 +1,4 @@
-import { useId, useMemo, useState } from 'react'
+import { useEffect, useId, useMemo, useState } from 'react'
import { ActivityIcon, InfoIcon, TrendingDownIcon, TrendingUpIcon } from 'lucide-react'
import { Area, AreaChart, XAxis } from 'recharts'
@@ -12,6 +12,7 @@ import { Button } from '@cfdm/ui/components/button'
import {
ChartContainer,
ChartTooltip,
+ ChartTooltipContent,
type ChartConfig,
} from '@cfdm/ui/components/chart'
import { Tabs, TabsList, TabsTrigger } from '@cfdm/ui/components/tabs'
@@ -87,21 +88,27 @@ function deltaPercent(points: ChartPoint[]): number | null {
return next - prev
}
-interface UptimeTooltipProps {
- active?: boolean
- payload?: Array<{ payload: ChartPoint }>
-}
+function UptimeDelta({ delta }: { delta: number }) {
+ if (Math.abs(delta) < 0.05) {
+ return без изменений за период
+ }
+
+ if (delta > 0) {
+ return (
+ <>
+
+ +{delta.toFixed(1)} п.п.
+ с начала периода
+ >
+ )
+ }
-function UptimeTooltip({ active, payload }: UptimeTooltipProps) {
- if (!active || !payload?.[0]) return null
- const point = payload[0].payload
return (
-
-
- {point.latency} мс · {point.ok ? 'OK' : 'Down'}
-
-
{point.period}
-
+ <>
+
+ {delta.toFixed(1)} п.п.
+ с начала периода
+ >
)
}
@@ -124,9 +131,14 @@ export function UptimeChart({
}: UptimeChartProps) {
const gradientId = useId().replace(/:/g, '')
const [internalPeriod, setInternalPeriod] = useState('5D')
+ const [tooltipPortal, setTooltipPortal] = useState(null)
const period = periodProp ?? internalPeriod
const days = UPTIME_PERIODS.find((entry) => entry.key === period)?.days ?? 5
+ useEffect(() => {
+ setTooltipPortal(document.body)
+ }, [])
+
function handlePeriodChange(next: UptimePeriodKey) {
onPeriodChange?.(next)
if (periodProp == null) setInternalPeriod(next)
@@ -202,35 +214,21 @@ export function UptimeChart({
{points.length} проб
- ) : delta >= 0 ? (
- <>
-
-
- +{delta.toFixed(1)} п.п.
-
- к первой половине окна
- >
) : (
- <>
-
-
- {delta.toFixed(1)} п.п.
-
- к первой половине окна
- >
+
)}
-
+
@@ -247,33 +245,56 @@ export function UptimeChart({
- } />
+ {
+ const point = item.payload as ChartPoint | undefined
+ const ping = Number(value)
+ return (
+
+
+ {point?.ok === false ? 'Down' : 'Пинг'}
+
+
+ {Number.isFinite(ping) ? `${ping} мс` : '—'}
+
+
+ )
+ }}
+ />
+ }
+ />
{
- const { cx, cy, payload, index } = dotProps as {
- cx?: number
- cy?: number
- index?: number
- payload?: ChartPoint
- }
+ const { cx, cy, payload, index } = dotProps
if (cx == null || cy == null) return
- const fill = payload?.ok
- ? 'var(--color-latency)'
- : 'var(--destructive)'
+ const point = payload as ChartPoint | undefined
return (
)
}}