Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix/4397 #4406

Merged
merged 4 commits into from Jun 23, 2017
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 12 additions & 2 deletions src/core/core.controller.js
Expand Up @@ -169,8 +169,18 @@ module.exports = function(Chart) {

// 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.
var newWidth = Math.floor(helpers.getMaximumWidth(canvas));
var newHeight = Math.floor(aspectRatio? newWidth / aspectRatio : helpers.getMaximumHeight(canvas));

// Default values. Set to 0 instead of canvas.size because the size defaults to 300x150 if the element is collased
var newWidth = 0;
var newHeight = 0;

// Avoid issues with the canvas having negative maximum width and/or height due to element being collapsed
if (Math.floor(helpers.getMaximumWidth(canvas)) >= 0) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would change just just slightly to cache the return of helpers.getMaximumWidth(canvas) into a local variable. This would improve minification and performance. The max width function reads some styles off the canvas element which can be slow

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree, and could be simply:

var newWidth = Math.max(0, Math.floor(helpers.getMaximumWidth(canvas)));
...

newWidth = Math.floor(helpers.getMaximumWidth(canvas));
}
if (helpers.getMaximumHeight(canvas) >= 0) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment here about the return of helpers.getMaximumHeight

newHeight = Math.floor(aspectRatio ? newWidth / aspectRatio : helpers.getMaximumHeight(canvas));
}

if (me.width === newWidth && me.height === newHeight) {
return;
Expand Down