From 81342d6c65650e5c6b78bcc476ecc6fd4503cb5a Mon Sep 17 00:00:00 2001 From: Jukka Kurkela Date: Fri, 19 Mar 2021 22:09:13 +0200 Subject: [PATCH] Fix _isPointInArea for undefined point (#8678) --- src/helpers/helpers.canvas.js | 2 +- test/specs/controller.line.tests.js | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/helpers/helpers.canvas.js b/src/helpers/helpers.canvas.js index e3344e6dd41..0472bddb31b 100644 --- a/src/helpers/helpers.canvas.js +++ b/src/helpers/helpers.canvas.js @@ -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; } diff --git a/test/specs/controller.line.tests.js b/test/specs/controller.line.tests.js index df0d7a14f73..93f857832f4 100644 --- a/test/specs/controller.line.tests.js +++ b/test/specs/controller.line.tests.js @@ -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',