# `GanttEx.Scale`
[🔗](https://github.com/rocket4ce/gantt_ex/blob/v0.1.0/lib/gantt_ex/scale.ex#L1)

One row of the time scale header.

A scale has a `:unit` (see `GanttEx.Dates.units/0`), a `:step` (a scale of
`unit: :hour, step: 6` shows one cell every 6 hours) and a `:format`, which
can be a named pattern, a strftime pattern or a function (see
`GanttEx.I18n`). An optional `:class` function returns extra CSS classes for
a cell given its start date.

    iex> GanttEx.Scale.new(unit: :week, format: "W%V")
    {:ok, %GanttEx.Scale{unit: :week, step: 1, format: "W%V", class: nil}}

    iex> GanttEx.Scale.new(%{"unit" => "month"})
    {:ok, %GanttEx.Scale{unit: :month, step: 1, format: :month, class: nil}}

    iex> GanttEx.Scale.new(unit: :decade)
    {:error, {:invalid, :unit}}

# `t`

```elixir
@type t() :: %GanttEx.Scale{
  class: (NaiveDateTime.t() -&gt; String.t() | nil) | nil,
  format: GanttEx.I18n.pattern(),
  step: pos_integer(),
  unit: GanttEx.Dates.unit()
}
```

# `new`

```elixir
@spec new(t() | keyword() | map()) :: {:ok, t()} | {:error, {:invalid, atom()}}
```

Builds a scale from a keyword list, a map or a `GanttEx.Scale`.

# `new!`

```elixir
@spec new!(t() | keyword() | map()) :: t()
```

Like `new/1` but raises on invalid attributes.

    iex> GanttEx.Scale.new!(unit: :day).format
    :day

---

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