22
22
23
23
const CV_WIDTH = 4000 ;
24
24
const MIN_WIDTH = 50 ;
25
+ const MIN_TOTAL_HEIGHT = 60 ;
25
26
26
27
export default function renderIntoCanvas (
27
28
canvas : HTMLCanvasElement ,
28
29
items : { valueWidth : number , valueOffset : number , serviceName : string } [ ] ,
29
30
totalValueWidth : number ,
30
31
getFillColor : string => string
31
32
) {
32
- // eslint-disable-next-line no-param-reassign
33
+ // eslint-disable-next-line no-param-reassign
33
34
canvas . width = CV_WIDTH ;
34
- // eslint-disable-next-line no-param-reassign
35
- canvas . height = items . length ;
35
+ let itemHeight = 1 ;
36
+ if ( items . length < MIN_TOTAL_HEIGHT ) {
37
+ // eslint-disable-next-line no-param-reassign
38
+ canvas . height = MIN_TOTAL_HEIGHT ;
39
+ itemHeight = MIN_TOTAL_HEIGHT / items . length ;
40
+ } else {
41
+ // eslint-disable-next-line no-param-reassign
42
+ canvas . height = items . length ;
43
+ itemHeight = 1 ;
44
+ }
36
45
const ctx = canvas . getContext ( '2d' ) ;
37
46
for ( let i = 0 ; i < items . length ; i ++ ) {
38
47
const { valueWidth, valueOffset, serviceName } = items [ i ] ;
@@ -44,6 +53,6 @@ export default function renderIntoCanvas(
44
53
width = MIN_WIDTH ;
45
54
}
46
55
ctx . fillStyle = getFillColor ( serviceName ) ;
47
- ctx . fillRect ( x , i , width , 1 ) ;
56
+ ctx . fillRect ( x , i * itemHeight , width , itemHeight ) ;
48
57
}
49
58
}
0 commit comments