SVAR React Gantt

repository·main·Indexed 41 days ago

https://github.com/svar-widgets/react-gantt

A high-performance, customizable React Gantt chart component for building project timelines. Version 2.7.3 supports large datasets via virtualization, hierarchical task structures, and configurable time scales. It offers a Core open-source edition for essential visualization and a PRO edition featuring critical path analysis, resource management, auto-scheduling, and exports to PDF, Excel, and MS Project.

Tokens
2.8K
Snippets
7
Records
16
Agent score
52%

What's inside SVAR React Gantt

  1. Compare Core and PRO editions of SVAR React Gantt

    main

    SVAR React Gantt is available in two editions:

    Core Edition (Open Source)

    Includes essential features for task visualization and interaction:

    • Task and dependency visualization
    • Interactive timeline with drag-and-drop
    • Hierarchical view of subtasks
    • Configurable time scales (hours, days, weeks, sprints, or stages)
    • Virtualization for large datasets (handles thousands of tasks)
    • Zooming, hotkeys, and localization

    PRO Edition

    Includes advanced automation and project management logic:

    • Calendars: Work-time calendars (non-linear), individual task/resource calendars.
    • Project Logic: Critical path, Slack (float) visualization, Baselines, and Auto-scheduling (forward mode/Finish-to-Start).
    • Resource Management: Resource planning and workload visualization.
    • Task Management: Task grouping, Summary task automation, Rollups, Split tasks, and WBS codes.
    • Advanced UI/UX: Vertical markers, Undo/redo.
    • Export/Import: PNG, PDF, Excel, and MS Project formats.
  2. PRO Edition features

    main

    The PRO edition of @svar-ui/react-gantt includes advanced project management capabilities:

    • Resource Management: Visualizing/assigning resources, resource load charts, grouping tasks by resources, and individual resource calendars.
    • Advanced Task Management: WBS codes, individual calendars for tasks, grouping tasks by any field, and calculating/visualizing slack.
    • Automation & Scheduling: Improved auto scheduling with summary tasks, auto calculation of progress for summary tasks, and auto conversion of parent tasks to summary tasks.
    • Exporting: Server-side export to PNG, PDF, XLSX, and MS Project; client-side import/export from MS Project.
    • Advanced Features: Rollups, Baselines, Critical path calculation, and Undo/Redo functionality.
  3. Install and use SVAR React Gantt

    main

    To use the SVAR React Gantt chart in your project, install the @svar-ui/react-gantt package. You must import both the Gantt component and the required CSS file (@svar-ui/react-gantt/all.css) to ensure the component renders correctly.

    Pass an array of task objects to the tasks prop of the <Gantt /> component. Each task object can include properties such as id, text, start, end, duration, progress, type (e.g., 'task' or 'summary'), and parent for hierarchical structures.

    import { Gantt } from '@svar-ui/react-gantt';
    import '@svar-ui/react-gantt/all.css';
    
    export default function MyComponent() {
      const tasks = [
        {
          id: 20,
          text: 'New Task',
          start: new Date(2024, 5, 11),
          end: new Date(2024, 6, 12),
          duration: 1,
          progress: 2,
          type: 'task',
          lazy: false,
        },
        {
          id: 47,
          text: '[1] Master project',
          start: new Date(2024, 5, 12),
          end: new Date(2024, 7, 12),
          duration: 8,
          progress: 0,
          parent: 0,
          type: 'summary',
        },
      ];
    
      return <Gantt tasks={tasks} />;
    }
  4. Understand Gantt event naming (GanttActions)

    main

    The Gantt component uses a specific naming convention for event props based on the methods available in the TMethodsConfig.

    To map a method name to an event prop, the library:

    1. Removes hyphens from the method name.
    2. Prefixes the result with on.

    Example Mapping:

    • Method: task-added $\rightarrow$ Prop: onTaskAdded
    • Method: resource-updated $\rightarrow$ Prop: onResourceUpdated

    This allows you to listen to any store action by providing a corresponding on<ActionName> prop.

  5. Apply visual themes and wrappers

    main

    The library provides several wrapper components to apply global styles, themes, or behaviors to the Gantt chart and its sub-components:

    • Material: Wraps the application to apply Material Design styles. Supports fonts prop.
    • Willow: A specific theme wrapper. Supports fonts prop.
    • WillowDark: A dark version of the Willow theme.
    • Fullscreen: Wraps children to enable fullscreen capabilities. Supports a hotkey prop.
    • Tooltip: Used to provide contextual information when hovering over elements.
  6. Access default configuration and utility functions from @svar-ui/gantt-store

    main

    The package re-exports several configuration defaults and utility functions from @svar-ui/gantt-store to help set up the Gantt chart's behavior and appearance. These include:

    • Defaults: defaultEditorItems, defaultToolbarButtons, defaultMenuOptions, defaultColumns, and defaultTaskTypes.
    • Getters: getDefaultColumns, getResourceColumns, getEditorItems, getToolbarButtons, getEditorButtons, and getMenuOptions.
    • Registration: registerScaleUnit for adding custom scale units.
    import {
      defaultEditorItems,
      defaultToolbarButtons,
      defaultMenuOptions,
      defaultColumns,
      defaultTaskTypes,
      getDefaultColumns,
      getResourceColumns,
      getEditorItems,
      getToolbarButtons,
      getEditorButtons,
      getMenuOptions,
      registerScaleUnit
    } from '@svar-ui/react-gantt';
  7. Use the Gantt API with sub-components

    main

    Several specialized components are provided to interact with the Gantt chart's state via the IApi instance. Most of these components accept an api prop to connect to the chart's internal store.

    • HeaderMenu: A menu component for header-level actions.
    • ContextMenu: A menu component for right-click context actions.
    • Toolbar: A component for displaying action buttons.
    • Editor: A component for managing data editing.
    • Tooltip: A wrapper for custom tooltips. The content prop accepts a function receiving api and data (which can be a task, link, rollup, or resource).
    • ResourceLoad: A component to display resource loading/allocation. It supports mode ('grid' | 'chart') and a template function for custom string rendering.
    // Example: Using a Toolbar with the Gantt API
    const ganttRef = useRef<IApi>(null);
    
    <Gantt ref={ganttRef} />
    <Toolbar api={ganttRef.current} />
  8. Import the Gantt component and core UI elements

    main

    The @svar-ui/react-gantt package exports the main Gantt component along with several supporting UI components for customization and interaction, including Toolbar, ContextMenu, Editor, HeaderMenu, ResourceLoad, and Tooltip. It also provides several built-in themes: Material, Willow, and WillowDark.

    import {
      Gantt,
      Toolbar,
      ContextMenu,
      Editor,
      HeaderMenu,
      ResourceLoad,
      Tooltip,
      Material,
      Willow,
      WillowDark
    } from '@svar-ui/react-gantt';
  9. Configure the Gantt component

    main

    The Gantt component is the primary entry point for the library. It accepts several configuration props to define columns, custom task rendering, and visual styles. It also exposes an init method to initialize the API and supports event listeners for store actions via the GanttActions pattern (e.g., if a method is named task-added, the event prop is onTaskAdded).

    Key props:

    • columns: An array of IColumnConfig objects to define the chart's columns.
    • taskTemplate: A functional component for custom task rendering. It receives data (the ITask), api (the IApi instance), and an onaction callback.
    • readonly: Boolean to enable/disable chart interactions.
    • cellBorders: Set to 'column' or 'full' to control border visibility.
    • highlightTime: A function (date: Date, unit: 'day' | 'hour') => string to apply custom styling to time segments.
    • init: A function (api: IApi) => void used to capture the API instance.

    The component also supports a ref to access the IApi directly.

    import { Gantt } from '@svar-ui/react-gantt';
    
    // Example usage with custom task template and columns
    <Gantt
      columns={[
        { header: 'Task Name', cell: 'name' },
        { header: 'Start Date', cell: 'start' }
      ]}
      taskTemplate={({ data, api, onaction }) => (
        <div onClick={() => onaction({ action: 'click', data: { id: data.id } })}>
          {data.name}
        </div>
      )}
      onTaskAdded={(task) => console.log('New task:', task)}
    />
  10. Define column configurations with IColumnConfig

    main

    The IColumnConfig interface extends IGanttColumn (from @svar-ui/gantt-store) to allow integration with @svar-ui/react-grid. It allows you to specify how cells, headers, and editors behave for a specific column.

    Properties:

    • cell: Configuration for the cell rendering (compatible with ITableColumn['cell']).
    • header: Configuration for the column header (compatible with ITableColumn['header']).
    • editor: Configuration for the cell editor (compatible with ITableColumn['editor']).