Skip to content

Commit

Permalink
Showing 3 changed files with 19 additions and 2 deletions.
8 changes: 7 additions & 1 deletion src/core/core.controller.js
Original file line number Diff line number Diff line change
@@ -241,20 +241,26 @@ class Chart {
const options = me.options;
const canvas = me.canvas;
const aspectRatio = (options.maintainAspectRatio && me.aspectRatio) || null;
const oldRatio = me.currentDevicePixelRatio;

// the canvas render width and height will be casted to integers so make sure that
// the canvas display style uses the same integer values to avoid blurring effect.

// Set to 0 instead of canvas.size because the size defaults to 300x150 if the element is collapsed
const newWidth = Math.max(0, Math.floor(helpers.dom.getMaximumWidth(canvas)));
const newHeight = Math.max(0, Math.floor(aspectRatio ? newWidth / aspectRatio : helpers.dom.getMaximumHeight(canvas)));
const newRatio = options.devicePixelRatio || platform.getDevicePixelRatio();

if (me.width === newWidth && me.height === newHeight && oldRatio === newRatio) {
return;
}

canvas.width = me.width = newWidth;
canvas.height = me.height = newHeight;
canvas.style.width = newWidth + 'px';
canvas.style.height = newHeight + 'px';

helpers.dom.retinaScale(me, options.devicePixelRatio);
helpers.dom.retinaScale(me, newRatio);

if (!silent) {
// Notify any plugins about the resize
4 changes: 4 additions & 0 deletions src/platforms/platform.dom.js
Original file line number Diff line number Diff line change
@@ -445,5 +445,9 @@ export default {
}

removeListener(canvas, type, proxy);
},

getDevicePixelRatio: function() {
return window.devicePixelRatio;
}
};
9 changes: 8 additions & 1 deletion src/platforms/platform.js
Original file line number Diff line number Diff line change
@@ -50,7 +50,14 @@ export default helpers.extend({
* @param {string} type - The ({@link IEvent}) type to remove
* @param {function} listener - The listener function to remove from the event target.
*/
removeEventListener: function() {}
removeEventListener: function() {},

/**
* Returs current devicePixelRatio of the device this platform is connected to.
*/
getDevicePixelRatio: function() {
return 1;
}

}, implementation);

0 comments on commit 16baf20

Please sign in to comment.