Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ea7c685

Browse files
committed
merged branch henrikbjorn/time-collector-canvas (PR #7065)
This PR was merged into the master branch. Commits ------- 439b8bc [WebProfilerBundle] Draw retina canvas if devicePixelRatio is bigger than 1 Discussion ---------- [2.3] [WebProfilerBundle] Draw retina canvas elements When using a MacBook Pro Retina the default canvas is fuzzy and ugly, this scales the elements for a higher DPI so they will look sharp and crisp.
2 parents 34c9323 + 439b8bc commit ea7c685

File tree

1 file changed

+18
-3
lines changed
  • src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector

1 file changed

+18
-3
lines changed

src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/time.html.twig

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,10 @@
194194
h = space,
195195
x = request.left * ratio + space, // position
196196
canvas = cache.get(elementId) || cache.set(elementId, document.getElementById(elementId)),
197-
ctx = canvas.getContext("2d");
197+
ctx = canvas.getContext("2d"),
198+
backingStoreRatio,
199+
scaleRatio,
200+
devicePixelRatio;
198201
199202
// Filter events whose total time is below the threshold.
200203
drawableEvents = request.events.filter(function(event) {
@@ -203,8 +206,20 @@
203206
204207
canvasHeight += gapPerEvent * drawableEvents.length;
205208
206-
canvas.width = width;
207-
canvas.height = canvasHeight;
209+
// For retina displays so text and boxes will be crisp
210+
devicePixelRatio = window.devicePixelRatio == "undefined" ? 1 : window.devicePixelRatio;
211+
backingStoreRatio = ctx.webkitBackingStorePixelRatio == "undefined" ? 1 : ctx.webkitBackingStorePixelRatio;
212+
scaleRatio = devicePixelRatio / 1;
213+
214+
canvasHeight += gapPerEvent * drawableEvents.length;
215+
216+
canvas.width = width * scaleRatio;
217+
canvas.height = canvasHeight * scaleRatio;
218+
219+
canvas.style.width = width + 'px';
220+
canvas.style.height = canvasHeight + 'px';
221+
222+
ctx.scale(scaleRatio, scaleRatio);
208223
209224
ctx.textBaseline = "middle";
210225
ctx.lineWidth = 0;

0 commit comments

Comments
 (0)