GanttEx.Zoom (GanttEx v0.1.0)

Copy Markdown View Source

Zoom levels: named combinations of scales and column width.

Levels are ordered from the most detailed to the least detailed. The default levels are :hour, :day, :week, :month, :quarter and :year.

Custom levels can be given to GanttEx.Live.Gantt through its zoom_levels attribute:

[
  %{name: :sprint, column_width: 60, scales: [[unit: :month, format: :month_year], [unit: :week, step: 2]]},
  %{name: :month, column_width: 80, scales: [[unit: :year], [unit: :month]]}
]

Examples

iex> levels = GanttEx.Zoom.default_levels()
iex> Enum.map(levels, & &1.name)
[:hour, :day, :week, :month, :quarter, :year]
iex> GanttEx.Zoom.zoom_in(levels, :week)
:day
iex> GanttEx.Zoom.zoom_out(levels, :year)
:year

Summary

Types

A zoom level.

Functions

Returns true if name can be zoomed further in the given direction.

Returns the default zoom levels.

Finds a level by name, falling back to the first level.

Validates and normalizes a list of levels, building GanttEx.Scale structs.

Returns the name of the next, more detailed level.

Returns the name of the next, less detailed level.

Types

level()

@type level() :: %{
  name: atom(),
  column_width: pos_integer(),
  scales: [GanttEx.Scale.t(), ...]
}

A zoom level.

Functions

can_zoom?(levels, name, atom)

@spec can_zoom?([level()], atom(), :in | :out) :: boolean()

Returns true if name can be zoomed further in the given direction.

iex> GanttEx.Zoom.can_zoom?(GanttEx.Zoom.default_levels(), :hour, :in)
false

default_levels()

@spec default_levels() :: [level()]

Returns the default zoom levels.

find(levels, name)

@spec find([level()], atom()) :: level()

Finds a level by name, falling back to the first level.

iex> GanttEx.Zoom.find(GanttEx.Zoom.default_levels(), :month).column_width
80

normalize!(levels)

@spec normalize!([map()]) :: [level()]

Validates and normalizes a list of levels, building GanttEx.Scale structs.

iex> [level] = GanttEx.Zoom.normalize!([%{name: :custom, scales: [[unit: :day]]}])
iex> {level.column_width, hd(level.scales).unit}
{60, :day}

zoom_in(levels, name)

@spec zoom_in([level()], atom()) :: atom()

Returns the name of the next, more detailed level.

zoom_out(levels, name)

@spec zoom_out([level()], atom()) :: atom()

Returns the name of the next, less detailed level.