From 4187face00584b959e9190f0f2403ebd83d927b2 Mon Sep 17 00:00:00 2001 From: JavaZero <71128095+JavaZeroo@users.noreply.github.com> Date: Mon, 25 Aug 2025 16:56:49 +0800 Subject: [PATCH 1/5] feat: add dark mode support --- src/App.jsx | 4 +++- src/components/FileUpload.jsx | 18 ++++++++------- src/components/ThemeToggle.jsx | 23 +++++++++++++++++++ src/components/__tests__/ThemeToggle.test.jsx | 15 ++++++++++++ src/index.css | 3 +++ tailwind.config.js | 1 + 6 files changed, 55 insertions(+), 9 deletions(-) create mode 100644 src/components/ThemeToggle.jsx create mode 100644 src/components/__tests__/ThemeToggle.test.jsx diff --git a/src/App.jsx b/src/App.jsx index 950e072..09c39ce 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -6,6 +6,7 @@ import ChartContainer from './components/ChartContainer'; import { ComparisonControls } from './components/ComparisonControls'; import { Header } from './components/Header'; import { FileConfigModal } from './components/FileConfigModal'; +import { ThemeToggle } from './components/ThemeToggle'; import { PanelLeftClose, PanelLeftOpen } from 'lucide-react'; import { mergeFilesWithReplacement } from './utils/mergeFiles.js'; @@ -273,9 +274,10 @@ function App() {

Log Analyzer

+ + ); +} diff --git a/src/components/__tests__/ThemeToggle.test.jsx b/src/components/__tests__/ThemeToggle.test.jsx new file mode 100644 index 0000000..b36bc30 --- /dev/null +++ b/src/components/__tests__/ThemeToggle.test.jsx @@ -0,0 +1,15 @@ +import { render, screen, fireEvent } from '@testing-library/react'; +import { describe, it, expect } from 'vitest'; +import { ThemeToggle } from '../ThemeToggle'; + +describe('ThemeToggle', () => { + it('toggles dark class on document element', () => { + document.documentElement.classList.remove('dark'); + render(); + const button = screen.getByRole('button', { name: '切换主题' }); + fireEvent.click(button); + expect(document.documentElement.classList.contains('dark')).toBe(true); + fireEvent.click(button); + expect(document.documentElement.classList.contains('dark')).toBe(false); + }); +}); diff --git a/src/index.css b/src/index.css index 3d38cda..c11bb65 100644 --- a/src/index.css +++ b/src/index.css @@ -4,6 +4,9 @@ /* Accessibility improvements */ @layer base { + body { + @apply bg-gray-50 text-gray-900 dark:bg-gray-900 dark:text-gray-100; + } /* Screen reader only content */ .sr-only { position: absolute; diff --git a/tailwind.config.js b/tailwind.config.js index dca8ba0..6fa4d26 100644 --- a/tailwind.config.js +++ b/tailwind.config.js @@ -1,5 +1,6 @@ /** @type {import('tailwindcss').Config} */ export default { + darkMode: 'class', content: [ "./index.html", "./src/**/*.{js,ts,jsx,tsx}", From efa652054bab5c7a75b7377ce6cde14fff4f89dc Mon Sep 17 00:00:00 2001 From: JavaZero <71128095+JavaZeroo@users.noreply.github.com> Date: Mon, 25 Aug 2025 19:05:43 +0800 Subject: [PATCH 2/5] feat: improve dark mode styling --- src/App.jsx | 56 +++++++++---------- src/components/ChartContainer.jsx | 12 ++--- src/components/ComparisonControls.jsx | 26 ++++----- src/components/FileConfigModal.jsx | 62 ++++++++++----------- src/components/FileList.jsx | 32 +++++------ src/components/RegexControls.jsx | 78 +++++++++++++-------------- src/components/ResizablePanel.jsx | 2 +- src/index.css | 74 +++++++++++++------------ 8 files changed, 170 insertions(+), 172 deletions(-) diff --git a/src/App.jsx b/src/App.jsx index 09c39ce..cb440a0 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -195,14 +195,14 @@ function App() { }, [handleGlobalDragEnter, handleGlobalDragOver, handleGlobalDragLeave, handleGlobalDrop]); return ( -
+
{/* 全页面拖拽覆盖层 */} {globalDragOver && (
-
@@ -227,13 +227,13 @@ function App() {
-

+

🎯 释放文件以上传

-

+

支持 所有文本格式 文件

-

+

拖拽到页面任意位置即可快速上传文件

@@ -243,7 +243,7 @@ function App() { {!sidebarVisible && (
-

+

📊 分析和可视化大模型训练日志中的损失函数和梯度范数数据

{/* 状态和链接按钮 */}
- @@ -300,7 +300,7 @@ function App() { href="https://github.com/JavaZeroo/log-parser" target="_blank" rel="noopener noreferrer" - className="inline-flex items-center gap-1 px-2 py-1 rounded-full text-xs font-medium bg-gray-100 text-gray-700 hover:bg-gray-200 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-2" + className="inline-flex items-center gap-1 px-2 py-1 rounded-full text-xs font-medium bg-gray-100 text-gray-700 hover:bg-gray-200 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-2 dark:bg-gray-700 dark:text-gray-300 dark:hover:bg-gray-600" aria-label="访问 GitHub 仓库(在新窗口中打开)" > @@ -336,26 +336,26 @@ function App() { /> )} -
-

+

🎛️ 显示选项

-

📊 图表显示

-

上传文件后自动展示所有已配置的指标图表

+

📊 图表显示

+

上传文件后自动展示所有已配置的指标图表

-
-

基准线设置

+
+

基准线设置

- @@ -365,7 +365,7 @@ function App() { step="0.001" value={relativeBaseline} onChange={(e) => setRelativeBaseline(parseFloat(e.target.value) || 0)} - className="w-full px-2 py-1 text-xs border border-gray-300 rounded-md focus:ring-2 focus:ring-blue-500 focus:border-blue-500 focus:outline-none" + className="input-field" placeholder="0.002" aria-describedby="relative-baseline-description" /> @@ -378,9 +378,9 @@ function App() {
- @@ -390,7 +390,7 @@ function App() { step="0.001" value={absoluteBaseline} onChange={(e) => setAbsoluteBaseline(parseFloat(e.target.value) || 0)} - className="w-full px-2 py-1 text-xs border border-gray-300 rounded-md focus:ring-2 focus:ring-blue-500 focus:border-blue-500 focus:outline-none" + className="input-field" placeholder="0.005" aria-describedby="absolute-baseline-description" /> diff --git a/src/components/ChartContainer.jsx b/src/components/ChartContainer.jsx index a5f124a..5cda7ec 100644 --- a/src/components/ChartContainer.jsx +++ b/src/components/ChartContainer.jsx @@ -532,8 +532,8 @@ export default function ChartContainer({ if (parsedData.length === 0) { return ( -
-
+
+

📊 暂无数据

📁 请上传日志文件开始分析

@@ -559,8 +559,8 @@ export default function ChartContainer({ if (metrics.length === 0) { return ( -
-
+
+

🎯 请选择要显示的图表

@@ -639,8 +639,8 @@ export default function ChartContainer({ {comparisonChart} {stats && ( -
-

{key} 差值统计

+
+

{key} 差值统计

平均误差 (normal): {stats.meanNormal.toFixed(6)}

平均误差 (absolute): {stats.meanAbsolute.toFixed(6)}

diff --git a/src/components/ComparisonControls.jsx b/src/components/ComparisonControls.jsx index d844575..7447f60 100644 --- a/src/components/ComparisonControls.jsx +++ b/src/components/ComparisonControls.jsx @@ -13,16 +13,16 @@ export function ComparisonControls({ ]; return ( -
+
-