Skip to content

Commit

Permalink
Fix for enabling monotone cubicInterpolationMode when tension is 0 (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
nagix committed Apr 30, 2021
1 parent 12bf256 commit dffc086
Show file tree
Hide file tree
Showing 13 changed files with 31 additions and 4 deletions.
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.

0 comments on commit dffc086

Please sign in to comment.