]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
Ensure that chart dimensions are always >= 0
authorPeter-Van-Drunen <peetevd@gmail.com>
Fri, 23 Jun 2017 22:08:16 +0000 (18:08 -0400)
committerEvert Timberg <evert.timberg+github@gmail.com>
Fri, 23 Jun 2017 22:08:16 +0000 (18:08 -0400)
Elements were resizing incorrectly if they were regenerated while the chart was in a div that was display:none. Added a check to avoid this issue. Resolves #4397

src/core/core.controller.js

index 93546f56974e7283b4a9280f166cc79c20c1fdc0..0d21fc5f400f0dcb73de9ee62274d817fd757018 100644 (file)
@@ -169,8 +169,10 @@ 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));
+
+            // Set to 0 instead of canvas.size because the size defaults to 300x150 if the element is collased
+                       var newWidth = Math.max(0, Math.floor(helpers.getMaximumWidth(canvas)));
+                       var newHeight = Math.max(0, Math.floor(aspectRatio ? newWidth / aspectRatio : helpers.getMaximumHeight(canvas)));
 
                        if (me.width === newWidth && me.height === newHeight) {
                                return;