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

Feature Request: Expose cubic interpolation algorithm as utility function #12016

Open
rhlohmeyer opened this issue Jan 30, 2025 · 0 comments
Open

Comments

@rhlohmeyer
Copy link

Feature Proposal

Description:
I'm requesting that Chart.js expose its cubic interpolation algorithm (specifically the 'monotone' mode) as a utility function that developers can use outside of the main chart drawing functionality.

Use Case:
I'm currently developing an application where I need to:

  • Display a main curve using Chart.js's excellent cubic interpolation
  • Show a moving point (date of interest indicator) that should follow the exact same curve
  • Currently, I can only approximate this with linear interpolation between points
  • Having access to the same interpolation algorithm would ensure consistent visualization

Current Workarounds:
Currently, developers needing this functionality must either:

  1. Implement their own cubic interpolation (potentially inconsistent with Chart.js)
  2. Use linear interpolation (less visually appealing)
  3. Create complex workarounds to try to access the internal calculations

Proposed Solution:
Add a utility function to Chart.js that:

  • Takes an array of points (x,y coordinates)
  • Takes a specific x value to interpolate
  • Returns the interpolated y value using the same algorithm as cubicInterpolationMode: 'monotone'

Example API could look like:

const interpolatedY = Chart.helpers.interpolateCubicMonotone(points, xValue);


### Possible Implementation

Proposed Solution:
Add a utility function to Chart.js that:
- Takes an array of points (x,y coordinates)
- Takes a specific x value to interpolate
- Returns the interpolated y value using the same algorithm as cubicInterpolationMode: 'monotone'

Example API could look like:
```javascript
const interpolatedY = Chart.helpers.interpolateCubicMonotone(points, xValue);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant