Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/jossmac/interpolate-range

💯 Super simple numeric range interpolation
https://github.com/jossmac/interpolate-range

animation chart curve graph interpolate range

Last synced: about 4 hours ago
JSON representation

💯 Super simple numeric range interpolation

Awesome Lists containing this project

README

        

# Interpolate Range

Numeric range interpolation à la ReactNative's `AnimatedValue.interpolate()`. No dependencies, handy for animation or plotting points on a chart.

### Props

Name | Type | Description
--- | --- | ---
`input` | `[number, number]` | Input range _(required)_
`output` | `[number, number]` | Output range _(required)_
`clamp` | `boolean` | Restrict the returned value to the output range
`fn` | `(from, to, x) => number` | Alternative function to call on the value

### Usage

```js
import interpolate from 'interpolate-range';

function generateCurve({ floor, ceil, total }) {
const data = [];
const int = interpolate({
inputRange: [floor, ceil],
outputRange: [0, 1],
clamp: true,
});

for (let k = 0; k < total; k++) {
data.push({ x: k, y: int(k) });
}

return data;
}
```