View Source Kino.VegaLite (KinoVegaLite v0.1.13)

A kino wrapping VegaLite graphic.

This kino allow for rendering regular VegaLite graphic and then streaming new data points to update the graphic.

Examples

chart =
  Vl.new(width: 400, height: 400)
  |> Vl.mark(:line)
  |> Vl.encode_field(:x, "x", type: :quantitative)
  |> Vl.encode_field(:y, "y", type: :quantitative)
  |> Kino.VegaLite.render()

for i <- 1..300 do
  point = %{x: i / 10, y: :math.sin(i / 10)}
  Kino.VegaLite.push(chart, point)
  Process.sleep(25)
end

Summary

Functions

Removes all data points from the graphic dataset.

Applies global configuration options for the VegaLite kinos.

Creates a new kino with the given VegaLite definition.

Registers a callback to run periodically in the kino process.

Appends a single data point to the graphic dataset.

Appends a number of data points to the graphic dataset.

Renders and returns a new kino with the given VegaLite definition.

Updates a vega-lite parameter's value.

Types

Functions

@spec clear(
  t(),
  keyword()
) :: :ok

Removes all data points from the graphic dataset.

Options

  • dataset - name of the targeted dataset from the VegaLite specification. Defaults to the default anonymous dataset
@spec configure(keyword()) :: :ok

Applies global configuration options for the VegaLite kinos.

Options

  • :theme - the theme to be applied on the rendered VegaLite charts. Currently the only supported theme is :livebook. If set to nil, no theme is applied. Defaults to :livebook.
@spec new(VegaLite.t()) :: t()

Creates a new kino with the given VegaLite definition.

Link to this function

periodically(kino, interval_ms, acc, fun)

View Source
This function is deprecated. Use Kino.listen/3 instead.
@spec periodically(t(), pos_integer(), term(), (term() -> {:cont, term()} | :halt)) ::
  :ok

Registers a callback to run periodically in the kino process.

The callback is run every interval_ms milliseconds and receives the accumulated value. The callback should return either of:

  • {:cont, acc} - the continue with the new accumulated value

  • :halt - to no longer schedule callback evaluation

The callback is run for the first time immediately upon registration.

Link to this function

push(kino, data_point, opts \\ [])

View Source
@spec push(t(), map(), keyword()) :: :ok

Appends a single data point to the graphic dataset.

Options

  • :window - the maximum number of data points to keep. This option is useful when you are appending new data points to the plot over a long period of time

  • dataset - name of the targeted dataset from the VegaLite specification. Defaults to the default anonymous dataset

Link to this function

push_many(kino, data_points, opts \\ [])

View Source
@spec push_many(t(), [map()], keyword()) :: :ok

Appends a number of data points to the graphic dataset.

See push/3 for more details.

@spec render(VegaLite.t()) :: t()

Renders and returns a new kino with the given VegaLite definition.

It is equivalent to:

vega_lite |> Kino.VegaLite.new() |> Kino.render()
Link to this function

set_param(kino, name, value)

View Source
@spec set_param(t(), String.t(), term()) :: :ok

Updates a vega-lite parameter's value.

The parameter must be registered: VegaLite.param(vl, "param_name", opts).

To use the parameter in the chart, set a property to [expr: "param_name"].

Examples

chart =
  VegaLite.new(width: 400, height: 400)
  |> VegaLite.param("stroke_width", value: 3)
  |> VegaLite.mark(:line, stroke_width: [expr: "stroke_width"])
  |> VegaLite.encode_field(:x, "x", type: :quantitative)
  |> VegaLite.encode_field(:y, "y", type: :quantitative)
  |> Kino.VegaLite.new()
  |> Kino.render()

Kino.VegaLite.set_param(chart, "stroke_width", 10)