Files
NODEDC_MISSION_CORE/packages/router-ui/src/RouterTraffic.tsx
T
DCCONSTRUCTIONS a49fb00b8e feat(routers): integrate Banana Pi Client API and onboard LibreSpeed measurements
Discover Ethernet routers under the board, map physical SIM slots, expose vendor controls and real telemetry, and provide packaged VPS speed tests with a live monochrome gauge. Enforce compact typography across Core and Node UI.
2026-11-11 23:53:46 +03:00

29 lines
3.1 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import {useId} from 'react';
import {Description,Icon} from '@nodedc/ui-react';
import {trafficArea,trafficCeiling,trafficPath,trafficRate,trafficSegments,trafficWindow,type TrafficPoint} from './overview';
export function RouterTraffic({points,ready,down,up}:{points:TrafficPoint[];ready:boolean;down:number|null;up:number|null}){
const gradient=`router-traffic-${useId().replaceAll(':','')}`;
const latest=points.at(-1)?.at??Date.now()/1000,start=latest-trafficWindow,max=trafficCeiling(points);
const hasTrend=points.filter(p=>p.down!=null||p.up!=null).length>=2;
return <>
<div className="router-traffic-values">
<div><span className="router-download"><i className="router-traffic-key"/><Icon name="download"/> Приём</span><strong>{ready?trafficRate(down):'—'}</strong></div>
<div><span className="router-upload"><i className="router-traffic-key"/><Icon name="upload"/> Передача</span><strong>{ready?trafficRate(up):'—'}</strong></div>
</div>
{hasTrend?<figure className="router-traffic-chart">
<div className="router-scale-labels"><span>{trafficRate(max)}</span><span>{ready?'Последние 5 минут':'Последние полученные измерения'}</span></div>
<svg viewBox="0 0 320 82" preserveAspectRatio="none" role="img" aria-label="Трафик за последние пять минут: приём — светлая линия, передача — серая точечная. Плавные линии проходят через измерения; разрывы означают отсутствие данных.">
<defs><linearGradient id={gradient} x1="0" y1="0" x2="0" y2="1"><stop offset="0%" stopColor="var(--nodedc-text-primary)" stopOpacity=".14"/><stop offset="100%" stopColor="var(--nodedc-text-primary)" stopOpacity="0"/></linearGradient></defs>
<path d={trafficArea(points,'down',start,latest,max)} fill={`url(#${gradient})`} className="router-chart-area"/>
<line x1="2" x2="318" y1="78" y2="78" className="router-chart-baseline"/>
<path d={trafficPath(points,'up',start,latest,max)} className="router-chart-line router-chart-up"/>
<path d={trafficPath(points,'down',start,latest,max)} className="router-chart-line router-chart-down"/>
{(['down','up'] as const).flatMap(field=>trafficSegments(points,field,start,latest,max).filter(s=>s.length===1).map((s,i)=><circle key={`${field}:${i}`} cx={s[0].x} cy={s[0].y} r="1.2" className={`router-chart-point router-chart-point-${field}`}/>))}
</svg>
<figcaption className="router-scale-labels"><span>−5 мин</span><span>{new Date(latest*1000).toLocaleTimeString('ru-RU')}</span></figcaption>
</figure>:<div className="router-chart-empty"><Description>{!ready?'Нет свежих измерений для графика':down==null&&up==null?'Скорость пока не получена от роутера':'Ожидание следующего измерения для графика'}</Description></div>}
<Description>Текущий трафик, а не предел скорости интернета.</Description>
</>;
}