Files
OpenFlare/frontend/app/(main)/components/dashboard/traffic-capacity-trend-chart.tsx
T
ryan 5a8722ff07 feat(frontend): 控制台 next-intl 中英双语
接入无 URL 前缀的 zh-CN/en,顶栏与外观设置可切换语言;选择写入 cookie 后刷新生效。
2026-08-16 16:49:16 +08:00

91 lines
2.7 KiB
TypeScript

'use client';
import { useTranslations } from 'next-intl';
import { TrendChart } from '@/components/data/trend-chart';
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
import type {
CapacityTrendPoint,
NetworkTrendPoint,
} from '@/lib/services/openflare';
import { formatBytes, formatPercent, formatTrendHour } from './dashboard-utils';
/** 业务流量(来自访问日志)与容量趋势(节点 Agent 宿主机指标)合并展示。 */
export function TrafficCapacityTrendChart({
networkPoints,
capacityPoints,
}: {
networkPoints: NetworkTrendPoint[];
capacityPoints: CapacityTrendPoint[];
}) {
const t = useTranslations('dashboard.trafficCapacity');
const tc = useTranslations('dashboard.capacityTrend');
return (
<Card className='border-dashed shadow-none'>
<CardHeader>
<CardTitle className='text-sm font-semibold'>
{t('title')}
</CardTitle>
</CardHeader>
<CardContent className='space-y-6'>
<TrendChart
labels={networkPoints.map((point) =>
formatTrendHour(point.bucket_started_at),
)}
height={180}
summaryScope='total'
summaryHint={t('networkHint')}
yAxisValueFormatter={formatBytes}
series={[
{
label: t('received'),
color: '#22c55e',
fillColor: 'rgba(34, 197, 94, 0.14)',
variant: 'area',
values: networkPoints.map((point) => point.bytes_received),
valueFormatter: formatBytes,
},
{
label: t('provided'),
color: '#38bdf8',
values: networkPoints.map((point) => point.bytes_provided),
valueFormatter: formatBytes,
},
]}
/>
<TrendChart
labels={capacityPoints.map((point) =>
formatTrendHour(point.bucket_started_at),
)}
height={180}
summaryScope='average'
summaryHint={t('capacityHint')}
yAxisValueFormatter={formatPercent}
series={[
{
label: tc('avgCpu'),
color: '#0f766e',
fillColor: 'rgba(15, 118, 110, 0.15)',
variant: 'area',
values: capacityPoints.map(
(point) => point.average_cpu_usage_percent,
),
valueFormatter: formatPercent,
},
{
label: tc('avgMemory'),
color: '#2563eb',
values: capacityPoints.map(
(point) => point.average_memory_usage_percent,
),
valueFormatter: formatPercent,
},
]}
/>
</CardContent>
</Card>
);
}