@@ -135,28 +135,29 @@ const MatrixPlot = ({ matrixData, labelFontSize, title = "Matrix" }: MatrixPlotP
135135
136136 return { col, avgScore } ;
137137 } ) ;
138- // Step 3: Sort columns by avgScore ascending
138+ // Step 3: Sort columns by avgScore descending
139139 const sortedDimensions = columnScores
140140 . sort ( ( a , b ) => b . avgScore - a . avgScore )
141+ // .sort((a, b) => a.avgScore - b.avgScore)
141142 . map ( d => d . col ) ;
142143
143144 const annotations : Partial < Plotly . Annotations > [ ] = [ ] ;
144145
145- for ( let i = 0 ; i < dimensions . length ; i ++ ) {
146- for ( let j = i + 1 ; j < dimensions . length ; j ++ ) {
147- const xKey = dimensions [ i ] ;
148- const yKey = dimensions [ j ] ;
149-
150- const pairValues = matrixData . map ( row => {
151- const x = row [ xKey ] ;
152- const y = row [ yKey ] ;
153- return x != null && y != null ? colorFunction ( x , y ) : null ;
154- } ) . filter ( v => v !== null ) as number [ ] ;
155-
156- const avg = pairValues . length > 0
157- ? pairValues . reduce ( ( sum , v ) => sum + v , 0 ) / pairValues . length
158- : 0 ;
159-
146+ for ( let i = 0 ; i < sortedDimensions . length ; i ++ ) {
147+ for ( let j = i + 1 ; j < sortedDimensions . length ; j ++ ) {
148+ const xKey = sortedDimensions [ i ] ;
149+ const yKey = sortedDimensions [ j ] ;
150+
151+ // const pairValues = matrixData.map(row => {
152+ // const x = row[xKey];
153+ // const y = row[yKey];
154+ // return x != null && y != null ? colorFunction(x, y) : null;
155+ // }).filter(v => v !== null) as number[];
156+
157+ // const avg = pairValues.length > 0
158+ // ? pairValues.reduce((sum, v) => sum + v, 0) / pairValues.length
159+ // : 0;
160+ const avg = pairwiseScores . get ( ` ${ xKey } | ${ yKey } ` ) ?? 0 ;
160161 annotations . push ( {
161162 text : `avg: ${ avg . toFixed ( 2 ) } ` ,
162163 // eslint-disable-next-line @typescript-eslint/no-explicit-any
0 commit comments