GanttEx.Scale (GanttEx v0.1.0)

Copy Markdown View Source

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}}

Summary

Functions

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

Like new/1 but raises on invalid attributes.

Types

t()

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

Functions

new(scale)

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

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

new!(attrs)

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

Like new/1 but raises on invalid attributes.

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