'use client';
import {Area, AreaChart, CartesianGrid, Line, XAxis, YAxis} from 'recharts';
import {Card, CardContent, CardDescription, CardHeader, CardTitle} from '@/components/ui/card';
import {
ChartConfig,
ChartContainer,
ChartLegend,
ChartLegendContent,
ChartTooltip,
ChartTooltipContent,
} from '@/components/ui/chart';
import type {NetworkTrendPoint} from '@/lib/services/openflare';
import {formatTrendHour} from '../../components/dashboard/dashboard-utils';
import {formatBytesPerSecond} from './node-utils';
const chartConfig = {
openrestyRx: {
label: 'OpenResty 入站',
color: 'hsl(var(--chart-2))',
},
openrestyTx: {
label: 'OpenResty 出站',
color: 'hsl(var(--chart-4))',
},
} satisfies ChartConfig;
export function NetworkTrendChart({
points,
title = '24 小时网络趋势',
description = '观察 OpenResty 入站/出站吞吐的变化,辅助识别回源压力、突发流量或出口异常。',
}: {
points: NetworkTrendPoint[];
title?: string;
description?: string;
}) {
const data = points.map((point) => ({
hour: formatTrendHour(point.bucket_started_at),
openrestyRx: point.openresty_rx_bytes,
openrestyTx: point.openresty_tx_bytes,
}));
if (data.length === 0) {
return (
{title}
{description}
暂无趋势数据
);
}
return (
{title}
{description}
formatBytesPerSecond(Number(value), 3600)}
/>
(
{formatBytesPerSecond(Number(value), 3600)}
{name === 'openrestyRx' ? '入站' : '出站'}
)}
/>
}
/>
} />
);
}