From 767ffc05cef14a9cd1d67c65094ba89b5f83e05b Mon Sep 17 00:00:00 2001 From: Jukka Kurkela Date: Sat, 18 Jan 2020 02:07:28 +0200 Subject: [PATCH] Resize on zoom (#6974) * Resize on zoom * Add test --- src/core/core.controller.js | 4 ---- test/specs/core.controller.tests.js | 34 +++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/src/core/core.controller.js b/src/core/core.controller.js index 4317bbfbd76..0c28c0dd48c 100644 --- a/src/core/core.controller.js +++ b/src/core/core.controller.js @@ -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'; diff --git a/test/specs/core.controller.tests.js b/test/specs/core.controller.tests.js index 1ba338c7158..aa4784fe0fc 100644 --- a/test/specs/core.controller.tests.js +++ b/test/specs/core.controller.tests.js @@ -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');