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

Support monotone cubic interpolation for vertical line charts #9084

Merged
merged 2 commits into from May 14, 2021

Conversation

nagix
Copy link
Contributor

@nagix nagix commented May 13, 2021

This PR adds support for monotone cubic interpolation for vertical line charts.

Version 3.2.1: https://jsfiddle.net/nagix/L32jmkuf/
Screen Shot 2021-05-13 at 1 51 36 PM

This PR: https://jsfiddle.net/nagix/k4frLjq2/
Screen Shot 2021-05-13 at 1 59 02 PM

Fixes #9083.

@nagix
Copy link
Contributor Author

nagix commented May 13, 2021

This PR also answers the first question of this comment.

@etimberg etimberg added this to the Version 3.3 milestone May 13, 2021
const me = this;
const options = me.options;
if ((options.tension || options.cubicInterpolationMode === 'monotone') && !options.stepped && !me._pointsUpdated) {
const loop = options.spanGaps ? me._loop : me._fullLoop;
_updateBezierControlPoints(me._points, options, chartArea, loop);
_updateBezierControlPoints(me._points, options, chartArea, loop, indexAxis);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure about it, but it could be better to include the indexAxis in options?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it's possible to include it in options, and it's more flexible than adding an argument to functions. My concern is that indexAxis is rarely set per element, so exposing this option to users may increase complexity of the configuration. @etimberg Any thoughts?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinkin about the lineElement, which is per dataset.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, it is the lineElement. But even in that case, it is not usual for each line to have a different index axis (x or y).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, did not read your concern properly. It already is possible to configure the indexAxis per dataset:
https://codepen.io/kurkle/pen/vYxEpLG

But I agree it would not be common.

It might have been a mistake to move the control point update procedure to the line element, in the MVC point of view, which I rarely think of. But since its there and now needs to know the index axis to work properly, I think the indexAxis can be considered to be a line option.

I don't see a big difference on how the option is passed to the line, but it would remove the need for that argument from the updateControlPoints call. It would also make it available to external code maybe in a bit more straight forward way. (When interacting a line, you'd get it from line.options)

If an plugin calls the updateControlPoints (like the filler does), it would be possible to provide a contradicting value compared to the line controller. Containing the value in the options would prevent those kinds of mistakes.

All that said, I think its really not a big issue either way, so lets hear what @etimberg thinks about it :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have strong opinions on which way. 😄 I slightly prefer the options just for the external interaction case but I won't hold up the PR over it.

@etimberg etimberg merged commit 0ba5c70 into chartjs:master May 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Vertical line chart doesn't calculate monotone cubic interpolation correctly
3 participants