Skip to content

Commit

Permalink
Fix: don't draw segments out of bounds (#8911)
Browse files Browse the repository at this point in the history
  • Loading branch information
kurkle committed Apr 16, 2021
1 parent d5f4a82 commit f94e882
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/elements/element.line.js
Expand Up @@ -34,17 +34,19 @@ function getLineMethod(options) {
return lineTo;
}

function pathVars(points, segment, params) {
params = params || {};
function pathVars(points, segment, params = {}) {
const count = points.length;
const start = Math.max(params.start || 0, segment.start);
const end = Math.min(params.end || count - 1, segment.end);
const {start: paramsStart = 0, end: paramsEnd = count - 1} = params;
const {start: segmentStart, end: segmentEnd} = segment;
const start = Math.max(paramsStart, segmentStart);
const end = Math.min(paramsEnd, segmentEnd);
const outside = paramsStart < segmentStart && paramsEnd < segmentStart || paramsStart > segmentEnd && paramsEnd > segmentEnd;

return {
count,
start,
loop: segment.loop,
ilen: end < start ? count + end - start : end - start
ilen: end < start && !outside ? count + end - start : end - start
};
}

Expand Down
30 changes: 30 additions & 0 deletions test/fixtures/controller.line/issue-8902.js
@@ -0,0 +1,30 @@
module.exports = {
description: 'https://github.com/chartjs/Chart.js/issues/8902',
config: {
type: 'line',
data: {
labels: [1, 2, 3, 4, 5, 6, 7, 8],
datasets: [{
data: [65, 59, NaN, 48, 56, 57, 40],
borderColor: 'rgb(75, 192, 192)',
}]
},
options: {
plugins: false,
scales: {
x: {
type: 'linear',
min: 1,
max: 3
}
}
}
},
options: {
spriteText: true,
canvas: {
height: 256,
width: 512
}
}
};
Binary file added test/fixtures/controller.line/issue-8902.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit f94e882

Please sign in to comment.