An interactive Gantt chart LiveComponent.
<.live_component
module={GanttEx.Live.Gantt}
id="project-gantt"
tasks={@tasks}
links={@links}
locale="es"
/>The chart keeps its own UI state (selection, expanded branches, zoom,
dialogs) and applies every user change immediately. Changes are reported
to the parent LiveView as {GanttEx, %GanttEx.Event{}} messages so they
can be persisted (see GanttEx.Event and the "Persistence" guide).
Whenever the parent renders the component with different tasks or
links, the chart reloads them while preserving its UI state.
Features
- task grid with tree, configurable/sortable/resizable columns and inline editing
- tasks, projects (dates rolled up from children) and milestones
- drag & drop to move, resize and change progress; drag to reorder rows
- finish-to-start, start-to-start, finish-to-finish and start-to-finish dependencies with lag, drawn by dragging between bar edges
- zoomable time scale (hours to years) and customizable zoom levels
- lightbox editor, quick info popup and tooltips
- keyboard navigation, fullscreen, print, export (JSON, CSV, iCal, MS Project)
- drag on the timeline to create tasks, or to pan the chart
- 8 bundled languages, light/dark themes and WAI-ARIA roles
Attributes
Data:
:id(required) - DOM id of the chart.:tasks- list of tasks (maps, keyword lists or structs, seeGanttEx.Task).:links- list of links (seeGanttEx.Link).:duration_unit- unit of durations and lags. Defaults to:day.:work_time- durations count only working time. Defaults tofalse.:calendar- the global working calendar: aGanttEx.Calendaror its options (work_days,hours,holidays,working_dates).:calendars- more calendars, referenced by the:calendar_idof tasks.
Behaviour:
:readonly- disables every edition. Defaults tofalse.:lightbox- opens the task editor on double click / Enter / "+". Defaults totrue.:lightbox_sections- lightbox fields to show, any of:text,:type,:parent,:timeand:progress. Defaults to all of them.:inline_edit- click a cell of the selected row to edit it. Defaults totrue.:quick_info- show a popup when a bar is clicked. Defaults totrue.:tooltips- show tooltips when hovering bars. Defaults totrue.:reorder- drag rows in the grid to reorder or re-parent tasks. Defaults totrue.:links_editable- draw and edit dependencies. Defaults totrue.:auto_scheduling- after every change, move tasks so that dependencies and constraints hold (seeGanttEx.Scheduler). The lightbox gets a constraint section. Defaults tofalse.:auto_scheduling_strict- also move tasks earlier, to their earliest possible date. Defaults tofalse.:critical_path- highlight the critical path (seeGanttEx.CriticalPath). The toolbar has a toggle for it. Defaults tofalse.:show_slack- draw the free slack of each task after its bar. Defaults tofalse.:resources- the resources tasks are assigned to (seeGanttEx.Resource). Tasks list their assignments in:resources; the lightbox gets a:resourcessection and grids can show a:resourcescolumn.:auto_types- tasks with children become projects and projects without children become tasks. Defaults tofalse.:group_by- group the tasks under virtual rows: a task field (:type), a:metakey (:owner),:resources(a task appears under each of its resources) or a function returning the group(s) of a task.:group_label- a function returning the label of a group.:resource_panel- show the load of every resource below the chart (seeGanttEx.ResourceLoad). Defaults tofalse.:baselines- draw the baseline (:planned_start/:planned_end) below each bar. Deadlines (:deadline) are always drawn, and tasks that end after them are marked as overdue. Defaults tofalse.:undo- undo and redo with the toolbar or Ctrl/Cmd+Z and Ctrl/Cmd+Shift+Z (Ctrl+Y). Undone changes are reported as events too. Defaults totrue.:drag_create- drag on an empty area of the timeline to create a task (otherwise dragging pans the chart; hold Shift for the other behaviour). Defaults tofalse.:smart_rendering- render only the rows around the visible area.:auto(the default) enables it above 120 visible rows;trueorfalseforce it.:filter- a 1-arity function returningtruefor the tasks to show (their ancestors are shown too).:notify- the pid that receives the events. Defaults to the parent LiveView.
Time scale:
:zoom- initial zoom level name. Defaults to:day.:zoom_levels- custom levels (seeGanttEx.Zoom).:start_date,:end_date- fixed visible range. By default the range fits the tasks.:week_start- first day of the week (1= Monday,7= Sunday). Defaults to1.:weekend- ISO days highlighted as non-working. Defaults to[6, 7].:today- the current date, used by the "Today" button. Defaults to now.:markers- vertical lines marking dates (seeGanttEx.Marker).:today_marker- add a marker for today. Defaults tofalse.
Appearance:
:locale- one ofGanttEx.I18n.locales/0. Defaults to"en".:theme-"auto"(followsprefers-color-schemeor adata-themeattribute on an ancestor),"light"or"dark". Defaults to"auto".:height- CSS height of the scrollable area. Defaults to"640px".:row_height,:bar_height,:scale_height- sizes in pixels.:grid_width- width of the grid in pixels. Defaults to the sum of the column widths.:show_gridhides it.:toolbar- show the built-in toolbar. Defaults totrue.:export_formats- formats offered by the toolbar::json,:csv,:ical,:ms_project,:svgand:png(seeGanttEx.Export).:export_filename- base name of exported files. Defaults to"gantt".:task_class- a function returning extra CSS classes for a task bar.:class- extra classes for the root element.
Slots
:column- grid columns. Attributes:field(required::text,:start_date,:end_date,:duration,:progress,:type,:addor any key of the task:meta),label,width,align,tree(shows the tree in this column),editor(:text,:date,:number,:progress,:typeornil) andsortable. The inner block receives the task:<:column field={:owner} label="Owner" width={120} :let={task}> {task.meta[:owner]} </:column>:task_text- content of the bars, receives the task.:tooltip- content of the tooltips, receives the task.:lightbox_fields- extra lightbox fields, receives the form. Values are stored in the task:meta.:toolbar_actions- extra content for the toolbar.
Controlling the chart from the parent
Use zoom/2, expand_all/1, collapse_all/1, select/2 and reload/1,
which wrap Phoenix.LiveView.send_update/2.
JavaScript
Drag & drop needs the bundled hook. Add it to your LiveSocket:
import {hooks as ganttHooks} from "phoenix-colocated/gantt_ex"
const liveSocket = new LiveSocket("/live", Socket, {
hooks: {...colocatedHooks, ...ganttHooks},
})and the styles to your app.css:
@import "phoenix-colocated/gantt_ex/colocated.css";
Summary
Functions
Collapses every branch of the chart.
Expands every branch of the chart.
Forces the chart to reload its data from the last tasks and links it
received, discarding local changes. Useful when the parent rejected a change
and its data did not change.
Selects the task with task_id (or clears the selection with nil).
Changes the zoom level of the chart with the given id.
Functions
@spec collapse_all(String.t()) :: :ok
Collapses every branch of the chart.
@spec expand_all(String.t()) :: :ok
Expands every branch of the chart.
@spec reload(String.t()) :: :ok
Forces the chart to reload its data from the last tasks and links it
received, discarding local changes. Useful when the parent rejected a change
and its data did not change.
@spec select(String.t(), GanttEx.Task.id() | nil) :: :ok
Selects the task with task_id (or clears the selection with nil).
Changes the zoom level of the chart with the given id.