From 6c83565b211065b1dc402c3239c6d0a5fb7cd8a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Wed, 15 Nov 2023 15:43:05 +0100 Subject: [PATCH 1/3] Add Kino.VegaLite/1 and deprecate periodically/4 --- lib/kino/vega_lite.ex | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/kino/vega_lite.ex b/lib/kino/vega_lite.ex index 9b1cda4..c740611 100644 --- a/lib/kino/vega_lite.ex +++ b/lib/kino/vega_lite.ex @@ -12,8 +12,7 @@ defmodule Kino.VegaLite do |> Vl.mark(:line) |> Vl.encode_field(:x, "x", type: :quantitative) |> Vl.encode_field(:y, "y", type: :quantitative) - |> Kino.VegaLite.new() - |> Kino.render() + |> Kino.VegaLite.render() for i <- 1..300 do point = %{x: i / 10, y: :math.sin(i / 10)} @@ -52,6 +51,14 @@ defmodule Kino.VegaLite do ) end + @doc """ + Renders and returns a new kino with the given VegaLite definition. + """ + @spec render(VegaLite.t()) :: t() + def render(vl) when is_struct(vl, VegaLite) do + Kino.JS.Live.new(__MODULE__, vl) |> Kino.render() + end + @doc """ Appends a single data point to the graphic dataset. @@ -145,6 +152,7 @@ defmodule Kino.VegaLite do The callback is run for the first time immediately upon registration. """ + @deprecated "Use Kino.listen/3 instead" @spec periodically(t(), pos_integer(), term(), (term() -> {:cont, term()} | :halt)) :: :ok def periodically(kino, interval_ms, acc, fun) do Kino.JS.Live.cast(kino, {:periodically, interval_ms, acc, fun}) From 1bbcdb72f16fa1e8d7be9093db1ad3624bde60b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Wed, 15 Nov 2023 15:44:02 +0100 Subject: [PATCH 2/3] wip --- lib/kino/vega_lite.ex | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/kino/vega_lite.ex b/lib/kino/vega_lite.ex index c740611..ce506ff 100644 --- a/lib/kino/vega_lite.ex +++ b/lib/kino/vega_lite.ex @@ -53,10 +53,14 @@ defmodule Kino.VegaLite do @doc """ Renders and returns a new kino with the given VegaLite definition. + + It is equivalent to: + + vega_lite |> Kino.VegaLite.new() |> Kino.render() """ @spec render(VegaLite.t()) :: t() def render(vl) when is_struct(vl, VegaLite) do - Kino.JS.Live.new(__MODULE__, vl) |> Kino.render() + vl |> new() |> Kino.render() end @doc """ From da9977f753bf076880d51b803c47610c2c023502 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonatan=20K=C5=82osko?= Date: Wed, 15 Nov 2023 16:10:33 +0100 Subject: [PATCH 3/3] Update vega_lite_test.exs --- test/kino/vega_lite_test.exs | 20 -------------------- 1 file changed, 20 deletions(-) diff --git a/test/kino/vega_lite_test.exs b/test/kino/vega_lite_test.exs index 8034e1a..6719c0c 100644 --- a/test/kino/vega_lite_test.exs +++ b/test/kino/vega_lite_test.exs @@ -93,26 +93,6 @@ defmodule Kino.VegaLiteTest do assert_broadcast_event(kino, "push", %{data: [], dataset: nil, window: 0}) end - test "periodically/4 evaluates the given callback in background until stopped" do - kino = start_kino() - - parent = self() - - Kino.VegaLite.periodically(kino, 1, 1, fn n -> - send(parent, {:ping, n}) - - if n < 2 do - {:cont, n + 1} - else - :halt - end - end) - - assert_receive {:ping, 1} - assert_receive {:ping, 2} - refute_receive {:ping, 3}, 5 - end - defp start_kino() do Vl.new() |> Vl.mark(:point)