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

Helper utilities for customizing a plot's grid.

# `set_color`

```elixir
@spec set_color(vl :: VegaLite.t(), color :: String.t()) :: VegaLite.t()
```

Set a specific color to the grid for both `x` and `y` axes. 

This will raise if any of the two x, y channels are not encoded.

See also `set_color/3`

## Examples

```tucan
Tucan.scatter(:iris, "petal_width", "petal_length")
|> Tucan.Grid.set_color("red")
```

# `set_color`

```elixir
@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
Tucan.scatter(:iris, "petal_width", "petal_length")
|> Tucan.Grid.set_color(:y, "red")
|> Tucan.Grid.set_color(:x, "#2A32F4")
```

# `set_dash_style`

```elixir
@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
Tucan.scatter(:iris, "petal_width", "petal_length")
|> Tucan.Grid.set_dash_style(:x, 10, 2)
|> Tucan.Grid.set_dash_style(:y, 2, 10)
```

# `set_enabled`

```elixir
@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
Tucan.scatter(:iris, "petal_width", "petal_length")
|> Tucan.Grid.set_enabled(false)
```

# `set_enabled`

```elixir
@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
Tucan.scatter(:iris, "petal_width", "petal_length")
|> Tucan.Grid.set_enabled(:y, false)
```

# `set_opacity`

```elixir
@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
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)
```

# `set_width`

```elixir
@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.

---

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