@@ -404,20 +404,26 @@ export const setupCanvasRoutes = function(app: Express, prisma: PrismaClient): v
404404
405405 // Check how many people hold the #1 spot
406406 const topRankings = rankings [ rankingType . type ] . filter ( r => r . rank === 1 ) ;
407- let fillColor = '#424242' ; // Base fill color if multiple coalitions share #1 spot or no data
407+ // Sort the top rankings by coalition id to have a consistent order in the gradient when there are multiple #1 ranked users from different coalitions
408+ topRankings . sort ( ( a , b ) => {
409+ const coalitionIdA = a . coalition ? a . coalition . id : 0 ;
410+ const coalitionIdB = b . coalition ? b . coalition . id : 0 ;
411+ return coalitionIdA - coalitionIdB ;
412+ } ) ;
413+ let fillColor : string | CanvasGradient = '#424242' ; // Base fill color if multiple coalitions share #1 spot or no data
408414 // Fill color based on the coalition color if there is only one #1 and that user has a coalition with a color
409415 if ( topRankings . length === 1 && topRankings [ 0 ] . coalition && topRankings [ 0 ] . coalition . color ) {
410416 fillColor = topRankings [ 0 ] . coalition . color ;
411417 }
412- // Fill color based on the coalition color if there are more users in the #1 spot but they all share the same coalition
418+ // Fill color based on coalition colors using gradient with multiple steps
413419 else if ( topRankings . length > 1 ) {
414- const coalitionIds = new Set ( topRankings . map ( r => r . coalition ? r . coalition . id : null ) ) ;
415- if ( coalitionIds . size === 1 ) {
416- const coalition = topRankings [ 0 ] . coalition ;
417- if ( coalition && coalition . color ) {
418- fillColor = coalition . color ;
419- }
420- }
420+ const gradient = ctx . createLinearGradient ( rightX , currentY , rightX + rightWidth , currentY + entryInnerHeight ) ;
421+ const step = 1 / topRankings . length ;
422+ topRankings . forEach ( ( ranking , index ) => {
423+ const color = ( ranking . coalition && ranking . coalition . color ) ? ranking . coalition . color : '#424242' ;
424+ gradient . addColorStop ( step * index , color ) ;
425+ } ) ;
426+ fillColor = gradient ;
421427 }
422428
423429 // Draw entry background based on the top user's coalition color
0 commit comments