@@ -12,27 +12,25 @@ function App() {
1212
1313 // 全局解析配置状态
1414 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+ ]
2529 } ) ;
2630
27- // 兼容旧版本的正则表达式状态(供ChartContainer使用)
28- const [ lossRegex , setLossRegex ] = useState ( 'loss:\\s*([\\d.eE+-]+)' ) ;
29- const [ gradNormRegex , setGradNormRegex ] = useState ( 'grad[\\s_]norm:\\s*([\\d.eE+-]+)' ) ;
30-
3131 const [ compareMode , setCompareMode ] = useState ( 'normal' ) ;
3232 const [ relativeBaseline , setRelativeBaseline ] = useState ( 0.002 ) ;
3333 const [ absoluteBaseline , setAbsoluteBaseline ] = useState ( 0.005 ) ;
34- const [ showLoss , setShowLoss ] = useState ( true ) ;
35- const [ showGradNorm , setShowGradNorm ] = useState ( false ) ;
3634 const [ configModalOpen , setConfigModalOpen ] = useState ( false ) ;
3735 const [ configFile , setConfigFile ] = useState ( null ) ;
3836 const [ globalDragOver , setGlobalDragOver ] = useState ( false ) ;
@@ -46,8 +44,7 @@ function App() {
4644 enabled : true ,
4745 config : {
4846 // 使用全局解析配置作为默认值
49- loss : { ...globalParsingConfig . loss } ,
50- gradNorm : { ...globalParsingConfig . gradNorm } ,
47+ metrics : globalParsingConfig . metrics . map ( m => ( { ...m } ) ) ,
5148 dataRange : {
5249 start : 0 , // 默认从第一个数据点开始
5350 end : undefined , // 默认到最后一个数据点
@@ -118,30 +115,17 @@ function App() {
118115 // 全局解析配置变更处理
119116 const handleGlobalParsingConfigChange = useCallback ( ( newConfig ) => {
120117 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+
126119 // 同步所有文件的解析配置
127120 setUploadedFiles ( prev => prev . map ( file => ( {
128121 ...file ,
129122 config : {
130123 ...file . config ,
131- loss : { ...newConfig . loss } ,
132- gradNorm : { ...newConfig . gradNorm }
124+ metrics : newConfig . metrics . map ( m => ( { ...m } ) )
133125 }
134126 } ) ) ) ;
135127 } , [ ] ) ;
136128
137- const handleRegexChange = useCallback ( ( type , value ) => {
138- if ( type === 'loss' ) {
139- setLossRegex ( value ) ;
140- } else {
141- setGradNormRegex ( value ) ;
142- }
143- } , [ ] ) ;
144-
145129 // 全局拖拽事件处理
146130 const handleGlobalDragEnter = useCallback ( ( e ) => {
147131 e . preventDefault ( ) ;
@@ -303,9 +287,6 @@ function App() {
303287 < RegexControls
304288 globalParsingConfig = { globalParsingConfig }
305289 onGlobalParsingConfigChange = { handleGlobalParsingConfigChange }
306- lossRegex = { lossRegex }
307- gradNormRegex = { gradNormRegex }
308- onRegexChange = { handleRegexChange }
309290 uploadedFiles = { uploadedFiles }
310291 xRange = { xRange }
311292 onXRangeChange = { setXRange }
@@ -336,41 +317,7 @@ function App() {
336317 < div className = "space-y-3" >
337318 < div >
338319 < 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 >
374321 </ div >
375322
376323 < div className = "border-t pt-3" >
@@ -438,13 +385,10 @@ function App() {
438385 >
439386 < ChartContainer
440387 files = { uploadedFiles }
441- lossRegex = { lossRegex }
442- gradNormRegex = { gradNormRegex }
388+ metrics = { globalParsingConfig . metrics }
443389 compareMode = { compareMode }
444390 relativeBaseline = { relativeBaseline }
445391 absoluteBaseline = { absoluteBaseline }
446- showLoss = { showLoss }
447- showGradNorm = { showGradNorm }
448392 xRange = { xRange }
449393 onXRangeChange = { setXRange }
450394 onMaxStepChange = { setMaxStep }
0 commit comments