// 中间件概览图表 — 状态 + 命中率 + QPS/连接(支持放大)// Logan.Li import { useMemo, type ReactNode } from 'react'; import { BarChart, Bar, XAxis, YAxis, Tooltip, ResponsiveContainer, Cell, PieChart, Pie, } from 'recharts'; import { Card, CardContent } from '@/components/ui/card'; import { BarChart3, PieChart as PieChartIcon, Percent } from 'lucide-react'; import type { MwTarget } from './helpers'; import { fmtHitRate, fmtVal } from './helpers'; import { ChartExpandShell } from '../shared/ChartExpandShell'; import { MonitorChartTooltip, MONITOR_PIE_STROKE, MonitorPieTooltip } from '../shared/monitorChartTheme'; import i18n from '@/i18n'; interface Props { targets: MwTarget[]; } function shortName(name: string) { return name.length > 10 ? `${name.slice(0, 10)}…` : name; } export function MwOverviewCharts({ targets }: Props) { const statusData = useMemo(() => { const online = targets.filter((t) => t.status === 'online').length; const offline = targets.length - online; return [ { name: i18n.t('agent.agentOnline'), value: online, fill: 'var(--dg-green)' }, { name: i18n.t('agent.agentOffline'), value: offline, fill: 'var(--dg-red)' }, ].filter((d) => d.value > 0); }, [targets]); const redisHitData = useMemo(() => targets .filter((t) => t.description === 'redis' && t.latest_metrics?.redis_hit_rate > 0) .map((t) => ({ name: shortName(t.name), fullName: t.name, value: (t.latest_metrics.redis_hit_rate || 0) * 100, fill: (t.latest_metrics.redis_hit_rate || 0) >= 0.9 ? 'var(--dg-green)' : 'var(--dg-yellow)', })) .sort((a, b) => a.value - b.value), [targets]); const redisQpsData = useMemo(() => targets .filter((t) => t.description === 'redis' && t.latest_metrics?.redis_qps > 0) .map((t) => ({ name: shortName(t.name), fullName: t.name, value: t.latest_metrics.redis_qps, fill: 'var(--dg-blue)' })) .sort((a, b) => b.value - a.value), [targets]); const mysqlConnData = useMemo(() => targets .filter((t) => t.description === 'mysql' && t.latest_metrics?.mysql_connections > 0) .map((t) => ({ name: shortName(t.name), fullName: t.name, value: t.latest_metrics.mysql_connections, fill: 'var(--dg-blue)' })) .sort((a, b) => b.value - a.value), [targets]); if (targets.length === 0) return null; return (