Skip to content

Commit

Permalink
Use abs() when comparing for spanGaps (#10316)
Browse files Browse the repository at this point in the history
* Use abs() when comparing for spanGaps

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

* remove redundant default config from spanGaps tests
  • Loading branch information
luke-heberling committed May 1, 2022
1 parent d8d69f5 commit a976504
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/controllers/controller.line.js
Expand Up @@ -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];
Expand Down
52 changes: 52 additions & 0 deletions test/specs/controller.line.tests.js
Expand Up @@ -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);
}
});
});

0 comments on commit a976504

Please sign in to comment.