# `Visualize.Shape.Band`
[🔗](https://github.com/dcoai/Visualize/blob/v0.8.3/lib/visualize/shape/band.ex#L1)

Band generator: a state timeline of one rectangle per datum (spec/04 §11, D-26).

Each datum spans `x0` to `x1` at `y`, `height` tall, filled per datum. The coordinates
are pixel accessors, so the caller applies the x scale inside `x0`/`x1` exactly as for
`Visualize.Shape.Line` and `Visualize.Shape.Area`.

## Examples

    states = [
      %{from: ~U[2024-01-01 00:00:00Z], to: ~U[2024-01-01 06:00:00Z], state: :ok},
      %{from: ~U[2024-01-01 06:00:00Z], to: ~U[2024-01-01 09:00:00Z], state: :down}
    ]

    band =
      Visualize.Shape.Band.new()
      |> Visualize.Shape.Band.x0(fn d -> Visualize.Scale.apply(x_scale, d.from) end)
      |> Visualize.Shape.Band.x1(fn d -> Visualize.Scale.apply(x_scale, d.to) end)
      |> Visualize.Shape.Band.y(20)
      |> Visualize.Shape.Band.height(12)
      |> Visualize.Shape.Band.fill(fn d -> color(d.state) end)

    rects = Visualize.Shape.Band.generate(band, states)

# `accessor`

```elixir
@type accessor() :: (any() -&gt; number()) | atom() | number()
```

# `t`

```elixir
@type t() :: %Visualize.Shape.Band{
  fill: text_accessor() | nil,
  height: accessor(),
  x0: accessor() | nil,
  x1: accessor() | nil,
  y: accessor()
}
```

# `text_accessor`

```elixir
@type text_accessor() :: (any() -&gt; String.t() | nil) | atom() | String.t()
```

An accessor whose value is text: a 1-arity function, an atom field, or a string.

# `fill`

```elixir
@spec fill(t(), text_accessor() | nil) :: t()
```

Sets the fill accessor: a 1-arity function, an atom field, or a string constant

# `generate`

```elixir
@spec generate(t(), Visualize.Data.Table.source()) :: [Visualize.IR.Element.t()]
```

Returns one `:rect` element per datum, in data order.

The rectangle is normalized so `x` is the lesser edge and `width` is non-negative; the
style is `%{class: "band"}` plus `fill:` when the fill accessor yields a value.

# `generate_path`

```elixir
@spec generate_path(t(), Visualize.Data.Table.source()) :: Visualize.IR.Path.t()
```

Returns one `IR.Path` of closed rectangles, in data order, for a uniformly filled band.

# `height`

```elixir
@spec height(t(), accessor()) :: t()
```

Sets the height accessor, in pixels

# `new`

```elixir
@spec new() :: t()
```

Creates a band generator reading tuple elements 0 and 1 as `x0`/`x1`

# `x0`

```elixir
@spec x0(t(), accessor()) :: t()
```

Sets the start-edge accessor, in pixels

# `x1`

```elixir
@spec x1(t(), accessor()) :: t()
```

Sets the end-edge accessor, in pixels

# `y`

```elixir
@spec y(t(), accessor()) :: t()
```

Sets the top accessor, in pixels

---

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