@@ -98,47 +98,47 @@ const MatrixPlot = ({ matrixData, labelFontSize, title = "Matrix" }: MatrixPlotP
9898 ? rawValues
9999 : normalize ( rawValues ) ;
100100
101- // // Step 1: Compute all pairwise avg scores only once
102- const pairwiseScores = new Map < string , number > ( ) ;
103-
104- for ( let i = 0 ; i < dimensions . length ; i ++ ) {
105- for ( let j = 0 ; j < dimensions . length ; j ++ ) {
106- if ( i === j ) continue ;
107- const a = dimensions [ i ] ;
108- const b = dimensions [ j ] ;
109- const key = `${ a } |${ b } ` ;
110-
111- const values = matrixData . map ( row => {
112- const x = row [ a ] ;
113- const y = row [ b ] ;
114- return x != null && y != null ? colorFunction ( x , y ) : null ;
115- } ) . filter ( v => v !== null ) as number [ ] ;
116-
117- const avg = values . length > 0
118- ? values . reduce ( ( sum , v ) => sum + v , 0 ) / values . length
119- : 0 ;
120-
121- pairwiseScores . set ( key , avg ) ;
101+ // // Step 1: Compute all pairwise avg scores only once
102+ const pairwiseScores = new Map < string , number > ( ) ;
103+
104+ for ( let i = 0 ; i < dimensions . length ; i ++ ) {
105+ for ( let j = 0 ; j < dimensions . length ; j ++ ) {
106+ if ( i === j ) continue ;
107+ const a = dimensions [ i ] ;
108+ const b = dimensions [ j ] ;
109+ const key = `${ a } |${ b } ` ;
110+
111+ const values = matrixData . map ( row => {
112+ const x = row [ a ] ;
113+ const y = row [ b ] ;
114+ return x != null && y != null ? colorFunction ( x , y ) : null ;
115+ } ) . filter ( v => v !== null ) as number [ ] ;
116+
117+ const avg = values . length > 0
118+ ? values . reduce ( ( sum , v ) => sum + v , 0 ) / values . length
119+ : 0 ;
120+
121+ pairwiseScores . set ( key , avg ) ;
122+ }
122123 }
123- }
124-
125-
126- const columnScores = dimensions . map ( col => {
127- const avgScore = dimensions
128- . filter ( other => other !== col )
129- . map ( other => {
130- const key1 = `${ col } |${ other } ` ;
131- const key2 = `${ other } |${ col } ` ;
132- return pairwiseScores . get ( key1 ) ?? pairwiseScores . get ( key2 ) ?? 0 ;
133- } )
134- . reduce ( ( a , b ) => a + b , 0 ) / ( dimensions . length - 1 ) ;
135-
136- return { col, avgScore } ;
137- } ) ;
138- // Step 3: Sort columns by avgScore ascending
139- const sortedDimensions = columnScores
140- . sort ( ( a , b ) => b . avgScore - a . avgScore )
141- . map ( d => d . col ) ;
124+
125+
126+ const columnScores = dimensions . map ( col => {
127+ const avgScore = dimensions
128+ . filter ( other => other !== col )
129+ . map ( other => {
130+ const key1 = `${ col } |${ other } ` ;
131+ const key2 = `${ other } |${ col } ` ;
132+ return pairwiseScores . get ( key1 ) ?? pairwiseScores . get ( key2 ) ?? 0 ;
133+ } )
134+ . reduce ( ( a , b ) => a + b , 0 ) / ( dimensions . length - 1 ) ;
135+
136+ return { col, avgScore } ;
137+ } ) ;
138+ // Step 3: Sort columns by avgScore ascending
139+ const sortedDimensions = columnScores
140+ . sort ( ( a , b ) => b . avgScore - a . avgScore )
141+ . map ( d => d . col ) ;
142142
143143 const annotations : Partial < Plotly . Annotations > [ ] = [ ] ;
144144
@@ -159,18 +159,10 @@ const columnScores = dimensions.map(col => {
159159
160160 annotations . push ( {
161161 text : `avg: ${ avg . toFixed ( 2 ) } ` ,
162- xref : ( i === 0 ? "x" : `x${ i + 1 } ` ) as
163- | "x" | "paper"
164- | "x2" | "x3" | "x4" | "x5" | "x6" | "x7" | "x8" | "x9" | "x10"
165- | "x11" | "x12" | "x13" | "x14" | "x15" | "x16" | "x17" | "x18" | "x19" | "x20"
166- | "x21" | "x22" | "x23" | "x24" | "x25" | "x26" | "x27" | "x28" | "x29" | "x30"
167- | undefined ,
168- yref : ( j === 0 ? "y" : `y${ j + 1 } ` ) as
169- | "y" | "paper"
170- | "y2" | "y3" | "y4" | "y5" | "y6" | "y7" | "y8" | "y9" | "y10"
171- | "y11" | "y12" | "y13" | "y14" | "y15" | "y16" | "y17" | "y18" | "y19" | "y20"
172- | "y21" | "y22" | "y23" | "y24" | "y25" | "y26" | "y27" | "y28" | "y29" | "y30"
173- | undefined ,
162+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
163+ xref : `x${ i + 1 } domain` as any ,
164+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
165+ yref : `y${ j + 1 } domain` as any ,
174166 x : 0.2 ,
175167 y : 0.8 ,
176168 showarrow : false ,
0 commit comments