From 65ffb0b77d216df29a910eedb2eb8e4be3d0bb43 Mon Sep 17 00:00:00 2001 From: margrop <1731827+margrop@users.noreply.github.com> Date: Tue, 3 Nov 2026 22:44:26 +0800 Subject: [PATCH] =?UTF-8?q?style:=20=E7=BB=9F=E8=AE=A1=E5=9B=BE=E8=A1=A8?= =?UTF-8?q?=E9=A2=9C=E8=89=B2=E6=94=B9=E7=94=A8=E4=B8=BB=E9=A2=98=E5=8F=98?= =?UTF-8?q?=E9=87=8F=E9=80=82=E9=85=8D=E6=B7=B1=E8=89=B2=E6=A8=A1=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 网格线、坐标轴、分类配色改用 CSS 主题变量,新增 --chart-6,组件中不再写死十六进制颜色。 Co-Authored-By: Claude Opus 5.5 --- src/app/globals.css | 3 ++ src/components/stats/chart-colors.ts | 42 +++++++++++++++++---- src/components/stats/practice-stats.tsx | 8 ++-- src/components/stats/subject-pie-chart.tsx | 2 +- src/components/stats/wrong-answer-stats.tsx | 16 +++++--- 5 files changed, 52 insertions(+), 19 deletions(-) diff --git a/src/app/globals.css b/src/app/globals.css index fa63e3ca..4b9be9cc 100644 --- a/src/app/globals.css +++ b/src/app/globals.css @@ -22,6 +22,7 @@ --color-sidebar-primary: var(--sidebar-primary); --color-sidebar-foreground: var(--sidebar-foreground); --color-sidebar: var(--sidebar); + --color-chart-6: var(--chart-6); --color-chart-5: var(--chart-5); --color-chart-4: var(--chart-4); --color-chart-3: var(--chart-3); @@ -81,6 +82,7 @@ --chart-3: oklch(0.7 0.17 50); --chart-4: oklch(0.6 0.2 320); --chart-5: oklch(0.75 0.15 90); + --chart-6: oklch(0.6 0.18 150); --sidebar: oklch(0.985 0 0); --sidebar-foreground: oklch(0.145 0 0); --sidebar-primary: oklch(0.52 0.2 268); @@ -118,6 +120,7 @@ --chart-3: oklch(0.75 0.16 50); --chart-4: oklch(0.68 0.2 320); --chart-5: oklch(0.8 0.15 90); + --chart-6: oklch(0.72 0.15 155); --sidebar: oklch(0.21 0.018 264); --sidebar-foreground: oklch(0.97 0.005 264); --sidebar-primary: oklch(0.68 0.16 268); diff --git a/src/components/stats/chart-colors.ts b/src/components/stats/chart-colors.ts index 2f614f0a..68386962 100644 --- a/src/components/stats/chart-colors.ts +++ b/src/components/stats/chart-colors.ts @@ -1,11 +1,37 @@ -/** 分类配色数组(饼图、柱状图等图表使用) */ -export const COLORS = ['#0088FE', '#00C49F', '#FFBB28', '#FF8042', '#8884d8', '#82ca9d']; +/** + * 统计图表颜色常量集中管理。 + * + * 所有颜色均引用 CSS 主题变量(globals.css 中定义), + * 亮色 / 暗色模式下自动适配,组件中不再出现十六进制颜色。 + * + * recharts 的 fill / stroke / tick 等属性均可直接接收 + * "var(--xxx)" 字符串;SVG linearGradient 的 stopColor 同理。 + */ -/** 难度配色 */ +/** 网格线颜色 */ +export const CHART_GRID_COLOR = 'var(--border)'; + +/** 坐标轴刻度文字颜色 */ +export const CHART_AXIS_COLOR = 'var(--muted-foreground)'; + +/** 分类配色(饼图、柱状图等图表使用),对应 globals.css 中的 --chart-1 ~ --chart-6 */ +export const COLORS: string[] = [ + 'var(--chart-1)', + 'var(--chart-2)', + 'var(--chart-3)', + 'var(--chart-4)', + 'var(--chart-5)', + 'var(--chart-6)', +]; + +/** 柱状图渐变起始颜色(月度趋势等图表的 linearGradient 使用) */ +export const CHART_BAR_GRADIENT_START = 'var(--chart-1)'; + +/** 难度配色(语义固定,深色模式下仍可辨识) */ export const DIFFICULTY_COLORS: Record = { - 'easy': '#4ade80', // Green-400 - 'medium': '#facc15', // Yellow-400 - 'hard': '#fb923c', // Orange-400 - 'harder': '#f87171', // Red-400 - 'Unknown': '#94a3b8' // Slate-400 + 'easy': 'var(--success)', + 'medium': 'var(--warning)', + 'hard': 'oklch(0.7 0.17 55)', + 'harder': 'oklch(0.65 0.2 25)', + 'Unknown': 'var(--muted-foreground)', }; diff --git a/src/components/stats/practice-stats.tsx b/src/components/stats/practice-stats.tsx index 23b07f57..563bb9f4 100644 --- a/src/components/stats/practice-stats.tsx +++ b/src/components/stats/practice-stats.tsx @@ -12,7 +12,7 @@ import { StatCard } from "./stat-card"; import { ChartTooltip } from "./chart-tooltip"; import { SubjectPieChart } from "./subject-pie-chart"; import { StatsEmpty, StatsError } from "./stats-state"; -import { COLORS, DIFFICULTY_COLORS } from "./chart-colors"; +import { COLORS, DIFFICULTY_COLORS, CHART_GRID_COLOR, CHART_AXIS_COLOR } from "./chart-colors"; export function PracticeStats() { const { t } = useLanguage(); @@ -92,19 +92,19 @@ export function PracticeStats() { - + `${name} ${((percent || 0) * 100).toFixed(0)}%`} diff --git a/src/components/stats/wrong-answer-stats.tsx b/src/components/stats/wrong-answer-stats.tsx index a9a7d42a..618e9a63 100644 --- a/src/components/stats/wrong-answer-stats.tsx +++ b/src/components/stats/wrong-answer-stats.tsx @@ -12,6 +12,7 @@ import { useStatsData } from "@/lib/use-stats-data"; import { StatCard } from "./stat-card"; import { SubjectPieChart } from "./subject-pie-chart"; import { StatsEmpty, StatsError } from "./stats-state"; +import { CHART_GRID_COLOR, CHART_AXIS_COLOR, CHART_BAR_GRADIENT_START } from "./chart-colors"; export function WrongAnswerStats() { const { t } = useLanguage(); @@ -87,21 +88,21 @@ export function WrongAnswerStats() { - - + + - +

{label}

-
+
{activityLabel}: {payload[0].value}