chartjs / chartjs/Chart.js

Feature Request: Expose cubic interpolation algorithm as utility function

Open
#12,016 0 comments 0 reactions 0 assignees View on GitHub
type: enhancement
Dominant language
JavaScript
Stars
67.7k
Forks
11.9k
Avg merge
7h 39m
Merged PRs (30d)
5

Description

### 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:
```javascript
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);

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.