]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
Use abs() when comparing for spanGaps (#10316)
authorluke-heberling <44244147+luke-heberling@users.noreply.github.com>
Sun, 1 May 2022 18:28:41 +0000 (11:28 -0700)
committerGitHub <noreply@github.com>
Sun, 1 May 2022 18:28:41 +0000 (14:28 -0400)
* Use abs() when comparing for spanGaps

* tests for spanGaps w/ integer (boolean already covered)

* remove redundant default config from spanGaps tests

src/controllers/controller.line.js
test/specs/controller.line.tests.js

index be96e72ed793fb94c9bb27fab106e2f420e47327..7fe2efecbcb8285ea9101c812a675dd6bdab4735 100644 (file)
@@ -68,7 +68,7 @@ export default class LineController extends DatasetController {
       const vPixel = properties[vAxis] = reset || nullData ? vScale.getBasePixel() : vScale.getPixelForValue(_stacked ? this.applyStack(vScale, parsed, _stacked) : parsed[vAxis], i);
 
       properties.skip = isNaN(iPixel) || isNaN(vPixel) || nullData;
-      properties.stop = i > 0 && (parsed[iAxis] - prevParsed[iAxis]) > maxGapLength;
+      properties.stop = i > 0 && (Math.abs(parsed[iAxis] - prevParsed[iAxis])) > maxGapLength;
       if (segment) {
         properties.parsed = parsed;
         properties.raw = _dataset.data[i];
index 222726fa30a653f05516649d52bde3faca5187b1..d166a4be36436068aaa918e0d335069f8d57fee8 100644 (file)
@@ -964,4 +964,56 @@ describe('Chart.controllers.line', function() {
     expect(isNaN(x)).toBe(false);
     expect(isNaN(y)).toBe(false);
   });
+
+  it('should honor spangap interval forwards', function() {
+    var chart = window.acquireChart({
+      type: 'line',
+      data: {
+        datasets: [{
+          spanGaps: 10,
+          data: [{x: 10, y: 123}, {x: 15, y: 124}, {x: 26, y: 125}, {x: 30, y: 126}, {x: 35, y: 127}],
+          label: 'dataset1',
+        }],
+      },
+      options: {
+        scales: {
+          x: {
+            type: 'linear',
+          }
+        }
+      }
+    });
+
+    var meta = chart.getDatasetMeta(0);
+    for (var i = 0; i < meta.data.length; ++i) {
+      var point = meta.data[i];
+      expect(point.stop).toBe(i === 2);
+    }
+  });
+
+  it('should honor spangap interval backwards', function() {
+    var chart = window.acquireChart({
+      type: 'line',
+      data: {
+        datasets: [{
+          spanGaps: 10,
+          data: [{x: 35, y: 123}, {x: 30, y: 124}, {x: 26, y: 125}, {x: 15, y: 126}, {x: 10, y: 127}],
+          label: 'dataset1',
+        }],
+      },
+      options: {
+        scales: {
+          x: {
+            type: 'linear',
+          }
+        }
+      }
+    });
+
+    var meta = chart.getDatasetMeta(0);
+    for (var i = 0; i < meta.data.length; ++i) {
+      var point = meta.data[i];
+      expect(point.stop).toBe(i === 3);
+    }
+  });
 });