MCPcopy
hub / github.com/chartjs/Chart.js / interpolate

Function interpolate

src/scales/scale.timeseries.js:12–32  ·  view source on GitHub ↗

* Linearly interpolates the given source `val` using the table. If value is out of bounds, values * at edges are used for the interpolation. * @param {object} table * @param {number} val * @param {boolean} [reverse] lookup time based on position instead of vice versa * @return {object}

(table, val, reverse)

Source from the content-addressed store, hash-verified

10 * @return {object}
11 */
12function interpolate(table, val, reverse) {
13 let lo = 0;
14 let hi = table.length - 1;
15 let prevSource, nextSource, prevTarget, nextTarget;
16 if (reverse) {
17 if (val >= table[lo].pos && val <= table[hi].pos) {
18 ({lo, hi} = _lookupByKey(table, 'pos', val));
19 }
20 ({pos: prevSource, time: prevTarget} = table[lo]);
21 ({pos: nextSource, time: nextTarget} = table[hi]);
22 } else {
23 if (val >= table[lo].time && val <= table[hi].time) {
24 ({lo, hi} = _lookupByKey(table, 'time', val));
25 }
26 ({time: prevSource, pos: prevTarget} = table[lo]);
27 ({time: nextSource, pos: nextTarget} = table[hi]);
28 }
29
30 const span = nextSource - prevSource;
31 return span ? prevTarget + (nextTarget - prevTarget) * (val - prevSource) / span : prevTarget;
32}
33
34class TimeSeriesScale extends TimeScale {
35

Callers 3

initOffsetsMethod · 0.85
getDecimalForValueMethod · 0.85
getValueForPixelMethod · 0.85

Calls 1

_lookupByKeyFunction · 0.85

Tested by

no test coverage detected