e7a7541b2b
补齐历史缺译并统一整句插值。九语覆盖 100%,静态检查及 713 项单测通过。
599 lines
20 KiB
React
599 lines
20 KiB
React
/*
|
|
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 <https://www.gnu.org/licenses/>.
|
|
|
|
For commercial licensing, please contact support@quantumnous.com
|
|
*/
|
|
|
|
import { I18N_TECHNICAL_TEXT } from '../../../i18n/technicalText.js';
|
|
import React, { useMemo, useState } from 'react';
|
|
import { Progress, Radio, RadioGroup, Tag } from '@/components/ui';
|
|
import { VChart } from '@visactor/react-vchart';
|
|
import {
|
|
BarChart3,
|
|
Cpu,
|
|
Crown,
|
|
GitCompareArrows,
|
|
LineChart,
|
|
Users,
|
|
} from 'lucide-react';
|
|
import { ChangeText, EmptyBlock, SectionCard } from './shared';
|
|
import {
|
|
formatCny,
|
|
orgDisplayName,
|
|
pct,
|
|
quotaToCny,
|
|
SEGMENTS,
|
|
TIERS,
|
|
} from './utils';
|
|
|
|
// VChart 配色必须是具体色值(图表在 canvas 上绘制,读取不到 CSS 变量);
|
|
// 与看板其余图表共用同一组色:个人蓝、企业紫、增长绿、下降红
|
|
const COLOR_PERSONAL = '#3b82f6';
|
|
const COLOR_ORG = '#8b5cf6';
|
|
const COLOR_ORG_MA = '#c4b5fd';
|
|
const COLOR_UP = '#10b981';
|
|
const COLOR_DOWN = '#ef4444';
|
|
|
|
const truncateLabel = (v, n = 14) =>
|
|
v && v.length > n ? `${v.slice(0, n - 1)}…` : v;
|
|
|
|
// ─── 变化归因:谁拉动了增长 / 下滑 ─────────────────────────────────
|
|
export const ChangeAttribution = ({ report, cny, t }) => {
|
|
const { chartSpec, segmentRows, netDelta } = useMemo(() => {
|
|
const orgs = (report.orgs || []).map((o) => ({
|
|
name: orgDisplayName(o, t),
|
|
delta: (o.quota || 0) - (o.prev_quota || 0),
|
|
}));
|
|
const up = orgs
|
|
.filter((o) => o.delta > 0)
|
|
.sort((a, b) => b.delta - a.delta)
|
|
.slice(0, 8);
|
|
const down = orgs
|
|
.filter((o) => o.delta < 0)
|
|
.sort((a, b) => a.delta - b.delta)
|
|
.slice(0, 8);
|
|
const values = [...up, ...down.reverse()]
|
|
.map((o, i) => ({
|
|
// 名称可能重复,用序号保证类目唯一,标签里再去掉
|
|
key: `${i} |