Mix.install([
{:kino_vega_lite, "~> 0.1.8"}
])
alias VegaLite, as: Vl
temp = fn time, degrees_c ->
%{"time" => time, "degrees_c" => degrees_c}
end
data_stream =
Stream.iterate(temp.(DateTime.utc_now(), 20.0), fn last ->
temp.(
DateTime.add(last["time"], 30, :second),
last["degrees_c"] + :rand.uniform()
)
end)
data_stream
|> Stream.take(10)
|> Enum.to_list()
# Source: https://vega.github.io/vega-lite/examples/line_color.html
vl =
Vl.new(width: 600, height: 400)
|> Vl.mark(:line)
|> Vl.encode_field(:x, "time", type: :temporal)
|> Vl.encode_field(:y, "degrees_c", type: :quantitative)
|> Kino.VegaLite.new()
data_stream
|> Stream.each(fn datum ->
Kino.VegaLite.push(vl, datum)
:timer.sleep(500)
end)
|> Stream.run()