]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
Fix _isPointInArea for undefined point (#8678)
authorJukka Kurkela <jukka.kurkela@gmail.com>
Fri, 19 Mar 2021 20:09:13 +0000 (22:09 +0200)
committerGitHub <noreply@github.com>
Fri, 19 Mar 2021 20:09:13 +0000 (16:09 -0400)
src/helpers/helpers.canvas.js
test/specs/controller.line.tests.js

index e3344e6dd413c1edc8455064b7ec6cdef7f288a9..0472bddb31b09029397516ab0b5f355b661475f9 100644 (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;
 }
 
index df0d7a14f73782157d7525b0cca5930c144fc7c2..93f857832f4a0a7b2186201347f0c9c09f79a90e 100644 (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',