# `ECharts.Kino`
[🔗](https://github.com/Mateus-M-Reis/echarts/blob/main/lib/echarts/kino.ex#L2)

Livebook integration for ECharts.

The kino renders the chart in place and keeps a small server process, so
the chart can be updated without re-evaluating the cell and browser
events can be delivered to Elixir.

## Rendering

    ECharts.Kino.new(%{
      xAxis: %{type: "category", data: ["Mon", "Tue", "Wed"]},
      yAxis: %{type: "value"},
      series: [%{type: "line", data: [120, 200, 150]}]
    })

Use `render/2` when you do not need to keep the kino around:

    ECharts.Kino.render(option, height: 360)

## Live updates

    chart = ECharts.Kino.new(option)

    for point <- stream do
      ECharts.Kino.push(chart, updated_option)
    end

`push/2` accepts a raw option map or an `ECharts.Chart`.

## Events

The chart forwards the events listed in the `:events` option (by default
`"click"` and `"legendselectchanged"`). Subscribe the current process:

    ECharts.Kino.subscribe(chart, :chart_events)

    receive do
      {:chart_events, %{"type" => "click", "data" => data}} ->
        IO.inspect(data)
    end

Subscribe to a single event type with `subscribe(chart, tag, :click)`, or
subscribe another process with `subscribe(chart, pid, tag)`.

Assets are public. Never put secrets in the option map.

# `kino`

```elixir
@type kino() :: Kino.JS.Live.t()
```

# `new`

```elixir
@spec new(ECharts.option() | ECharts.Chart.t(), keyword()) :: kino()
```

Builds a live kino from an ECharts option map or an `ECharts.Chart`.

Accepts the options of `ECharts.new/2` when given an option map.

# `push`

```elixir
@spec push(kino(), ECharts.option() | ECharts.Chart.t()) :: :ok
```

Pushes a new chart to every connected client.

Returns `:ok`. The update runs asynchronously; the chart is replaced in
place.

# `render`

```elixir
@spec render(ECharts.option() | ECharts.Chart.t(), keyword()) :: kino()
```

Renders the chart immediately and returns the kino.

This is a convenience for notebook cells where you do not need to keep a
reference to the kino.

# `subscribe`

```elixir
@spec subscribe(kino(), atom()) :: :ok
```

Subscribes a process to chart events.

Without a `pid`, subscribes the calling process. `filter` is `:all`
(default) or an event name such as `:click`.

Messages are sent as `{tag, payload}` where `payload` is
`%{"type" => event_name, "data" => event_data}`.

# `subscribe`

```elixir
@spec subscribe(kino(), atom(), atom() | String.t()) :: :ok
@spec subscribe(kino(), pid(), atom()) :: :ok
```

# `subscribe`

```elixir
@spec subscribe(kino(), pid(), atom(), atom() | String.t()) :: :ok
```

---

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