Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use abs() when comparing for spanGaps #10316

Merged
merged 3 commits into from May 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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);
}
});
});