Skip to content

GGanttChart Component

The GGanttChart component is the main container component for creating Gantt charts in your Vue 3 application. It handles the overall layout, time management, and coordination between all child components.

Basic Usage

Here's a minimal example of using the GGanttChart component:

vue
<template>
  <g-gantt-chart
    :chart-start="chartStart"
    :chart-end="chartEnd"
    :precision="precision"
    :bar-start="barStart"
    :bar-end="barEnd"
  >
    <g-gantt-row
      v-for="row in rows"
      :key="row.label"
      :label="row.label"
      :bars="row.bars"
    />
  </g-gantt-chart>
</template>

Component API

Props

Prop NameTypeDefaultDescription
chartStartstring | DateRequiredThe start date of the chart's visible range
chartEndstring | DateRequiredThe end date of the chart's visible range
precision'hour' | 'day' | 'week' | 'month''day'Time unit precision for the chart
barStartstringRequiredProperty name for bar start dates
barEndstringRequiredProperty name for bar end dates
widthstring'100%'Chart width
hideTimeaxisbooleanfalseHide the time axis
colorSchemestring | ColorScheme'default'Color scheme for the chart
gridbooleanfalseShow background grid
pushOnOverlapbooleanfalsePush bars when they overlap
pushOnConnectbooleanfalsePush connected bars when moving
noOverlapbooleanfalsePrevent bars from overlapping
rowHeightnumber40Height of each row in pixels
fontstring'inherit'Font family for the chart
labelColumnTitlestring''Title for the label column
labelColumnWidthstring'150px'Width of the label column
sortablebooleantrueEnable row sorting functionality
multiColumnLabelLabelColumnConfig[][]Array of columns to display in the header
commandsbooleantrueShow chart control commands
enableMinutesbooleanfalseEnable minutes precision for hour view
enableConnectionsbooleantrueEnable connections between bars
defaultConnectionTypeConnectionType'straight'Default type for bar connections
defaultConnectionColorstring'#ff0000'Default color for connections
defaultConnectionPatternConnectionPattern'solid'Default pattern for connections
defaultConnectionAnimatedbooleanfalseEnable connection animations
defaultConnectionAnimationSpeedConnectionSpeed'normal'Speed of connection animations
maxRowsnumber0Maximum number of visible rows
initialSortSortState'none'Initial sorting column and direction
initialRowsChartRow[][]Initial rows data
currentTimebooleanfalseShow current time indicator
currentTimeLabelstring''Label for current time indicator
dateFormatstring | false'YYYY-MM-DD HH:mm'Format for dates
milestonesGanttMilestone[][]List of milestone
holidayHighlightstring``Country Cody of date-holidays
rowClass(row: ChartRow) => string``Method to add classes to data rows
rowLabelClass(row: ChartRow) => string``Method to add classes to label rows
dayOptionLabelDayOptionLabel[]['day']Customization for time unit day
localestring'en'Locale for dayjs
enableRowDragAndDropbooleanfalseEnable drag and drop of rows
markerConnectionMarkerConnectionforwardChoose the type of marker in connection
showLabelbooleantrueEnable the visualization of bar label
showProgressbooleantrueEnable the visualization of percentage bar progress
defaultProgressResizablebooleantrueEnable progress adjustment through dragging
enableConnectionCreationbooleanfalseEnable the possibility to draw connections
enableConnectionDeletebooleanfalseEnable the possibility to delete connections
utcbooleanfalseSet the current time position based on UTC
barLabelEditablebooleanfalseEnable the possibility to edit a bar label
exportEnabledbooleantrueEnable the export functionality
exportOptionsExportOptions{}Configure export options
showImporterbooleanfalseControls the visibility of the importer dialog
importerTitlestring'Import Data'Title for the importer dialog
importerDefaultFormatImportFormat'csv'Default import format
importerAllowedFormatsImportFormat[]['msproject', 'jira', 'csv', 'excel']List of allowed import formats
importerBarStartFieldstring'start'Default field name for bar start dates in imported data
importerBarEndFieldstring'end'Default field name for bar end dates in imported data

Events

Event NamePayloadDescription
click-bar{ bar: GanttBarObject, e: MouseEvent, datetime?: string | Date }Bar clicked
mousedown-bar{ bar: GanttBarObject, e: MouseEvent, datetime?: string | Date }Mouse down on bar
mouseup-bar{ bar: GanttBarObject, e: MouseEvent, datetime?: string | Date }Mouse up on bar
mouseenter-bar{ bar: GanttBarObject, e: MouseEvent }Mouse enter bar
mouseleave-bar{ bar: GanttBarObject, e: MouseEvent }Mouse leave bar
dblclick-bar{ bar: GanttBarObject, e: MouseEvent }Bar double clicked
dragstart-bar{ bar: GanttBarObject, e: MouseEvent }Bar drag started
drag-bar{ bar: GanttBarObject, e: MouseEvent }Bar being dragged
dragend-bar{ bar: GanttBarObject, e: MouseEvent, movedBars?: Map<GanttBarObject, { oldStart: string; oldEnd: string } }Bar drag ended
sort{ direction: SortState }Sort rows column and direction
contextmenu-bar{ bar: GanttBarObject; e: MouseEvent; datetime?: string | Date }Contextmenu click
group-expansion{ rowId: string | number }Open close group bar
row-drop{ sourceRow: ChartRow; targetRow?: ChartRow; newIndex: number; parentId string |number }Row drop after drag
progress-change{ bar: GanttBarObject, e: MouseEvent }Bar progress change
progress-drag-start{ bar: GanttBarObject, e: MouseEvent }Start progress change
progress-drag-end{ bar: GanttBarObject, e: MouseEvent }End progress change
connection-start{ sourceBar: GanttBarObject, connectionPoint: ConnectionPoint, e: MouseEvent }Starts the creation of a connection
connection-drag{ sourceBar: GanttBarObject, connectionPoint: ConnectionPoint, currentX: number, currentY: number, e: MouseEvent }During connection dragging
connection-complete{ sourceBar: GanttBarObject, targetBar: GanttBarObject, sourcePoint: ConnectionPoint, targetPoint: ConnectionPoint, e: MouseEvent }Completes the creation of a connection
connection-cancel{ sourceBar: GanttBarObject, connectionPoint: ConnectionPoint, e: MouseEvent }Cancels the creation of a connection
connection-delete{ sourceBar: GanttBarObject, targetBar: GanttBarObject, e: MouseEvent }Delete a connection
label-edit{ sourceBar: GanttBarObject, e: MouseEvent, oldValue: string, newValue: string }Edit bar label
timeaxisEventsTimeaxisEvent[][]
showEventsAxisbooleantrue
eventsAxisHeightnumber25
export-startformat: stringEmitted when the export process starts
export-successresult: ExportResultEmitted when the export process completes successfully
export-errorerror: stringEmitted when the export process encounters an error
import-dataresult: ImportResultEmitted when data is imported with the import result

Slots

Slot NamePropsDescription
defaultNoneMain content slot for GGanttRow components
label-column-titleNoneCustom label column header
label-column-{label}NoneCustom specific label form column
current-time-labelNoneCustom current time indicator label
bar-label{ bar: GanttBarObject }Custom bars label content
milestone{ bar: GanttBarObject }Custom milestones content
milestone-{milestoneId}{ bar: GanttBarObject }Custom specific milestone content
commandsCommandSlotPropsCustomization of the command section
timeaxis-event{ event: TimeaxisEvent }Custom template for timeline events displayed on the events axis

Command Slot Usage

The commands slot allows complete customization of the chart control section. It exposes a comprehensive set of functions and states through the CommandSlotProps interface:

typescript
interface CommandSlotProps {
  // Zoom Controls
  zoomIn: () => void                    // Increase zoom level
  zoomOut: () => void                   // Decrease zoom level
  zoomLevel: Ref<number>                // Current zoom level (1-10)
  
  // Row Navigation
  scrollRowUp: () => void               // Scroll one row up
  scrollRowDown: () => void             // Scroll one row down
  isAtTop: Ref<boolean>                 // Whether scroll is at top
  isAtBottom: Ref<boolean>              // Whether scroll is at bottom
  
  // Group Controls  
  expandAllGroups: () => void           // Expand all group rows
  collapseAllGroups: () => void         // Collapse all group rows
  
  // Timeline Navigation
  handleToStart: () => void             // Scroll to start of timeline
  handleBack: () => void                // Scroll backwards
  handleScroll: () => void              // Handle scroll position change
  handleForward: () => void             // Scroll forwards  
  handleToEnd: () => void               // Scroll to end of timeline
  
  // History Controls
  undo: () => void                      // Undo last action
  redo: () => void                      // Redo last undone action
  canUndo: ComputedRef<boolean>         // Whether undo is available
  canRedo: ComputedRef<boolean>         // Whether redo is available

  // Export Controls
  export: () => void                    // Trigger chart export
}

Example Usage

Here's an example of customizing the command section:

vue
<template>
  <g-gantt-chart>
    <template #commands="{
      zoomIn,
      zoomOut,
      scrollRowUp,
      scrollRowDown,
      expandAllGroups,
      collapseAllGroups,
      handleToStart,
      handleBack,
      handleForward,
      handleToEnd,
      undo,
      redo,
      canUndo,
      canRedo,
      isAtTop,
      isAtBottom,
      zoomLevel,
      export
    }">
      <div class="custom-commands">
        <!-- Zoom Controls -->
        <div class="zoom-controls">
          <button @click="zoomOut" :disabled="zoomLevel === 1">-</button>
          <span>Zoom: {{ zoomLevel }}x</span>
          <button @click="zoomIn" :disabled="zoomLevel === 10">+</button>
        </div>

        <!-- Navigation Controls -->
        <div class="navigation">
          <button @click="handleToStart">⟪</button>
          <button @click="handleBack">⟨</button>
          <button @click="handleForward">⟩</button>
          <button @click="handleToEnd">⟫</button>
        </div>

        <!-- History Controls -->
        <div class="history">
          <button @click="undo" :disabled="!canUndo">Undo</button>
          <button @click="redo" :disabled="!canRedo">Redo</button>
        </div>

        <!-- Export Controls -->
        <div class="export">
          <button @click="export">Export</button>
        </div>
      </div>
    </template>
  </g-gantt-chart>
</template>

The command slot provides complete flexibility in designing your own control interface while maintaining all the core functionality of the Gantt chart. You can choose which controls to expose, customize their appearance, and add additional features as needed.

Time Management

The GGanttChart component provides precise control over time representation:

vue
<template>
  <g-gantt-chart
    chart-start="2024-01-01"
    chart-end="2024-12-31"
    precision="day"
    :enable-minutes="true"
    date-format="YYYY-MM-DD HH:mm"
  />
</template>

Keyboard Navigation

The component supports keyboard navigation:

  • Arrow keys for moving through the timeline
  • +/- for zooming
  • Page Up/Down for faster navigation
  • Home/End for jumping to start/end
  • Ctrl+Z for undo history
  • Ctrl+Shift+Z for redo history

Released under the MIT License.