# `Tucan.Export`
[🔗](https://github.com/pnezis/tucan/blob/v0.6.0/lib/tucan/export.ex#L1)

Various export methods for `Tucan` plots.

This is a simple wrapper around the `VegaLite.Convert` API. It provides helper
utilities for exporting a tucan plot as `json`, `html`, `png`, `svg`, `jpeg`
or `pdf`.

> #### External dependencies {: .info}
>
> All of the export functions depend on the `vega_lite_convert` package.
> In order to use these functions you need to add the package in your
> dependencies:
>
> ```elixir
> def deps do
>   [
>     {:vega_lite_convert, "~> 1.0.0"}
>   ]
> end
> ```

# `save!`

```elixir
@spec save!(vl :: VegaLite.t(), path :: String.t(), opts :: keyword()) :: :ok
```

Saves a `Tucan` specification in one of the supported formats.

## Options

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

## Examples

```elixir
Tucan.scatter(:iris, "petal_width", "petal_length")
|> Tucan.Export.save!("iris.png")
```

See also `VegaLite.Convert.save!/3`

# `to_html`

```elixir
@spec to_html(vl :: VegaLite.t(), opts :: keyword()) :: String.t()
```

Builds an HTML page that renders the given graphic.

## 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`.

See also `VegaLite.Convert.to_html/2`

# `to_jpeg`

```elixir
@spec to_jpeg(vl :: VegaLite.t(), opts :: 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`.

See also `VegaLite.Convert.to_png/2`

# `to_json`

```elixir
@spec to_json(vl :: VegaLite.t()) :: String.t()
```

Returns the underlying Vega-Lite specification as JSON.

See also `VegaLite.Convert.to_json/1`

# `to_pdf`

```elixir
@spec to_pdf(vl :: VegaLite.t()) :: binary()
```

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

See also `VegaLite.Convert.to_pdf/1`

# `to_png`

```elixir
@spec to_png(vl :: VegaLite.t(), opts :: 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`

See also `VegaLite.Convert.to_png/2`

# `to_svg`

```elixir
@spec to_svg(vl :: VegaLite.t()) :: binary()
```

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

Relies on the `npm` packages mentioned above.

## Options

* `:local_npm_prefix` - a relative path pointing to a local npm project directory
  where the necessary npm packages are installed.

See also `VegaLite.Convert.to_svg/1`

---

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