Skip to content

Commit 42d781a

Browse files
michaelkuhnlunny
authored andcommitted
Update gitgraph.js to fix blurry commit graph on HiDPI screens (#2957)
1 parent 2cb6c51 commit 42d781a

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

public/vendor/VERSIONS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ File(s): /vendor/plugins/clipboard/clipboard.min.js
1515
Version: 1.5.9
1616

1717
File(s): /vendor/plugins/gitgraph/gitgraph.js
18-
Version: 5fcc26b
18+
Version: 9b492e8bf1ddf7908a4997b8f83fa38a809a9da3
1919

2020
File(s): /vendor/plugins/autolink/autolink.js
2121
Version: 741f66f

public/vendor/plugins/gitgraph/gitgraph.js

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,15 @@ var gitGraph = function (canvas, rawGraphList, config) {
4444

4545
var ctx = canvas.getContext("2d");
4646

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+
4756
var init = function () {
4857
var maxWidth = 0;
4958
var i;
@@ -61,12 +70,20 @@ var gitGraph = function (canvas, rawGraphList, config) {
6170
graphList.unshift(row);
6271
}
6372

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';
6681

6782
ctx.lineWidth = config.lineWidth;
6883
ctx.lineJoin = "round";
6984
ctx.lineCap = "round";
85+
86+
ctx.scale(ratio, ratio);
7087
};
7188

7289
var genRandomStr = function () {
@@ -186,7 +203,7 @@ var gitGraph = function (canvas, rawGraphList, config) {
186203
}
187204
}
188205

189-
y = canvas.height - config.unitSize * 0.5;
206+
y = (canvas.height / ratio) - config.unitSize * 0.5;
190207

191208
//iterate
192209
for (i = 0, l = graphList.length; i < l; i++) {

0 commit comments

Comments
 (0)