View Source Tucan.VegaLiteUtils (tucan v0.1.1)

Helper low level utilities for interacting with a VegaLite struct

Summary

Functions

Drops the given encoding channel or channels.

Similar to VegaLite.encode/3 but handles also plain maps.

Gets the configured encoding options for the given channel or nil if not set.

Returns true if the given single view plot has the provided channel encoded, false otherwise.

Puts and merges the given opts into the encoding options.

Puts the given opts under the given key in the provided VegaLite struct.

Functions

Link to this function

drop_encoding_channels(vl, channel)

View Source
@spec drop_encoding_channels(vl :: VegaLite.t(), channel :: atom() | [atom()]) ::
  VegaLite.t()

Drops the given encoding channel or channels.

An error is raised if vl is not a single view.

Link to this function

encode_field_raw(vl, channel, field, opts)

View Source
@spec encode_field_raw(
  vl :: VegaLite.t() | map(),
  channel :: atom() | binary(),
  field :: binary(),
  opts :: keyword()
) :: VegaLite.t() | map()

Similar to VegaLite.encode_field/4 but handles also plain maps.

Accepts as input either a VegaLite struct or a plain map that is assumed to be a VegaLite spec, and encodes the given field.

If the input is a VegaLite struct then a VegaLite is returned, otherwise a map is returned.

This is useful in case you want to modify an existing multi-layer/multi-plot spec where you cannot call directly VegaLite.encode_field/4

All provided options are converted to channel properties.

Link to this function

encode_raw(vl, channel, opts)

View Source
@spec encode_raw(
  vl :: VegaLite.t() | map(),
  channel :: atom() | binary(),
  opts :: keyword()
) ::
  VegaLite.t() | map()

Similar to VegaLite.encode/3 but handles also plain maps.

Accepts as input either a VegaLite struct or a plain map that is assumed to be a VegaLite spec, and encodes the given field.

If the input is a VegaLite struct then a VegaLite is returned, otherwise a map is returned.

This is useful in case you want to modify an existing multi-layer/multi-plot spec where you cannot call directly VegaLite.encode/3

All provided options are converted to channel properties.

Link to this function

encoding_options(vl, channel)

View Source
@spec encoding_options(vl :: VegaLite.t(), channel :: atom()) :: map() | nil

Gets the configured encoding options for the given channel or nil if not set.

Raises in case of a non single view.

Examples

iex> VegaLite.new()
...> |> VegaLite.encode_field(:x, "x", foo: "bar")
...> |> Tucan.VegaLiteUtils.encoding_options(:x)
%{"field" => "x", "foo" => "bar"}
Link to this function

has_encoding?(vl, channel)

View Source
@spec has_encoding?(vl :: VegaLite.t(), channel :: atom()) :: boolean()

Returns true if the given single view plot has the provided channel encoded, false otherwise.

Raises in case of a non single view.

Examples

iex> Tucan.VegaLiteUtils.has_encoding?(VegaLite.new(), :x)
false

iex> Tucan.VegaLiteUtils.has_encoding?(VegaLite.encode_field(VegaLite.new(), :x, "x"), :x)
true
Link to this function

put_encoding_options(vl, channel, opts)

View Source
@spec put_encoding_options(
  vl :: VegaLite.t() | map(),
  encoding :: atom(),
  opts :: keyword()
) ::
  VegaLite.t()

Puts and merges the given opts into the encoding options.

The input can either by a VegaLite struct or the spec map. The options will be deep merged with the existing ones.

The input vega lite representation must be a single view.

It will raise an ArgumentError if:

  • The input vl is not a single view.
  • The encoding does not exist in the specification an ArgumentError will be raised.
Link to this function

put_in_spec(vl, key, opts)

View Source
@spec put_in_spec(vl :: VegaLite.t(), key :: atom(), opts :: term()) :: VegaLite.t()

Puts the given opts under the given key in the provided VegaLite struct.

This is a destructive operation, any existing value for the provided key will be replaced by opts.