View Source VegaLite.Convert (VegaLite.Convert v1.0.1)

Various export methods for a VegaLite specification.

All of the exports are performed via a Rustler NIF that wraps the vl-convert-rs Rust library.

alias VegaLite, as: Vl

vl =
  Vl.new(width: 400, height: 400)
  |> Vl.data_from_values(iteration: 1..100, score: 1..100)
  |> Vl.mark(:line)
  |> Vl.encode_field(:x, "iteration", type: :quantitative)
  |> Vl.encode_field(:y, "score", type: :quantitative)

# Saves graphic to a file
VegaLite.Convert.save!(vl, "image.png")

# Returns graphic as a binary
VegaLite.Convert.to_png(vl)

Summary

Functions

Renders a VegaLite graphic in a GUI window widget.

Same as show/1, but blocks until the window widget is closed.

Renders a VegaLite graphic to a file in one of the supported formats.

Builds an HTML page that renders the given graphic.

Renders the given graphic as a JPEG image and returns its binary content.

Returns the underlying Vega-Lite specification as JSON.

Renders the given graphic as a PDF and returns its binary content.

Renders the given graphic as a PNG image and returns its binary content.

Renders the given graphic as an SVG image and returns its binary content.

Functions

@spec open_viewer(VegaLite.t()) :: :ok | :error

Renders a VegaLite graphic in a GUI window widget.

This requires the Erlang compilation to include the :wx module.

Link to this function

open_viewer_and_wait(vl)

View Source
@spec open_viewer_and_wait(VegaLite.t()) :: :ok | :error

Same as show/1, but blocks until the window widget is closed.

Link to this function

save!(vl, path, opts \\ [])

View Source
@spec save!(VegaLite.t(), Path.t(), keyword()) :: :ok

Renders a VegaLite graphic to a file in one of the supported formats.

Any additional options provided beyond :format are passed to the functions that export to the desired format.

Options

  • :format - the format to export the graphic as, must be either of: :json, :html, :png, :svg, :pdf, :jpeg, :jpg. By default the format is inferred from the file extension.

Builds an HTML page that renders the given graphic.

The HTML page loads necessary JavaScript dependencies from a CDN and then renders the graphic in a root element.

Options

  • :bundle - configures whether the VegaLite client side JS library is embedded in the document or if it is pulled down from the CDN. Defaults to true.

  • :renderer - determines how the VegaLite chart is rendered in the HTML document. Possible values are: :svg, :canvas, or :hybrid. Defaults to :svg.

@spec to_jpeg(
  VegaLite.t(),
  keyword()
) :: binary()

Renders the given graphic as a JPEG image and returns its binary content.

Options

  • :scale - the image scale factor. Defaults to 1.0.

  • :quality - the quality of the generated JPEG between 0 (worst) and 100 (best). Defaults to 90.

@spec to_json(vl :: VegaLite.t(), opts :: keyword()) :: String.t()

Returns the underlying Vega-Lite specification as JSON.

Options

  • :target - specifies whether JSON export is in the VegaLite format or Vega. Valid options are :vega_lite or :vega. Defaults to :vega_lite.
@spec to_pdf(VegaLite.t()) :: binary()

Renders the given graphic as a PDF and returns its binary content.

@spec to_png(
  VegaLite.t(),
  keyword()
) :: binary()

Renders the given graphic as a PNG image and returns its binary content.

Options

  • :scale - the image scale factor. Defaults to 1.0.

  • :ppi - the number of pixels per inch. Defaults to 72.0.

@spec to_svg(VegaLite.t()) :: binary()

Renders the given graphic as an SVG image and returns its binary content.