Mix.install([
{:kino, "~> 0.4.1"},
{:vega_lite, "~> 0.1.1"}
])
alias VegaLite, as: Vl
graph =
Vl.new(height: 300, width: 300)
|> Vl.mark(:line)
|> Vl.encode_field(:x, "day", type: :quantitative)
|> Vl.encode_field(:y, "count", type: :quantitative)
# |> Vl.encode_field(:y, "count", type: :quantitative, scale: [type: :log])
|> Kino.VegaLite.new()
|> Kino.render()
Kino.VegaLite.periodically(
graph,
100,
{0, {0, 3, 2, 0, 0, 1, 0, 1, 0}},
fn {day, {t0, t1, t2, t3, t4, t5, t6, t7, t8} = t} ->
count = Tuple.sum(t)
Kino.VegaLite.push(graph, %{day: day, count: count})
if day < 200 do
t = {t1, t2, t3, t4, t5, t6, t7 + t0, t8, t0}
{:cont, {day + 1, t}}
else
:halt
end
end
)
Change the initial value and see how the histogram stabilizes over time.
graph =
Vl.new(height: 300, width: 300)
|> Vl.mark(:bar)
|> Vl.encode_field(:x, "timer", type: :nominal)
|> Vl.encode_field(:y, "count", type: :quantitative)
|> Kino.VegaLite.new()
|> Kino.render()
Kino.VegaLite.periodically(
graph,
100,
{0, {0, 3, 2, 0, 0, 1, 0, 1, 0}},
fn {day, {t0, t1, t2, t3, t4, t5, t6, t7, t8} = t} ->
histogram_points =
t
|> Tuple.to_list()
|> Enum.with_index()
|> Enum.map(fn {count, timer} -> %{count: count, timer: timer} end)
Kino.VegaLite.push_many(graph, histogram_points, window: length(histogram_points))
if day < 200 do
t = {t1, t2, t3, t4, t5, t6, t7 + t0, t8, t0}
{:cont, {day + 1, t}}
else
:halt
end
end
)