View Source Contex.GanttChart (ContEx v0.5.0)

Generates a Gantt Chart.

Bars are drawn for each task covering the start and end time for each task. In addition, tasks can be grouped into categories which have a different coloured background - this is useful for showing projects that are in major phases.

The time interval columns must be of a date time type (either NaiveDateTime or DateTime)

Labels can optionally be drawn for each task (use show_task_labels/2) and a description for each task, including the time interval is generated and added as a '<title>' element attached to the bar. Most browsers provide a tooltip functionality to display the title when the mouse hovers over the containing element.

By default, the first four columns of the supplied dataset are used for the category, task, start time and end time.

Link to this section Summary

Functions

Optionally specify a LiveView event handler. This attaches a phx-click attribute to each bar element. You can specify the event_target for LiveComponents - a phx-target attribute will also be attached.

Creates a new Gantt chart from a dataset and sets defaults.

Specify the columns used for category and task

Sets the default scales for the plot based on its column mapping.

If id_col is set it is used as the value sent by the phx_event_handler. Otherwise, the category and task is used

Specify the columns used for start and end time of each task.

Show or hide labels on the bar for each task

Link to this section Types

@type t() :: %Contex.GanttChart{
  category_scale: term(),
  dataset: term(),
  mapping: term(),
  options: term(),
  task_scale: term(),
  time_scale: term()
}

Link to this section Functions

Link to this function

event_handler(plot, event_handler, event_target \\ nil)

View Source
This function is deprecated. Set in new/2 options.

Optionally specify a LiveView event handler. This attaches a phx-click attribute to each bar element. You can specify the event_target for LiveComponents - a phx-target attribute will also be attached.

Note that it may not work with some browsers (e.g. Safari on iOS).

Link to this function

new(dataset, options \\ [])

View Source
@spec new(
  Contex.Dataset.t(),
  keyword()
) :: t()

Creates a new Gantt chart from a dataset and sets defaults.

Options may be passed to control the settings for the barchart. Options available are:

  • :padding : integer (default 2) - Specifies the padding between the task bars. Defaults to 2. Specified relative to the plot size.
  • :show_task_labels : true (default) or false - display labels for each task
  • :colour_palette : :default (default) or colour palette - see colours/2

Overrides the default colours.

Colours can either be a named palette defined in Contex.CategoryColourScale or a list of strings representing hex code of the colour as per CSS colour hex codes, but without the #. For example:

  gantt = GanttChart.new(
      dataset,
      mapping: %{category_col: :category, task_col: :task_name, start_col: :start_time, finish_col: :end_time, id_col: :task_id},
      colour_palette: ["fbb4ae", "b3cde3", "ccebc5"]
    )

The colours will be applied to the data series in the same order as the columns are specified in set_val_col_names/2

  • :phx_event_handler : nil (default) or string representing phx-click event handler
  • :phx_event_target : nil (default) or string representing phx-target for handler

Optionally specify a LiveView event handler. This attaches a phx-click attribute to each bar element. You can specify the event_target for LiveComponents - a phx-target attribute will also be attached.

Note that it may not work with some browsers (e.g. Safari on iOS).

  • :mapping : Maps attributes required to generate the barchart to columns in the dataset.

If the data in the dataset is stored as a map, the :mapping option is required. If the dataset is not stored as a map, :mapping may be left out, in which case the columns will be assigned in order to category, task, start time, finish time, task id.

If a mapping is explicit (recommended) the value must be a map of the plot's :category_col, :task_col, :start_col, :finish_col, :id_col to keys in the map,

For example:

mapping: %{category_col: :category, task_col: :task_name, start_col: :start_time, finish_col: :end_time, id_col: :task_id}

Link to this function

set_category_task_cols(plot, cat_col_name, task_col_name)

View Source
This function is deprecated. Use `:mapping` option in `new/2`.
@spec set_category_task_cols(
  t(),
  Contex.Dataset.column_name(),
  Contex.Dataset.column_name()
) :: t()

Specify the columns used for category and task

Link to this function

set_default_scales(plot)

View Source
This function is deprecated. Default scales are now silently applied.
@spec set_default_scales(t()) :: t()

Sets the default scales for the plot based on its column mapping.

Link to this function

set_id_col(plot, id_col_name)

View Source
This function is deprecated. Use `:mapping` option in `new/2`.
@spec set_id_col(t(), Contex.Dataset.column_name()) :: t()

If id_col is set it is used as the value sent by the phx_event_handler. Otherwise, the category and task is used

Link to this function

set_task_interval_cols(plot, arg)

View Source
This function is deprecated. Use `:mapping` option in `new/2`.
@spec set_task_interval_cols(
  t(),
  {Contex.Dataset.column_name(), Contex.Dataset.column_name()}
) :: t()

Specify the columns used for start and end time of each task.

Link to this function

show_task_labels(plot, show_task_labels)

View Source
This function is deprecated. Set in new/2 options.
@spec show_task_labels(t(), boolean()) :: t()

Show or hide labels on the bar for each task