]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
Resize on zoom (#6974)
authorJukka Kurkela <jukka.kurkela@gmail.com>
Sat, 18 Jan 2020 00:07:28 +0000 (02:07 +0200)
committerEvert Timberg <evert.timberg+github@gmail.com>
Sat, 18 Jan 2020 00:07:28 +0000 (19:07 -0500)
* Resize on zoom
* Add test

src/core/core.controller.js
test/specs/core.controller.tests.js

index 4317bbfbd76d04b1cc2252490b6a1cc5b2c2b48b..0c28c0dd48cfd148c468ad27567f2f61bbe7aaa6 100644 (file)
@@ -249,10 +249,6 @@ class Chart {
                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)));
 
-               if (me.width === newWidth && me.height === newHeight) {
-                       return;
-               }
-
                canvas.width = me.width = newWidth;
                canvas.height = me.height = newHeight;
                canvas.style.width = newWidth + 'px';
index 1ba338c7158a186940db948aa56b06399d3abb3a..aa4784fe0fcf60ef7175ea70469c5c437cc893e5 100644 (file)
@@ -547,6 +547,40 @@ describe('Chart', function() {
                        wrapper.style.display = 'block';
                });
 
+               // https://github.com/chartjs/Chart.js/issues/5485
+               it('should resize the canvas when the devicePixelRatio changes', function(done) {
+                       var chart = acquireChart({
+                               options: {
+                                       responsive: true,
+                                       maintainAspectRatio: false,
+                                       devicePixelRatio: 1
+                               }
+                       }, {
+                               canvas: {
+                                       style: ''
+                               },
+                               wrapper: {
+                                       style: 'width: 400px; height: 200px; position: relative'
+                               }
+                       });
+
+                       expect(chart).toBeChartOfSize({
+                               dw: 400, dh: 200,
+                               rw: 400, rh: 200,
+                       });
+
+                       waitForResize(chart, function() {
+                               expect(chart).toBeChartOfSize({
+                                       dw: 400, dh: 200,
+                                       rw: 800, rh: 400,
+                               });
+
+                               done();
+                       });
+                       chart.options.devicePixelRatio = 2;
+                       chart.resize();
+               });
+
                // https://github.com/chartjs/Chart.js/issues/3790
                it('should resize the canvas if attached to the DOM after construction', function(done) {
                        var canvas = document.createElement('canvas');