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