Skip to content

Commit

Permalink
Resize on zoom (#6974)
Browse files Browse the repository at this point in the history
* Resize on zoom
* Add test
  • Loading branch information
kurkle authored and etimberg committed Jan 18, 2020
1 parent 35adcd6 commit 767ffc0
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
4 changes: 0 additions & 4 deletions src/core/core.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
34 changes: 34 additions & 0 deletions test/specs/core.controller.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down

0 comments on commit 767ffc0

Please sign in to comment.