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

add check on overwriting canvas height/width #4874

Merged
merged 3 commits into from Nov 22, 2017
Merged
Changes from 1 commit
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
6 changes: 4 additions & 2 deletions src/core/core.helpers.js
Expand Up @@ -544,8 +544,10 @@ module.exports = function(Chart) {
// If no style has been set on the canvas, the render size is used as display size,
// making the chart visually bigger, so let's enforce it to the "correct" values.
// See https://github.com/chartjs/Chart.js/issues/3575
canvas.style.height = height + 'px';
canvas.style.width = width + 'px';
if (!canvas.style.height && !canvas.style.width) {
Copy link
Member

Choose a reason for hiding this comment

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

@andersponders shouldn't we split this check in case only one dimension is set in the style?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You could, but I would say if the user is explicitly setting one through CSS, it seems more natural to let the other get handled that way too. im too lazy to make an example, but in my case I was setting height to be 70% of the container, and in that case i probably don't want the library to set width to be static 200px

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i should add this is with responsive=false, another option is instead check if responsive is set

Copy link
Member

Choose a reason for hiding this comment

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

This method should not be aware about the responsive stuff, let's keep it the way you did.

canvas.style.height = height + 'px';
canvas.style.width = width + 'px';
}
};
// -- Canvas methods
helpers.fontString = function(pixelSize, fontStyle, fontFamily) {
Expand Down