Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[2.9] FitBoxes recursion when dimensions are NaN #7853

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/core/core.layouts.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ function updateDims(chartArea, params, layout) {
chartArea.h = newHeight;

// return true if chart area changed in layout's direction
return layout.horizontal ? newWidth !== chartArea.w : newHeight !== chartArea.h;
var sizes = layout.horizontal ? [newWidth, chartArea.w] : [newHeight, chartArea.h];
return sizes[0] !== sizes[1] && (!isNaN(sizes[0]) || !isNaN(sizes[1]));
}
}

Expand Down
40 changes: 40 additions & 0 deletions test/specs/core.layouts.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -653,5 +653,45 @@ describe('Chart.layouts', function() {
expect(yAxis.width).toBeCloseToPixel(33);
expect(yAxis.ticks).toEqual(['2.5', '2.0', '1.5', '1.0', '0.5', '0']);
});

it('should correctly handle NaN dimensions', function() {

// issue #7761: Maximum call stack size exceeded
var chartContainer = document.createElement('div');
chartContainer.style.width = '600px';
chartContainer.style.height = '400px';

var chartCanvas = document.createElement('canvas');
chartContainer.appendChild(chartCanvas);

var chart = new Chart(chartCanvas, {
type: 'line',
responsive: true,
data: {
labels: ['Red', 'Blue', 'Yellow', 'Green', 'Purple', 'Orange'],
datasets: [{
label: '# of Votes',
data: [12, 19, 3, 5, 2, 3]
}]
},
options: {
scales: {
yAxes: [{
type: 'linear',
label: 'first axis',
position: 'right'
}, {
type: 'linear',
label: 'second axis',
position: 'right'
}]
}
}
});

expect(chart.width).toBeNaN();
expect(chart.height).toBeNaN();

});
});
});