mirror of
https://github.com/margrop/wrong-notebook.git
synced 2026-12-02 09:59:38 +08:00
style: 统计图表颜色改用主题变量适配深色模式
网格线、坐标轴、分类配色改用 CSS 主题变量,新增 --chart-6,组件中不再写死十六进制颜色。 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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<string, string> = {
|
||||
'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)',
|
||||
};
|
||||
|
||||
@@ -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() {
|
||||
<CardContent className="h-[300px]">
|
||||
<ResponsiveContainer width="100%" height="100%">
|
||||
<BarChart data={stats.activityStats} margin={{ top: 10, right: 10, left: -20, bottom: 0 }}>
|
||||
<CartesianGrid strokeDasharray="3 3" vertical={false} stroke="#e5e7eb" />
|
||||
<CartesianGrid strokeDasharray="3 3" vertical={false} stroke={CHART_GRID_COLOR} />
|
||||
<XAxis
|
||||
dataKey="date"
|
||||
axisLine={false}
|
||||
tickLine={false}
|
||||
tick={{ fill: '#6b7280', fontSize: 12 }}
|
||||
tick={{ fill: CHART_AXIS_COLOR, fontSize: 12 }}
|
||||
dy={10}
|
||||
/>
|
||||
<YAxis
|
||||
allowDecimals={false}
|
||||
axisLine={false}
|
||||
tickLine={false}
|
||||
tick={{ fill: '#6b7280', fontSize: 12 }}
|
||||
tick={{ fill: CHART_AXIS_COLOR, fontSize: 12 }}
|
||||
/>
|
||||
<Tooltip
|
||||
content={
|
||||
|
||||
@@ -25,7 +25,7 @@ export function SubjectPieChart({ title, data }: SubjectPieChartProps) {
|
||||
cy="50%"
|
||||
innerRadius={60}
|
||||
outerRadius={80}
|
||||
fill="#8884d8"
|
||||
fill={COLORS[0]}
|
||||
paddingAngle={5}
|
||||
dataKey="value"
|
||||
label={({ name, percent }) => `${name} ${((percent || 0) * 100).toFixed(0)}%`}
|
||||
|
||||
@@ -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() {
|
||||
<BarChart data={data.activityData} margin={{ top: 10, right: 10, left: -20, bottom: 0 }}>
|
||||
<defs>
|
||||
<linearGradient id="colorCount" x1="0" y1="0" x2="0" y2="1">
|
||||
<stop offset="5%" stopColor="#8b5cf6" stopOpacity={0.8} />
|
||||
<stop offset="95%" stopColor="#8b5cf6" stopOpacity={0.1} />
|
||||
<stop offset="5%" stopColor={CHART_BAR_GRADIENT_START} stopOpacity={0.8} />
|
||||
<stop offset="95%" stopColor={CHART_BAR_GRADIENT_START} stopOpacity={0.1} />
|
||||
</linearGradient>
|
||||
</defs>
|
||||
<CartesianGrid strokeDasharray="3 3" vertical={false} stroke="#e5e7eb" />
|
||||
<CartesianGrid strokeDasharray="3 3" vertical={false} stroke={CHART_GRID_COLOR} />
|
||||
<XAxis
|
||||
dataKey="date"
|
||||
stroke="#888888"
|
||||
stroke={CHART_AXIS_COLOR}
|
||||
fontSize={12}
|
||||
tickLine={false}
|
||||
axisLine={false}
|
||||
dy={10}
|
||||
/>
|
||||
<YAxis
|
||||
stroke="#888888"
|
||||
stroke={CHART_AXIS_COLOR}
|
||||
fontSize={12}
|
||||
tickLine={false}
|
||||
axisLine={false}
|
||||
@@ -141,7 +142,10 @@ function MonthlyTooltip({ active, payload, label, activityLabel }: MonthlyToolti
|
||||
<div className="bg-background border rounded-lg shadow-lg p-3 text-sm">
|
||||
<p className="font-medium mb-1">{label}</p>
|
||||
<div className="flex items-center gap-2">
|
||||
<div className="w-2 h-2 rounded-full bg-violet-500" />
|
||||
<div
|
||||
className="w-2 h-2 rounded-full"
|
||||
style={{ backgroundColor: CHART_BAR_GRADIENT_START }}
|
||||
/>
|
||||
<span className="text-muted-foreground">{activityLabel}:</span>
|
||||
<span className="font-bold">{payload[0].value}</span>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user