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 for enabling monotone cubicInterpolationMode when tension is 0 #9008

Merged
merged 1 commit into from Apr 30, 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
8 changes: 4 additions & 4 deletions src/elements/element.line.js
Expand Up @@ -27,7 +27,7 @@ function getLineMethod(options) {
return _steppedLineTo;
}

if (options.tension) {
if (options.tension || options.cubicInterpolationMode === 'monotone') {
return _bezierCurveTo;
}

Expand Down Expand Up @@ -182,7 +182,7 @@ function fastPathSegment(ctx, line, segment, params) {
function _getSegmentMethod(line) {
const opts = line.options;
const borderDash = opts.borderDash && opts.borderDash.length;
const useFastPath = !line._decimated && !line._loop && !opts.tension && !opts.stepped && !borderDash;
const useFastPath = !line._decimated && !line._loop && !opts.tension && opts.cubicInterpolationMode !== 'monotone' && !opts.stepped && !borderDash;
return useFastPath ? fastPathSegment : pathSegment;
}

Expand All @@ -194,7 +194,7 @@ function _getInterpolationMethod(options) {
return _steppedInterpolation;
}

if (options.tension) {
if (options.tension || options.cubicInterpolationMode === 'monotone') {
return _bezierInterpolation;
}

Expand Down Expand Up @@ -260,7 +260,7 @@ export default class LineElement extends Element {
updateControlPoints(chartArea) {
const me = this;
const options = me.options;
if (options.tension && !options.stepped && !me._pointsUpdated) {
if ((options.tension || options.cubicInterpolationMode === 'monotone') && !options.stepped && !me._pointsUpdated) {
const loop = options.spanGaps ? me._loop : me._fullLoop;
_updateBezierControlPoints(me._points, options, chartArea, loop);
me._pointsUpdated = true;
Expand Down
27 changes: 27 additions & 0 deletions test/fixtures/element.line/cubicInterpolationMode/monotone.js
@@ -0,0 +1,27 @@
module.exports = {
config: {
type: 'line',
data: {
datasets: [
{
data: [{x: 1, y: 10}, {x: 5, y: 0}, {x: 15, y: -10}, {x: 19, y: -5}],
borderColor: 'red',
fill: false,
cubicInterpolationMode: 'monotone'
}
]
},
options: {
scales: {
x: {type: 'linear', display: false, min: 0, max: 20},
y: {display: false, min: -15, max: 15}
}
}
},
options: {
canvas: {
height: 256,
width: 512
}
}
};
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/fixtures/plugin.filler/line/before-dataset-draw.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/fixtures/plugin.filler/line/before-datasets-draw.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/fixtures/plugin.filler/line/boundary/origin-spline-span.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/fixtures/plugin.filler/line/boundary/origin-spline.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/fixtures/plugin.filler/line/dataset/span-dual.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/fixtures/plugin.filler/line/dataset/spline-span-above.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/fixtures/plugin.filler/line/dataset/spline-span-below.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/fixtures/plugin.filler/line/dataset/spline-span.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/fixtures/plugin.filler/line/dataset/spline.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.