@@ -12,27 +12,25 @@ function App() {
12
12
13
13
// 全局解析配置状态
14
14
const [ globalParsingConfig , setGlobalParsingConfig ] = useState ( {
15
- loss : {
16
- mode : 'keyword' , // 'keyword' | 'regex'
17
- keyword : 'loss:' ,
18
- regex : 'loss:\\s*([\\d.eE+-]+)'
19
- } ,
20
- gradNorm : {
21
- mode : 'keyword' , // 'keyword' | 'regex'
22
- keyword : 'norm:' ,
23
- regex : 'grad[\\s_]norm:\\s*([\\d.eE+-]+)'
24
- }
15
+ metrics : [
16
+ {
17
+ name : 'Loss' ,
18
+ mode : 'keyword' , // 'keyword' | 'regex'
19
+ keyword : 'loss:' ,
20
+ regex : 'loss:\\s*([\\d.eE+-]+)'
21
+ } ,
22
+ {
23
+ name : 'Grad Norm' ,
24
+ mode : 'keyword' ,
25
+ keyword : 'norm:' ,
26
+ regex : 'grad[\\s_]norm:\\s*([\\d.eE+-]+)'
27
+ }
28
+ ]
25
29
} ) ;
26
30
27
- // 兼容旧版本的正则表达式状态(供ChartContainer使用)
28
- const [ lossRegex , setLossRegex ] = useState ( 'loss:\\s*([\\d.eE+-]+)' ) ;
29
- const [ gradNormRegex , setGradNormRegex ] = useState ( 'grad[\\s_]norm:\\s*([\\d.eE+-]+)' ) ;
30
-
31
31
const [ compareMode , setCompareMode ] = useState ( 'normal' ) ;
32
32
const [ relativeBaseline , setRelativeBaseline ] = useState ( 0.002 ) ;
33
33
const [ absoluteBaseline , setAbsoluteBaseline ] = useState ( 0.005 ) ;
34
- const [ showLoss , setShowLoss ] = useState ( true ) ;
35
- const [ showGradNorm , setShowGradNorm ] = useState ( false ) ;
36
34
const [ configModalOpen , setConfigModalOpen ] = useState ( false ) ;
37
35
const [ configFile , setConfigFile ] = useState ( null ) ;
38
36
const [ globalDragOver , setGlobalDragOver ] = useState ( false ) ;
@@ -46,8 +44,7 @@ function App() {
46
44
enabled : true ,
47
45
config : {
48
46
// 使用全局解析配置作为默认值
49
- loss : { ...globalParsingConfig . loss } ,
50
- gradNorm : { ...globalParsingConfig . gradNorm } ,
47
+ metrics : globalParsingConfig . metrics . map ( m => ( { ...m } ) ) ,
51
48
dataRange : {
52
49
start : 0 , // 默认从第一个数据点开始
53
50
end : undefined , // 默认到最后一个数据点
@@ -118,30 +115,17 @@ function App() {
118
115
// 全局解析配置变更处理
119
116
const handleGlobalParsingConfigChange = useCallback ( ( newConfig ) => {
120
117
setGlobalParsingConfig ( newConfig ) ;
121
-
122
- // 同步更新兼容的正则表达式状态
123
- setLossRegex ( newConfig . loss . mode === 'regex' ? newConfig . loss . regex : 'loss:\\s*([\\d.eE+-]+)' ) ;
124
- setGradNormRegex ( newConfig . gradNorm . mode === 'regex' ? newConfig . gradNorm . regex : 'grad[\\s_]norm:\\s*([\\d.eE+-]+)' ) ;
125
-
118
+
126
119
// 同步所有文件的解析配置
127
120
setUploadedFiles ( prev => prev . map ( file => ( {
128
121
...file ,
129
122
config : {
130
123
...file . config ,
131
- loss : { ...newConfig . loss } ,
132
- gradNorm : { ...newConfig . gradNorm }
124
+ metrics : newConfig . metrics . map ( m => ( { ...m } ) )
133
125
}
134
126
} ) ) ) ;
135
127
} , [ ] ) ;
136
128
137
- const handleRegexChange = useCallback ( ( type , value ) => {
138
- if ( type === 'loss' ) {
139
- setLossRegex ( value ) ;
140
- } else {
141
- setGradNormRegex ( value ) ;
142
- }
143
- } , [ ] ) ;
144
-
145
129
// 全局拖拽事件处理
146
130
const handleGlobalDragEnter = useCallback ( ( e ) => {
147
131
e . preventDefault ( ) ;
@@ -303,9 +287,6 @@ function App() {
303
287
< RegexControls
304
288
globalParsingConfig = { globalParsingConfig }
305
289
onGlobalParsingConfigChange = { handleGlobalParsingConfigChange }
306
- lossRegex = { lossRegex }
307
- gradNormRegex = { gradNormRegex }
308
- onRegexChange = { handleRegexChange }
309
290
uploadedFiles = { uploadedFiles }
310
291
xRange = { xRange }
311
292
onXRangeChange = { setXRange }
@@ -336,41 +317,7 @@ function App() {
336
317
< div className = "space-y-3" >
337
318
< div >
338
319
< h4 className = "text-xs font-medium text-gray-700 mb-2" > 📊 图表显示</ h4 >
339
- < div className = "space-y-2" >
340
- < label className = "flex items-center cursor-pointer hover:bg-gray-50 p-1 rounded" >
341
- < input
342
- type = "checkbox"
343
- checked = { showLoss }
344
- onChange = { ( e ) => setShowLoss ( e . target . checked ) }
345
- className = "rounded border-gray-300 text-blue-600 focus:ring-2 focus:ring-blue-500 focus:ring-offset-2"
346
- aria-describedby = "show-loss-description"
347
- />
348
- < span className = "ml-2 text-xs text-gray-700" > 📉 显示 Loss 函数</ span >
349
- < span
350
- id = "show-loss-description"
351
- className = "sr-only"
352
- >
353
- 控制是否显示损失函数图表
354
- </ span >
355
- </ label >
356
-
357
- < label className = "flex items-center cursor-pointer hover:bg-gray-50 p-1 rounded" >
358
- < input
359
- type = "checkbox"
360
- checked = { showGradNorm }
361
- onChange = { ( e ) => setShowGradNorm ( e . target . checked ) }
362
- className = "rounded border-gray-300 text-blue-600 focus:ring-2 focus:ring-blue-500 focus:ring-offset-2"
363
- aria-describedby = "show-gradnorm-description"
364
- />
365
- < span className = "ml-2 text-xs text-gray-700" > 📈 显示 Grad Norm</ span >
366
- < span
367
- id = "show-gradnorm-description"
368
- className = "sr-only"
369
- >
370
- 控制是否显示梯度范数图表
371
- </ span >
372
- </ label >
373
- </ div >
320
+ < p className = "text-xs text-gray-500" > 上传文件后自动展示所有已配置的指标图表</ p >
374
321
</ div >
375
322
376
323
< div className = "border-t pt-3" >
@@ -438,13 +385,10 @@ function App() {
438
385
>
439
386
< ChartContainer
440
387
files = { uploadedFiles }
441
- lossRegex = { lossRegex }
442
- gradNormRegex = { gradNormRegex }
388
+ metrics = { globalParsingConfig . metrics }
443
389
compareMode = { compareMode }
444
390
relativeBaseline = { relativeBaseline }
445
391
absoluteBaseline = { absoluteBaseline }
446
- showLoss = { showLoss }
447
- showGradNorm = { showGradNorm }
448
392
xRange = { xRange }
449
393
onXRangeChange = { setXRange }
450
394
onMaxStepChange = { setMaxStep }
0 commit comments