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

adds midpoint interpolation to stepped plots #5908

Merged
merged 3 commits into from Dec 18, 2018
Merged
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions docs/charts/line.md
Expand Up @@ -90,6 +90,7 @@ The following values are supported for `steppedLine`.
* `true`: Step-before Interpolation (eq. 'before')
* `'before'`: Step-before Interpolation
* `'after'`: Step-after Interpolation
* `'midpoint'`: Step-midpoint Interpolation
veggiesaurus marked this conversation as resolved.
Show resolved Hide resolved

If the `steppedLine` value is set to anything other than false, `lineTension` will be ignored.

Expand Down
4 changes: 4 additions & 0 deletions samples/charts/line/stepped.html
Expand Up @@ -82,6 +82,10 @@
steppedLine: 'after',
label: 'Step After Interpolation',
color: window.chartColors.purple
}, {
steppedLine: 'midpoint',
label: 'Step Midpoint Interpolation',
color: window.chartColors.blue
}];

steppedLineSettings.forEach(function(details) {
Expand Down
6 changes: 5 additions & 1 deletion src/helpers/helpers.canvas.js
Expand Up @@ -185,7 +185,11 @@ var exports = module.exports = {

lineTo: function(ctx, previous, target, flip) {
if (target.steppedLine) {
if ((target.steppedLine === 'after' && !flip) || (target.steppedLine !== 'after' && flip)) {
if (target.steppedLine === 'midpoint') {
veggiesaurus marked this conversation as resolved.
Show resolved Hide resolved
var midpoint = (previous.x + target.x) / 2.0;
ctx.lineTo(midpoint, flip ? target.y : previous.y);
ctx.lineTo(midpoint, flip ? previous.y : target.y);
} else if ((target.steppedLine === 'after' && !flip) || (target.steppedLine !== 'after' && flip)) {
ctx.lineTo(previous.x, target.y);
} else {
ctx.lineTo(target.x, previous.y);
Expand Down