Fix _isPointInArea for undefined point (#8678)

This commit is contained in:
Jukka Kurkela 2021-03-19 22:09:13 +02:00 committed by GitHub
parent 9a0a509385
commit 81342d6c65
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 1 deletions

View File

@ -251,7 +251,7 @@ export function drawPoint(ctx, options, x, y) {
export function _isPointInArea(point, area, margin) {
margin = margin || 0.5; // margin - default is to match rounded decimals
return point.x > area.left - margin && point.x < area.right + margin &&
return point && point.x > area.left - margin && point.x < area.right + margin &&
point.y > area.top - margin && point.y < area.bottom + margin;
}

View File

@ -42,6 +42,23 @@ describe('Chart.controllers.line', function() {
expect(meta.yAxisID).toBe('y');
});
it('Should not throw with empty dataset when tension is non-zero', function() {
// https://github.com/chartjs/Chart.js/issues/8676
function createChart() {
return window.acquireChart({
type: 'line',
data: {
datasets: [{
data: [],
tension: 0.5
}],
labels: []
},
});
}
expect(createChart).not.toThrow();
});
it('Should create line elements and point elements for each data item during initialization', function() {
var chart = window.acquireChart({
type: 'line',