@@ -43,6 +43,15 @@ var gitGraph = function (canvas, rawGraphList, config) {
43
43
44
44
var ctx = canvas . getContext ( "2d" ) ;
45
45
46
+ var devicePixelRatio = window . devicePixelRatio || 1 ;
47
+ var backingStoreRatio = ctx . webkitBackingStorePixelRatio ||
48
+ ctx . mozBackingStorePixelRatio ||
49
+ ctx . msBackingStorePixelRatio ||
50
+ ctx . oBackingStorePixelRatio ||
51
+ ctx . backingStorePixelRatio || 1 ;
52
+
53
+ var ratio = devicePixelRatio / backingStoreRatio ;
54
+
46
55
var init = function ( ) {
47
56
var maxWidth = 0 ;
48
57
var i ;
@@ -60,12 +69,20 @@ var gitGraph = function (canvas, rawGraphList, config) {
60
69
graphList . unshift ( row ) ;
61
70
}
62
71
63
- canvas . width = maxWidth * config . unitSize ;
64
- canvas . height = graphList . length * config . unitSize ;
72
+ var width = maxWidth * config . unitSize ;
73
+ var height = graphList . length * config . unitSize ;
74
+
75
+ canvas . width = width * ratio ;
76
+ canvas . height = height * ratio ;
77
+
78
+ canvas . style . width = width + 'px' ;
79
+ canvas . style . height = height + 'px' ;
65
80
66
81
ctx . lineWidth = config . lineWidth ;
67
82
ctx . lineJoin = "round" ;
68
83
ctx . lineCap = "round" ;
84
+
85
+ ctx . scale ( ratio , ratio ) ;
69
86
} ;
70
87
71
88
var genRandomStr = function ( ) {
@@ -185,7 +202,7 @@ var gitGraph = function (canvas, rawGraphList, config) {
185
202
}
186
203
}
187
204
188
- y = canvas . height - config . unitSize * 0.5 ;
205
+ y = ( canvas . height / ratio ) - config . unitSize * 0.5 ;
189
206
190
207
//iterate
191
208
for ( i = 0 , l = graphList . length ; i < l ; i ++ ) {
0 commit comments