/* Copyright (C) 2025 QuantumNous This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see . For commercial licensing, please contact support@quantumnous.com */ import React, { useMemo } from 'react'; import { Card } from '@/components/ui'; import { VChart } from '@visactor/react-vchart'; import { renderQuota } from '../../helpers'; const ModelDistribution = ({ data, title, icon, t }) => { const pieSpec = useMemo(() => { if (!data || data.length === 0) return null; const chartData = data.slice(0, 8).map((item) => ({ name: item.model_name || t('未知'), value: item.quota || 0, })); // 如果有更多数据,合并为"其他" if (data.length > 8) { const otherQuota = data .slice(8) .reduce((sum, item) => sum + (item.quota || 0), 0); chartData.push({ name: t('其他'), value: otherQuota }); } return { type: 'pie', data: [{ id: 'modelDist', values: chartData }], valueField: 'value', categoryField: 'name', outerRadius: 0.8, innerRadius: 0.5, padAngle: 0.02, pie: { style: { cornerRadius: 4, }, }, tooltip: { mark: { content: [ { key: (datum) => datum?.name, value: (datum) => renderQuota(datum?.value || 0), }, ], }, }, legends: { visible: true, position: 'right', orient: 'vertical', item: { width: 100, label: { style: { fontSize: 11, }, }, }, }, label: { visible: false, }, color: [ '#3b82f6', '#10b981', '#f59e0b', '#ef4444', '#8b5cf6', '#06b6d4', '#f97316', '#84cc16', '#94a3b8', ], }; }, [data, t]); // 排行列表 const topModels = data?.slice(0, 5) || []; return ( {icon} {title} } styles={{ body: { padding: '16px' } }} > {pieSpec ? (
{topModels.map((item, index) => (
{index + 1} {item.model_name} {item.percent?.toFixed(1)}%
))}
) : (
{t('暂无数据')}
)}
); }; export default ModelDistribution;