]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
Resize on zoom, retry (#6987)
authorJukka Kurkela <jukka.kurkela@gmail.com>
Sun, 19 Jan 2020 18:15:27 +0000 (20:15 +0200)
committerEvert Timberg <evert.timberg+github@gmail.com>
Sun, 19 Jan 2020 18:15:27 +0000 (13:15 -0500)
src/core/core.controller.js
src/platforms/platform.dom.js
src/platforms/platform.js

index 0c28c0dd48cfd148c468ad27567f2f61bbe7aaa6..488f81e98f7a4293e46467009e19eef59daff278 100644 (file)
@@ -241,6 +241,7 @@ 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.
@@ -248,13 +249,18 @@ class Chart {
                // 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
index 1579e0e15dc916c335cd929de67c0e6833466312..6a7c07a2226f6d2768b7a7956ef41b4463af5dfd 100644 (file)
@@ -445,5 +445,9 @@ export default {
                }
 
                removeListener(canvas, type, proxy);
+       },
+
+       getDevicePixelRatio: function() {
+               return window.devicePixelRatio;
        }
 };
index f527c69cd72e381b98967ef3efe6afc6aa99fb47..a135c0992635836d75ab1b1fee71069965e1be12 100644 (file)
@@ -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);