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

Fix line segments with alignToPixel #9042

Merged
merged 1 commit into from May 7, 2021
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
5 changes: 5 additions & 0 deletions src/helpers/helpers.segment.js
Expand Up @@ -100,6 +100,11 @@ export function _boundSegment(segment, points, bounds) {
}

value = normalize(point[property]);

if (value === prevValue) {
continue;
}

inside = between(value, startBound, endBound);

if (subStart === null && shouldStart()) {
Expand Down
46 changes: 46 additions & 0 deletions test/fixtures/plugin.filler/line/segments/alignToPixels.js
@@ -0,0 +1,46 @@
module.exports = {
config: {
type: 'line',
data: {
datasets: [
{
data: [
{x: 0, y: 0},
{x: 1, y: 20},
{x: 1.00001, y: 30},
{x: 2, y: 100},
{x: 2.00001, y: 100}
],
backgroundColor: '#FF000070',
borderColor: 'black',
radius: 0,
segment: {
borderDash: ctx => ctx.p0.parsed.x > 1 ? [10, 5] : undefined,
},
fill: true
}
]
},
options: {
plugins: {
legend: false
},
scales: {
x: {
type: 'linear',
alignToPixels: true,
display: false
},
y: {
display: false
}
}
}
},
options: {
canvas: {
width: 300,
height: 240
}
}
};
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions test/specs/helpers.segment.tests.js
Expand Up @@ -49,5 +49,13 @@ describe('helpers.segments', function() {
{start: 3, end: 4, loop: false, style: undefined},
]);
});

it('should find correct segments when there are multiple points with same property value', function() {
const repeatedPoints = [{x: 1, y: 5}, {x: 1, y: 6}, {x: 2, y: 5}, {x: 2, y: 6}, {x: 3, y: 5}, {x: 3, y: 6}, {x: 3, y: 7}];
expect(_boundSegment({start: 0, end: 6, loop: false}, repeatedPoints, {property: 'x', start: 1, end: 1.1})).toEqual([{start: 0, end: 2, loop: false, style: undefined}]);
expect(_boundSegment({start: 0, end: 6, loop: false}, repeatedPoints, {property: 'x', start: 2, end: 2.1})).toEqual([{start: 2, end: 4, loop: false, style: undefined}]);
expect(_boundSegment({start: 0, end: 6, loop: false}, repeatedPoints, {property: 'x', start: 2, end: 3.1})).toEqual([{start: 2, end: 6, loop: false, style: undefined}]);
expect(_boundSegment({start: 0, end: 6, loop: false}, repeatedPoints, {property: 'x', start: 0, end: 8})).toEqual([{start: 0, end: 6, loop: false, style: undefined}]);
});
});
});