From: luke-heberling <44244147+luke-heberling@users.noreply.github.com> Date: Sun, 1 May 2022 18:28:41 +0000 (-0700) Subject: Use abs() when comparing for spanGaps (#10316) X-Git-Tag: v3.8.0~11 X-Git-Url: http://git.ipfire.org/gitweb/gitweb.cgi?a=commitdiff_plain;h=a9765042f184bb25c97cc0501c9a956d4167c448;p=thirdparty%2FChart.js.git Use abs() when comparing for spanGaps (#10316) * Use abs() when comparing for spanGaps * tests for spanGaps w/ integer (boolean already covered) * remove redundant default config from spanGaps tests --- diff --git a/src/controllers/controller.line.js b/src/controllers/controller.line.js index be96e72ed..7fe2efecb 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]; diff --git a/test/specs/controller.line.tests.js b/test/specs/controller.line.tests.js index 222726fa3..d166a4be3 100644 --- a/test/specs/controller.line.tests.js +++ b/test/specs/controller.line.tests.js @@ -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); + } + }); });