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
Link to this section 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.
Note that it may not work with some browsers (e.g. Safari on iOS).
@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 - seecolours/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 representingphx-click
event handler:phx_event_target
:nil
(default) or string representingphx-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}
@spec set_category_task_cols( t(), Contex.Dataset.column_name(), Contex.Dataset.column_name() ) :: t()
Specify the columns used for category and task
Sets the default scales for the plot based on its column mapping.
@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
@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.
Show or hide labels on the bar for each task