@@ -32,12 +32,22 @@ function renderReport(report: Report) {
3232 const values = report . results . map ( unit => unit . mean )
3333 const maxValue = Math . max ( ...values )
3434 const viewBoxWidth = labelColumnWidth + barColumnWidth + 5 * padding + numberColumnWidth
35- const coords = report . results . map ( ( unit , index ) => ( { ...unit , index, y : index * rowHeight } ) )
36- const labels = coords . map ( ( { command, y } ) =>
35+ const shapes = report . results . map ( ( unit , index ) => ( {
36+ ...unit ,
37+ index,
38+ y : index * rowHeight ,
39+ labelX : padding ,
40+ barX : padding + labelColumnWidth + padding ,
41+ numberX : padding + labelColumnWidth + padding + barColumnWidth + padding ,
42+ labelWidth : unit . command . length * charWidth ,
43+ barWidth : Math . round ( unit . mean * barColumnWidth / maxValue ) ,
44+ numberContent : String ( unit . mean ) . slice ( 0 , numberLength - 1 ) + 's' ,
45+ } ) )
46+ const labels = shapes . map ( ( { command, y, labelX, labelWidth } ) =>
3747 svg `<svg
38- x=${ padding }
48+ x=${ labelX }
3949 y=${ y }
40- width=${ command . length * charWidth }
50+ width=${ labelWidth }
4151 height=${ rowHeight }
4252 fill=${ textColor }
4353 font-family=${ fontFamily }
@@ -52,18 +62,18 @@ function renderReport(report: Report) {
5262 >${ command } </text>
5363 </svg>`
5464 )
55- const bars = coords . map ( ( { y, index, mean } ) =>
65+ const bars = shapes . map ( ( { y, index, barX , barWidth } ) =>
5666 svg `<rect
57- x=${ padding + labelColumnWidth + padding }
67+ x=${ barX }
5868 y=${ y }
59- width=${ Math . round ( mean * barColumnWidth / maxValue ) }
69+ width=${ barWidth }
6070 height=${ rowHeight }
6171 fill=${ getBarColor ( index ) }
6272 />`
6373 )
64- const numbers = coords . map ( ( { y, mean } ) =>
74+ const numbers = shapes . map ( ( { y, numberX , numberContent } ) =>
6575 svg `<svg
66- x=${ padding + labelColumnWidth + padding + barColumnWidth + padding }
76+ x=${ numberX }
6777 y=${ y }
6878 width=${ numberColumnWidth }
6979 height=${ rowHeight }
@@ -75,7 +85,7 @@ function renderReport(report: Report) {
7585 height="100%"
7686 fill=${ textColor }
7787 font-family=${ fontFamily }
78- >${ String ( mean ) . slice ( 0 , numberLength - 1 ) + 's' } </text>
88+ >${ numberContent } </text>
7989 </svg>`
8090 )
8191 return svg `<svg
0 commit comments