type alias Input a =
{ data : List a
, threshold : Int
, xGetter : a -> Float
, yGetter : a -> Float
}
downsample : Input a -> List a
Say we have a list of ten thousand of these:
type alias OurRecord =
{ id : Int
, time : Time.Posix
, temperature : Float
, humidity : Float
, comment : String
}
and we just want five hundred points when plotting time on the x-axis and temperature on the y-axis we can downsample it with:
LTTB.downsample
{ data = originalData
, threshold = 500
, xGetter = .time >> Time.posixToMillis >> toFloat
, yGetter = .temperature
}
which results in a List OurRecord
of length 500
sorted by .time
.