mirror of
https://github.com/livebook-dev/livebook.git
synced 2024-11-11 01:28:47 +08:00
80bed1aa06
* 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
32 lines
844 B
Elixir
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
|