@quartic/bokehjs
Version:
Interactive, novel data visualization
50 lines (38 loc) • 1.22 kB
text/coffeescript
import {Interpolator} from "./interpolator"
import * as p from "core/properties"
import {min, findIndex, findLastIndex} from "core/util/array"
export class StepInterpolator extends Interpolator
{
mode: [ p.TransformStepMode, "after"]
}
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]
ind = -1
if == "after"
ind = findLastIndex(, (num) -> x >= num)
if == "before"
ind = findIndex(, (num) -> x <= num)
if == "center"
diffs = (Math.abs(tx - x) for tx in )
mdiff = min(diffs)
ind = findIndex(diffs, (num) -> mdiff == num)
if ind != -1
ret = [ind]
else
ret = null
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