@@ -26,6 +26,33 @@ ChartJS.register(
2626 zoomPlugin
2727) ;
2828
29+ export const getComparisonData = ( data1 , data2 , mode ) => {
30+ const map1 = new Map ( data1 . map ( p => [ p . x , p . y ] ) ) ;
31+ const map2 = new Map ( data2 . map ( p => [ p . x , p . y ] ) ) ;
32+ const steps = [ ...map1 . keys ( ) ] . filter ( k => map2 . has ( k ) ) . sort ( ( a , b ) => a - b ) ;
33+ return steps . map ( step => {
34+ const v1 = map1 . get ( step ) ;
35+ const v2 = map2 . get ( step ) ;
36+ let diff ;
37+ switch ( mode ) {
38+ case 'absolute' :
39+ diff = Math . abs ( v2 - v1 ) ;
40+ break ;
41+ case 'relative-normal' :
42+ diff = v1 !== 0 ? ( v2 - v1 ) / v1 : 0 ;
43+ break ;
44+ case 'relative' : {
45+ const ad = Math . abs ( v2 - v1 ) ;
46+ diff = v1 !== 0 ? ad / Math . abs ( v1 ) : 0 ;
47+ break ;
48+ }
49+ default :
50+ diff = v2 - v1 ;
51+ }
52+ return { x : step , y : diff } ;
53+ } ) ;
54+ } ;
55+
2956const ChartWrapper = ( { data, options, chartId, onRegisterChart, onSyncHover } ) => {
3057 const chartRef = useRef ( null ) ;
3158
@@ -248,58 +275,31 @@ export default function ChartContainer({
248275 }
249276 } , [ parsedData , onXRangeChange , useStepKeyword ] ) ;
250277
251- const colors = [ '#ef4444' , '#3b82f6' , '#10b981' , '#f59e0b' , '#8b5cf6' , '#f97316' ] ;
252- const createChartData = dataArray => ( {
253- datasets : dataArray . map ( ( item , index ) => {
254- const color = colors [ index % colors . length ] ;
255- return {
256- label : item . name ?. replace ( / \. ( l o g | t x t ) $ / i, '' ) || `File ${ index + 1 } ` ,
257- data : item . data ,
258- borderColor : color ,
259- backgroundColor : `${ color } 33` ,
260- borderWidth : 2 ,
261- fill : false ,
262- tension : 0 ,
263- pointRadius : 0 ,
264- pointHoverRadius : 4 ,
265- pointBackgroundColor : color ,
266- pointBorderColor : color ,
267- pointBorderWidth : 1 ,
268- pointHoverBackgroundColor : color ,
269- pointHoverBorderColor : color ,
270- pointHoverBorderWidth : 1 ,
271- animation : false ,
272- animations : { colors : false , x : false , y : false } ,
273- } ;
274- } )
275- } ) ;
276-
277- const getComparisonData = ( data1 , data2 , mode ) => {
278- const minLength = Math . min ( data1 . length , data2 . length ) ;
279- const result = [ ] ;
280- for ( let i = 0 ; i < minLength ; i ++ ) {
281- const v1 = data1 [ i ] . y ;
282- const v2 = data2 [ i ] . y ;
283- let diff ;
284- switch ( mode ) {
285- case 'absolute' :
286- diff = Math . abs ( v2 - v1 ) ;
287- break ;
288- case 'relative-normal' :
289- diff = v1 !== 0 ? ( v2 - v1 ) / v1 : 0 ;
290- break ;
291- case 'relative' : {
292- const ad = Math . abs ( v2 - v1 ) ;
293- diff = v1 !== 0 ? ad / Math . abs ( v1 ) : 0 ;
294- break ;
295- }
296- default :
297- diff = v2 - v1 ;
298- }
299- result . push ( { x : i , y : diff } ) ;
300- }
301- return result ;
302- } ;
278+ const colors = [ '#ef4444' , '#3b82f6' , '#10b981' , '#f59e0b' , '#8b5cf6' , '#f97316' ] ;
279+ const createChartData = dataArray => ( {
280+ datasets : dataArray . map ( ( item , index ) => {
281+ const color = colors [ index % colors . length ] ;
282+ return {
283+ label : item . name ?. replace ( / \. ( l o g | t x t ) $ / i, '' ) || `File ${ index + 1 } ` ,
284+ data : item . data ,
285+ borderColor : color ,
286+ backgroundColor : `${ color } 33` ,
287+ borderWidth : 2 ,
288+ fill : false ,
289+ tension : 0 ,
290+ pointRadius : 0 ,
291+ pointHoverRadius : 4 ,
292+ pointBackgroundColor : color ,
293+ pointBorderColor : color ,
294+ pointBorderWidth : 1 ,
295+ pointHoverBackgroundColor : color ,
296+ pointHoverBorderColor : color ,
297+ pointHoverBorderWidth : 1 ,
298+ animation : false ,
299+ animations : { colors : false , x : false , y : false } ,
300+ } ;
301+ } )
302+ } ) ;
303303
304304 const calculateYRange = useCallback ( ( dataArray ) => {
305305 let min = Infinity ;
0 commit comments