@quartic/bokehjs
Version:
Interactive, novel data visualization
38 lines (29 loc) • 963 B
text/coffeescript
import {findLastIndex} from "core/util/array"
import {Interpolator} from "./interpolator"
export class LinearInterpolator extends Interpolator
compute: (x) ->
# Apply the transform to a single value
if == true
if x < [0] or x > [.length-1]
return null
else
if x < [0]
return [0]
if x > [.length-1]
return [.length-1]
if x == [0]
return [0]
ind = findLastIndex(, (num) -> num < x)
x1 = [ind]
x2 = [ind+1]
y1 = [ind]
y2 = [ind+1]
ret = y1 + (((x-x1) / (x2-x1)) * (y2-y1))
return ret
v_compute: (xs) ->
# Apply the tranform to a vector of values
result = new Float64Array(xs.length)
for x, idx in xs
result[idx] = this.compute(x)
return result