# `Fude.Live`
[🔗](https://github.com/hattoriai/fude/blob/v0.1.0/lib/fude/live.ex#L1)

New points for a chart on the page, without sending its data again.

A chart follows its assigns: when the data of `<.chart>` changes, the
chart draws again in place, its marks moving to their new places. For a
chart that grows a point at a time (a reading every second, the orders
of the day), `append/5` sends only the new rows: the chart takes them in,
keeps the last `max` of them, and moves.

    def mount(_params, _session, socket) do
      if connected?(socket), do: Phoenix.PubSub.subscribe(MyApp.PubSub, "readings")
      {:ok, assign(socket, chart: Fude.line(x: :at, y: :load), readings: Readings.last(60))}
    end

    def handle_info({:reading, reading}, socket) do
      {:noreply, Fude.Live.append(socket, "load", socket.assigns.chart, [reading], max: 60)}
    end

    <.chart id="load" chart={@chart} data={@readings} />

The new rows go through the chart's rules as its data does (types, units
of time, formats), and are added to its marks: a chart whose marks are
its rows (lines, areas and points with no aggregate). A chart that sums
or counts its rows draws again from its assigns instead.

The page's table of the data is the one of the last render.

# `append`

```elixir
@spec append(
  Phoenix.LiveView.Socket.t(),
  String.t(),
  Fude.Chart.t(),
  list() | map(),
  keyword()
) ::
  Phoenix.LiveView.Socket.t()
```

Sends new rows to the chart of an id, made with the chart they belong to
(without its data). Options:

  * `:max` - the most rows the chart keeps: the oldest go first. All of
    them when not given.

# `export`

```elixir
@spec export(Phoenix.LiveView.Socket.t(), String.t(), :svg | :png) ::
  Phoenix.LiveView.Socket.t()
```

Has the browser save the chart of an id as a file: `:svg`, or `:png`
at twice its size. The file has the chart's title, legend and source,
as on the page.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
