livebook/lib/livebook_web/live/output/vega_lite_static_component.ex

18 lines
450 B
Elixir
Raw Normal View History

defmodule LivebookWeb.Output.VegaLiteStaticComponent do
use LivebookWeb, :live_component
@impl true
def update(assigns, socket) do
socket = assign(socket, id: assigns.id)
{:ok, push_event(socket, "vega_lite:#{socket.assigns.id}:init", %{"spec" => assigns.spec})}
end
@impl true
def render(assigns) do
~H"""
<div id={"vega-lite-#{@id}"} phx-hook="VegaLite" phx-update="ignore" data-id={@id}>
</div>
"""
end
end