-
Notifications
You must be signed in to change notification settings - Fork 11.9k
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
[ Line Chart ] Monotone cubic interpolation #3086
Comments
@MatthieuRivaud these would be great to have. Perhaps we could have an option in the line element config to enable this. I agree that a new What are your thoughts on something like this as a config option? options: {
elements: {
line: {
cubicInterpolationMode: 'monotone'
}
}
} |
I used a config option very similar to this ( I'll try to implement Questions :
|
I think I can answer your questions
|
I'm having a hard time implementing I also think I will have to clamp the strength of the control points (the norm of the resulting vector) : I believe the monotone cubic interpolation algorithm cannot guarantee the monotonicity if the control point is further than 1/3rd of the distance between data points (not really sure about that, my math is a bit fuzzy). I could also ignore the tension parameter, and use the 1/3 ratio (which I believe is the exact ratio to use for cubic interpolation, according to the last paragraph in https://en.wikipedia.org/wiki/Cubic_interpolation#Representations, but I may be mistaken). |
Mmm, Ok, I had a bug in my hacked scatter.html sample file. I can now activate monotone cubic interpolation on a scatter graph, and can confirm the result is absolute bonkers ... ^^ There must be a mean to adapt the algorithm to keep local extremums in 2d (if it has any sense at all), but this is another work for another day. (I also don't think monotonicity has a sense in this case, but my math is much too rusty to give a definite answer). What test would you recommend in order to detect the scatter case ? Both x-axis and y-axis in linear mode for the dataset to interpolate ? |
I wouldn't constrain yourself to having the same signature as Since this is new, I think it is fine to ignore the tension and instead use 1/3. We will just need to make sure the docs are clear on this. What if your algorithm worked on monotonic subsets of the data? The normal case would only have 1 monotonic section but scatter plots would not necessarily be. The worst case would be monotonic subsets that change with every point. If this strategy works, you won't need a specific test for the scatter chart. |
The algorithm already handles minute changes in monotony. What it does not handle is datasets where the x distribution of data points isn't monotonic (i.e. when the dataset isn't of the form The scatter chart displays a function of There probably is a way to preserve local "extremums" (ensure the interpolated curve does not go "further" than the nearest data points), but I do not know the math, and it seems much more work than necessary for a graph that does not really need a better interpolation than the one we have now. [1] like this one : http://mathworld.wolfram.com/VectorOrdering.html |
OK, I finished coding
How do we proceed ?
[1] https://en.wikipedia.org/wiki/Pure_function |
@MatthieuRivaud awesome! The I generally use I would recommend cloning the repository then creating a new branch for your changes. Push your changes up to the branch and then create a pull request. :) Thanks for implementing this :) |
I finally have my node installation (mostly) working. I had to manually install a lot of packages (which weren't auto-installed by My code does pass
(I successfully ran Also : I assume the actual code and doc review will happen when processing the pull request. Correct ? |
I think that error comes from https://github.com/chartjs/Chart.js/blob/master/package.json#L42 The actual review will be on the pull request. The tests and linting will auto run there as well so we'll have confirmation that nothing broke. |
I'm not sure why you're seeing the issue with the bezier control points after the skipped line. They should definitely be used. |
I found the issue with the control points : the I think I will proceed with the pull request very soon. |
Ok, pull request is green. I will open a new issue for the Thanks for the guidance. |
Great! thanks @MatthieuRivaud |
I'm having second thoughts on the
This would give room to add other interpolation modes if need be. This change may need a dedicated #issue and PR, though. Thoughts ? |
@MatthieuRivaud that's a good change in the long run, but it'd require a major version bump since the API is changing, or at least, we would have to support all the old options even if the new option is the way going forward.. I think because of this is would have to be its own issue |
Yep, I agree. Maybe for v3 ^^ |
First, thanks for all the good work.
I just started using Charts.js (have tinkered a bit with line charts so far), and it seems the cubic interpolation used does not preserves monotonicity of the provided data (which makes sense, because said algorithm is very generic, probably because Charts.js has to interpolate for a lot of different data representations).
I think however that monotone cubic interpolation [1] has several advantages over the classic cubic interpolation :
I hacked the current Chart.js interpolation in my repository to switch to monotone cubic interpolation if wanted, and it seems to work quite well (I already did the math for a personal charting project in SVG, so it was quite easy to replicate in Charts.js due to the use of Bezier curves for its existing cubic interpolation).
Are you interested in uplifting my changes to the official Charts.js repository ?
Regards,
[1] https://en.wikipedia.org/wiki/Monotone_cubic_interpolation
Notes :
The text was updated successfully, but these errors were encountered: