View Source Tucan.Grid (tucan v0.3.0)

Helper utilities for customizing a plot's grid.

Summary

Functions

Set a specific color to the grid for the given channel.

Sets the dash style of the grid.

Enables or disables the grid for the plot.

Enable or disable the grid of a specific channel

Sets the opacity of the grid lines.

Sets the width of the grid lines.

Functions

Link to this function

set_color(vl, channel, color)

View Source
@spec set_color(vl :: VegaLite.t(), channel :: atom(), color :: String.t()) ::
  VegaLite.t()

Set a specific color to the grid for the given channel.

This will raise if the channel is not encoded.

Examples

A scatter plot with the y-axis grid colored red and x-axis grid with a custom RGB color:

Tucan.scatter(:iris, "petal_width", "petal_length")
|> Tucan.Grid.set_color(:y, "red")
|> Tucan.Grid.set_color(:x, "#2A32F4")
Link to this function

set_dash_style(vl, channel, stroke, space)

View Source
@spec set_dash_style(
  vl :: VegaLite.t(),
  channel :: atom(),
  stroke :: pos_integer(),
  space :: pos_integer()
) :: VegaLite.t()

Sets the dash style of the grid.

stroke and space are alternative lengths for the dashed grid lines in pixels.

This will raise if the channel is not encoded.

Examples

A scatter plot with the different dashed styles across the two axes:

Tucan.scatter(:iris, "petal_width", "petal_length")
|> Tucan.Grid.set_dash_style(:x, 10, 2)
|> Tucan.Grid.set_dash_style(:y, 2, 10)
Link to this function

set_enabled(vl, enabled)

View Source
@spec set_enabled(vl :: VegaLite.t(), enabled :: boolean()) :: VegaLite.t()

Enables or disables the grid for the plot.

Notice that the grid is enabled by default.

See also set_enabled/3 for enabling/disabling specific axis' grid.

Examples

A scatter plot with the grid disabled:

Tucan.scatter(:iris, "petal_width", "petal_length")
|> Tucan.Grid.set_enabled(false)
Link to this function

set_enabled(vl, channel, enabled)

View Source
@spec set_enabled(vl :: VegaLite.t(), channel :: atom(), enabled :: boolean()) ::
  VegaLite.t()

Enable or disable the grid of a specific channel

This will raise if the channel is not encoded.

Examples

A scatter plot with the y-axis grid disabled:

Tucan.scatter(:iris, "petal_width", "petal_length")
|> Tucan.Grid.set_enabled(:y, false)
Link to this function

set_opacity(vl, channel, opacity)

View Source
@spec set_opacity(vl :: VegaLite.t(), channel :: atom(), opacity :: float()) ::
  VegaLite.t()

Sets the opacity of the grid lines.

If not set it defaults to 1.

This will raise if the channel is not encoded.

Examples

A scatter plot with the y-axis grid colored red and x-axis grid with a custom RGB color and opacity values set. Also the width is increased to make the opacity changes more clear.

Tucan.scatter(:iris, "petal_width", "petal_length")
|> Tucan.Grid.set_color(:x, "red")
|> Tucan.Grid.set_color(:y, "cyan")
|> Tucan.Grid.set_opacity(:x, 0.1)
|> Tucan.Grid.set_opacity(:y, 0.8)
|> Tucan.Grid.set_width(:x, 3)
|> Tucan.Grid.set_width(:y, 3)
Link to this function

set_width(vl, channel, width)

View Source
@spec set_width(vl :: VegaLite.t(), channel :: atom(), width :: pos_integer()) ::
  VegaLite.t()

Sets the width of the grid lines.

If not set it defaults to 1.

This will raise if the channel is not encoded.