11import { IntraCoalition , PrismaClient } from '@prisma/client' ;
22import { Express } from 'express' ;
33import { CanvasRenderingContext2D , createCanvas , loadImage , registerFont } from 'canvas' ;
4- import { bonusPointsAwardingStarted , CoalitionScore , getBlocAtDate , getCoalitionScore , getCoalitionTopContributors , getRanking , SingleRanking , SMALL_CONTRIBUTION_TYPES , timeAgo } from '../utils' ;
4+ import { bonusPointsAwardingStarted , CoalitionScore , formatThousands , getBlocAtDate , getCoalitionScore , getCoalitionTopContributors , getRanking , SingleRanking , SMALL_CONTRIBUTION_TYPES , timeAgo } from '../utils' ;
55
66const CANVAS_WIDTH = 1920 ;
77const CANVAS_HEIGHT = 1080 ;
@@ -302,7 +302,7 @@ const drawInitialCanvas = async function(prisma: PrismaClient, ctx: CanvasRender
302302 ctx . fillText ( `${ coalition . intra_coalition . name } ` , textX , textY - entryHeight * 0.15 ) ;
303303 const nameWidth = ctx . measureText ( `${ coalition . intra_coalition . name } ` ) . width ;
304304 ctx . font = `bold ${ Math . floor ( entryHeight * 0.18 ) } px "Museo Sans"` ;
305- ctx . fillText ( `${ score . score } pts.` , textX + nameWidth , textY - entryHeight * 0.15 ) ;
305+ ctx . fillText ( `${ formatThousands ( score . score ) } pts.` , textX + nameWidth , textY - entryHeight * 0.15 ) ;
306306
307307 // Draw coalition logo
308308 // TODO: make this work! The logos are SVG, which is not supported properly by canvas loadImage
@@ -323,7 +323,7 @@ const drawInitialCanvas = async function(prisma: PrismaClient, ctx: CanvasRender
323323 ctx . fillText ( 'TOP CONTRIBUTOR' , profilePicX + profilePicSize + PADDING * 0.5 , profilePicY + profilePicSize * 0.47 ) ;
324324
325325 // Draw login and score next to profile picture
326- ctx . font = `${ Math . floor ( entryHeight * 0.13 ) } px "Museo Sans"` ;
326+ ctx . font = `${ Math . floor ( entryHeight * 0.11 ) } px "Museo Sans"` ;
327327 ctx . textBaseline = 'middle' ;
328328 ctx . fillText ( `${ ( topContributor . user . login ) } ` , profilePicX + profilePicSize + PADDING * 0.5 , profilePicY + profilePicSize * 0.62 ) ;
329329 }
@@ -417,7 +417,7 @@ export const setupCanvasRoutes = function(app: Express, prisma: PrismaClient): v
417417 // Draw user profile picture in the vertical center of the entry
418418 await drawUserProfilePicture ( ctx , rightX + PADDING + entryPadding , currentY + entryPadding , profilePicSize , topRanking . user . image || '' ) ;
419419 // Draw login and score next to profile picture
420- ctx . fillText ( `${ topRanking . user . login } / ${ topRanking . score } pts.` , entryTextX , entryTextY , entryTextMaxWidth ) ;
420+ ctx . fillText ( `${ topRanking . user . login } / ${ formatThousands ( topRanking . score ) } pts.` , entryTextX , entryTextY , entryTextMaxWidth ) ;
421421 } else {
422422 ctx . fillText ( 'No data available' , entryTextX , entryTextY , entryTextMaxWidth ) ;
423423 }
@@ -533,7 +533,7 @@ export const setupCanvasRoutes = function(app: Express, prisma: PrismaClient): v
533533 ctx . fillStyle = '#FFFFFF' ;
534534 ctx . textBaseline = 'bottom' ;
535535 ctx . font = `bold ${ Math . floor ( entryInnerHeight * 0.21 ) } px "Museo Sans"` ;
536- ctx . fillText ( `${ score . user . intra_user . login } / ${ score . amount } pts. / ${ timeAgo ( score . created_at ) } ` , entryTextX , entryTextY , entryTextMaxWidth ) ;
536+ ctx . fillText ( `${ score . user . intra_user . login } / ${ formatThousands ( score . amount ) } pts. / ${ timeAgo ( score . created_at ) } ` , entryTextX , entryTextY , entryTextMaxWidth ) ;
537537
538538 // Draw user profile picture in the vertical center of the entry
539539 await drawUserProfilePicture ( ctx , rightX + PADDING + entryPadding , currentY + entryPadding , profilePicSize , score . user . intra_user . image || '' ) ;
0 commit comments