livebook/lib/livebook_web/live/output/vega_lite_dynamic_live.ex
Jonatan Kłosko 80bed1aa06
Delegate output formatting rules to Kino (#309)
* Delegate output formatting rules to Kino

* Update naming

* Group output components and views

* Fallback to inspect when Kino.Render.to_output/1 fails

* Update naming

* Add reference to Kino
2021-06-01 17:47:03 +02:00

32 lines
844 B
Elixir

defmodule LivebookWeb.Output.VegaLiteDynamicLive do
use LivebookWeb, :live_view
@impl true
def mount(_params, %{"pid" => pid, "id" => id}, socket) do
send(pid, {:connect, self()})
{:ok, assign(socket, id: id)}
end
@impl true
def render(assigns) do
~L"""
<div id="vega-lite-<%= @id %>" phx-hook="VegaLite" phx-update="ignore" data-id="<%= @id %>">
</div>
"""
end
@impl true
def handle_info({:connect_reply, %{spec: spec}}, socket) do
{:noreply, push_event(socket, "vega_lite:#{socket.assigns.id}:init", %{"spec" => spec})}
end
def handle_info({:push, %{data: data, dataset: dataset, window: window}}, socket) do
{:noreply,
push_event(socket, "vega_lite:#{socket.assigns.id}:push", %{
"data" => data,
"dataset" => dataset,
"window" => window
})}
end
end