From cfec8011d5fa921f2c4de590fcc0879acb2adef2 Mon Sep 17 00:00:00 2001 From: Luke Heberling Date: Sat, 23 Apr 2022 15:26:33 -0700 Subject: [PATCH 1/3] Use abs() when comparing for spanGaps --- src/controllers/controller.line.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/controllers/controller.line.js b/src/controllers/controller.line.js index be96e72ed79..7fe2efecbcb 100644 --- a/src/controllers/controller.line.js +++ b/src/controllers/controller.line.js @@ -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]; From 438feb7e940a78db2e41439d7a16de0b407567aa Mon Sep 17 00:00:00 2001 From: Luke Heberling Date: Tue, 26 Apr 2022 21:06:43 -0700 Subject: [PATCH 2/3] tests for spanGaps w/ integer (boolean already covered) --- test/specs/controller.line.tests.js | 56 +++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/test/specs/controller.line.tests.js b/test/specs/controller.line.tests.js index 222726fa30a..50b5cd131ac 100644 --- a/test/specs/controller.line.tests.js +++ b/test/specs/controller.line.tests.js @@ -964,4 +964,60 @@ 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: [{ + xAxisKey: 'x', + yAxisKey: 'y', + 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: [{ + xAxisKey: 'x', + yAxisKey: 'y', + 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); + } + }); }); From b8880d92839ba72ecfc5bb462c0874533e9c6b70 Mon Sep 17 00:00:00 2001 From: Luke Heberling Date: Tue, 26 Apr 2022 21:32:53 -0700 Subject: [PATCH 3/3] remove redundant default config from spanGaps tests --- test/specs/controller.line.tests.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/test/specs/controller.line.tests.js b/test/specs/controller.line.tests.js index 50b5cd131ac..d166a4be364 100644 --- a/test/specs/controller.line.tests.js +++ b/test/specs/controller.line.tests.js @@ -970,8 +970,6 @@ describe('Chart.controllers.line', function() { type: 'line', data: { datasets: [{ - xAxisKey: 'x', - yAxisKey: 'y', 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', @@ -998,8 +996,6 @@ describe('Chart.controllers.line', function() { type: 'line', data: { datasets: [{ - xAxisKey: 'x', - yAxisKey: 'y', 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',