// 拨测协议数量分布饼图 // Logan.Li import { useMemo } from 'react'; import { PieChart, Pie, Cell, Tooltip, ResponsiveContainer } from 'recharts'; import { MONITOR_PIE_STROKE, MonitorPieTooltip } from '../shared/monitorChartTheme'; import { Card, CardContent } from '@/components/ui/card'; import { PieChart as PieChartIcon } from 'lucide-react'; import { PROBE_TYPE_OPTIONS, normalizeProbeType } from './helpers'; import type { SiteTask } from './helpers'; import { useTranslation } from 'react-i18next'; interface Props { tasks: SiteTask[]; } const PROTOCOL_COLORS: Record = { HTTP: 'var(--dg-blue)', SSL: '#a855f7', TCP: '#06b6d4', DNS: 'var(--dg-green)', PING: '#f59e0b', }; export function SiteProtocolPieChart({ tasks }: Props) { const { t } = useTranslation(); const protocolData = useMemo(() => { const counts: Record = {}; for (const t of PROBE_TYPE_OPTIONS) counts[t] = 0; for (const t of tasks) { const key = normalizeProbeType(t.type); counts[key] = (counts[key] || 0) + 1; } return PROBE_TYPE_OPTIONS .map((name) => ({ name, value: counts[name] || 0, fill: PROTOCOL_COLORS[name] || 'var(--dg-text-muted)' })) .filter((d) => d.value > 0); }, [tasks]); if (tasks.length === 0) { return ( {t('monitor.siteprotocolpiechart.s0589e5')} ); } return (

{t('monitor.siteprotocolpiechart.s20721c')}

共 {tasks.length} 个任务
{protocolData.map((entry) => ( ))} } />
{protocolData.map((d) => (
{d.name} {d.value}
))}
); }