# Gantt overview

> A project scheduling component with a task tree, a timeline and a critical-path engine, working calendars, MS Project XML exchange and a headless engine for servers.

Birch UI Gantt is a project scheduling component: a task tree on the left, a timeline on the right, and a critical-path scheduling engine underneath. Planners build the schedule by typing durations and predecessors or by dragging bars, and the engine moves every dependent task on its working calendar, the way desktop project tools do.

It is written in plain TypeScript, renders to the DOM and follows the shared Birch UI widget contract, so it works in any framework. The task list is built on the MIT Birch UI Grid core, so **no Grid Pro license is needed**.

> **Gantt: Paid feature. Fully functional without a key; a license removes the watermark. Pricing: https://docs.birchui.com/getting-started/pricing.md**
>
> Birch UI Gantt is a commercial product: $399 per developer, a one-time purchase with free updates forever, unlimited apps and unlimited end users. It is also part of the Project Suite bundle with the Scheduler and the Event Calendar. Without a license key every feature works and a small watermark is shown; on `localhost` the watermark is skipped while you develop.

**Live demo: Warehouse fit-out project** (runs on the HTML version of this page). Source of `demos/gantt-project.ts`. Imports from `./_shared` and `./_scheduler-data` are sample data and small UI helpers used only by the docs.

```ts
import { createGantt, type GanttDependency, type GanttTask } from '@birchui/gantt';
import { button, docsTheme, layout, onDocsThemeChange } from './_shared';

export const meta = { title: 'Warehouse fit-out project', height: 560 };

const tasks: GanttTask[] = [
  { id: 'plan', name: 'Planning', type: 'summary', expanded: true },
  { id: 'survey', parentId: 'plan', name: 'Site survey', start: '2027-01-04', duration: 3 },
  { id: 'design', parentId: 'plan', name: 'Racking layout design', duration: 5 },
  { id: 'permits', parentId: 'plan', name: 'Building permits', duration: 10 },
  { id: 'signoff', parentId: 'plan', name: 'Design sign-off', type: 'milestone', duration: 0 },
  { id: 'build', name: 'Fit-out', type: 'summary', expanded: true },
  { id: 'floor', parentId: 'build', name: 'Floor resurfacing', duration: 6 },
  { id: 'electrical', parentId: 'build', name: 'Electrical and lighting', duration: 8 },
  { id: 'racking', parentId: 'build', name: 'Install pallet racking', duration: 7 },
  { id: 'conveyor', parentId: 'build', name: 'Conveyor installation', duration: 9 },
  { id: 'golive', name: 'Go-live', type: 'summary', expanded: true },
  { id: 'wms', parentId: 'golive', name: 'Warehouse system configuration', duration: 6 },
  { id: 'training', parentId: 'golive', name: 'Staff training', duration: 4 },
  { id: 'handover', parentId: 'golive', name: 'Handover to operations', type: 'milestone', duration: 0 },
];

const links: [string, string, GanttDependency['type'], number?][] = [
  ['survey', 'design', 'FS'],
  ['design', 'permits', 'SS', 2],
  ['design', 'signoff', 'FS'],
  ['permits', 'signoff', 'FS'],
  ['signoff', 'floor', 'FS'],
  ['signoff', 'electrical', 'FS'],
  ['floor', 'racking', 'FS', 1],
  ['electrical', 'conveyor', 'SS', 3],
  ['racking', 'conveyor', 'FF'],
  ['signoff', 'wms', 'FS', 5],
  ['conveyor', 'training', 'FS'],
  ['wms', 'training', 'FS'],
  ['training', 'handover', 'FS'],
];

const dependencies: GanttDependency[] = links.map(([from, to, type, lag], index) => ({
  id: `d${index + 1}`,
  from,
  to,
  type,
  ...(lag ? { lag } : {}),
}));

export default function mount(el: HTMLElement): () => void {
  const { toolbar, body, status } = layout(el);
  const gantt = createGantt(body, {
    tasks,
    dependencies,
    projectStart: '2027-01-04',
    viewPreset: 'weekAndDay',
    showCriticalPath: true,
    calendars: [
      {
        id: 'uk',
        name: 'UK working days',
        workingDays: [1, 2, 3, 4, 5],
        exceptions: [{ start: '2027-01-01', isWorking: false, name: "New Year's Day" }],
      },
    ],
    calendarId: 'uk',
    theme: docsTheme(),
    height: '100%',
    ariaLabel: 'Warehouse fit-out schedule',
  });
  const undo = button('Undo', () => gantt.undo());
  const redo = button('Redo', () => gantt.redo());
  const syncHistory = () => {
    undo.disabled = !gantt.canUndo();
    redo.disabled = !gantt.canRedo();
  };
  const describeFinish = () => {
    const { end } = gantt.getProjectRange();
    return `Project finishes ${end.toDateString()}; ${gantt.getCriticalPath().taskIds.length} tasks are critical.`;
  };
  toolbar.append(
    button('Zoom in', () => gantt.zoomIn()),
    button('Zoom out', () => gantt.zoomOut()),
    undo,
    redo,
    'Drag a bar to move it, drag its end to change the duration, or drag from a bar edge to another bar to link them.',
  );
  const offs = [
    gantt.on('tasksScheduled', ({ changed, ms }) => {
      status.textContent = `Rescheduled ${changed.length} task(s) in ${ms.toFixed(1)} ms. ${describeFinish()}`;
      syncHistory();
    }),
    gantt.on('cycleDetected', () => {
      status.textContent = 'That link would create a cycle, so it was not added.';
    }),
    gantt.on('taskClick', ({ task }) => {
      const slack = gantt.getSlack(task.id);
      const critical = slack?.isCritical ? ', on the critical path' : '';
      status.textContent = `${task.name}: ${task.start.toDateString()} to ${task.end.toDateString()}${critical}.`;
    }),
  ];
  syncHistory();
  status.textContent = describeFinish();
  const stopTheme = onDocsThemeChange((theme) => gantt.update({ theme }));
  return () => {
    for (const off of offs) off();
    stopTheme();
    gantt.destroy();
  };
}
```

## What it does

- **Tasks** of type `task`, `milestone` and `summary`, nested with `parentId`, with progress, colors and baselines. See [Tasks](https://docs.birchui.com/gantt/tasks.md).
- **Dependencies** FS, SS, FF and SF with lag or lead in working or elapsed time. See [Dependencies](https://docs.birchui.com/gantt/dependencies.md).
- **Working calendars** with working days, hours, breaks, holidays and working exceptions, one for the project and one per task. See [Calendars](https://docs.birchui.com/gantt/calendars.md).
- **Scheduling**: forward and backward pass (CPM), the eight MS Project constraints, total and free slack, the critical path, manually scheduled tasks and loop detection. Edits reschedule only what they affect. See [Scheduling](https://docs.birchui.com/gantt/scheduling.md).
- **Editing** in the task grid (including predecessor text such as `3FS+2d, 5SS`) and on the timeline (move, resize, progress, drawing links), with indent and outdent, undo and redo. See [Task grid](https://docs.birchui.com/gantt/task-grid.md) and [Interactions](https://docs.birchui.com/gantt/interactions.md).
- **Exchange**: MS Project XML export and import, JSON, and a headless engine for Node and workers. See [MS Project XML](https://docs.birchui.com/gantt/ms-project.md) and [Headless engine](https://docs.birchui.com/gantt/headless.md).
- **Accessibility**: a WAI-ARIA treegrid task list, focusable bars with keyboard moving, resizing and linking, and live announcements. See [Keyboard and accessibility](https://docs.birchui.com/gantt/accessibility.md).

## Install

```bash
npm install @birchui/gantt
```

The package depends on `@birchui/core`, `@birchui/license` and `@birchui/scheduler` (for its time axis engine), which npm installs for you. Styles are injected the first time a Gantt is created; to ship the CSS yourself, pass `injectStyles: false` and import `@birchui/gantt/styles.css`.

## Create a Gantt

`createGantt(container, options)` renders into an element you own and returns the Gantt API. `tasks` is the only required option.

```ts title="warehouse-fit-out.ts"
import { createGantt } from '@birchui/gantt';

const gantt = createGantt(document.getElementById('fit-out')!, {
  projectStart: '2027-01-04',
  timeZone: 'Europe/London',
  height: 520,
  calendars: [
    {
      id: 'site',
      workingDays: [1, 2, 3, 4, 5],
      workingHours: [
        { from: '08:00', to: '12:00' },
        { from: '13:00', to: '17:00' },
      ],
      exceptions: [{ start: '2027-04-02', end: '2027-04-05', name: 'Easter' }],
    },
  ],
  calendarId: 'site',
  tasks: [
    { id: 'fitout', name: 'Distribution centre fit-out' },
    { id: 'survey', parentId: 'fitout', name: 'Floor survey and racking layout', duration: 3 },
    { id: 'permit', parentId: 'fitout', name: 'Racking permit approved', type: 'milestone' },
    { id: 'floor', parentId: 'fitout', name: 'Floor repairs and sealing', duration: 5 },
    { id: 'racking', parentId: 'fitout', name: 'Install pallet racking', duration: 10, percentDone: 20 },
    { id: 'lighting', parentId: 'fitout', name: 'LED high-bay lighting', duration: 6 },
    { id: 'wms', parentId: 'fitout', name: 'WMS configuration and scanners', duration: 8 },
    { id: 'handover', parentId: 'fitout', name: 'Handover to operations', type: 'milestone' },
  ],
  dependencies: [
    { id: 'd1', from: 'survey', to: 'permit', type: 'FS' },
    { id: 'd2', from: 'survey', to: 'floor', type: 'FS' },
    { id: 'd3', from: 'permit', to: 'racking', type: 'FS' },
    { id: 'd4', from: 'floor', to: 'racking', type: 'FS' },
    { id: 'd5', from: 'racking', to: 'lighting', type: 'SS', lag: 4, lagUnit: 'day' },
    { id: 'd6', from: 'racking', to: 'wms', type: 'FF', lag: 2 },
    { id: 'd7', from: 'lighting', to: 'handover', type: 'FS' },
    { id: 'd8', from: 'wms', to: 'handover', type: 'FS' },
  ],
  showCriticalPath: true,
});

gantt.on('taskChange', ({ task, source }) => saveTask(task.id, { start: task.start, end: task.end, source }));
gantt.on('dependencyCreate', ({ dependency }) => saveLink(dependency));
gantt.on('tasksScheduled', ({ changed, ms }) => console.info(`${changed.length} tasks rescheduled in ${ms} ms`));
```

The engine places every task: `survey` starts at the project start, its successors follow, and the `fitout` summary spans its subtasks. Durations are working days on the `site` calendar, so Easter and weekends are skipped.

> **Tip**
>
> Give the container a height, or pass `height`. The Gantt fills it and scrolls inside.

## The widget contract

`createGantt` returns a `GanttApi` with the four members every Birch UI component shares:

| Member | What it does |
| --- | --- |
| `element` | The Gantt's root element. |
| `update(partial)` | Applies only the options you pass, without recreating the Gantt. |
| `on(event, listener)` | Subscribes to one of the 13 events and returns an unsubscribe function. Payloads are always objects. |
| `destroy()` | Removes the DOM and releases every listener, timer and animation frame. |

```ts
gantt.update({ viewPreset: 'weekAndMonth', showBaselines: true });

const stop = gantt.on('cycleDetected', ({ cycles }) => {
  console.warn(`${cycles.length} dependency loops ignored`, cycles);
});

stop();
gantt.destroy();
```

The API adds task and link editing, scheduling queries (`getCriticalPath`, `getSlack`), undo and redo, zoom and navigation, and the file methods (`toJSON`, `fromJSON`, `toMSProjectXML`, `fromMSProjectXML`). See [API and events](https://docs.birchui.com/gantt/api.md).

## Activate your license

Set the key once for every Birch UI widget on the page, before the first Gantt is created, or pass it per instance:

```ts
import { setLicenseKey } from '@birchui/license';

setLicenseKey(import.meta.env.VITE_BIRCHUI_LICENSE);
```

```ts
createGantt(container, { ...options, licenseKey: 'LQ1.…' });
```

The Gantt checks the key for the `gantt` product and passes its root element as the watermark host. Verification happens in the browser with no network call. A missing or invalid key never disables anything: it adds a small watermark and logs one console warning, and on `localhost` the watermark is skipped. Changing `licenseKey` through `update()` re-checks it. The [headless engine](https://docs.birchui.com/gantt/headless.md) does not check a license.

| Tier | Price, one-time |
| --- | --- |
| Developer (one named developer) | $399 |
| Team (up to 5 developers) | $1,499 |
| Company (unlimited developers) | $3,999 |

The Gantt is also included in the Project Suite ($699 per developer, with the Scheduler and the Event Calendar) and in Birch UI Complete. Colleagues who only build or deploy the app need no seat. See [Pricing](https://docs.birchui.com/getting-started/pricing.md) and [Licensing and activation](https://docs.birchui.com/getting-started/licensing.md).

## Use it in your framework

The framework adapters do not ship a Gantt component, but each exports the generic factory its own components are built with. Pass it `ganttDefinition` (tag name `birchui-gantt`) to get a component that creates the Gantt on mount, sends changed props to `update()` and forwards all 13 events.

**JavaScript**

```ts
import { createGantt } from '@birchui/gantt';

const gantt = createGantt(document.getElementById('plan')!, { tasks, dependencies, height: 560 });
gantt.on('taskChange', ({ task }) => saveTask(task));
```

**React**

```tsx
import { createReactComponent } from '@birchui/react';
import { ganttDefinition } from '@birchui/gantt';

export const BirchGantt = createReactComponent(ganttDefinition);

export function ProjectPlan({ tasks, dependencies }: ProjectPlanProps) {
  return (
    <BirchGantt
      tasks={tasks}
      dependencies={dependencies}
      height={560}
      showCriticalPath
      onTaskChange={({ task }) => saveTask(task)}
    />
  );
}
```

**Vue**

```vue
<script setup lang="ts">
import { createVueComponent } from '@birchui/vue';
import { ganttDefinition, type GanttDependency, type GanttEvents, type GanttTask } from '@birchui/gantt';

const BirchGantt = createVueComponent(ganttDefinition);

defineProps<{ tasks: GanttTask[]; dependencies: GanttDependency[] }>();

function onTaskChange({ task }: GanttEvents['taskChange']) {
  saveTask(task);
}
</script>

<template>
  <BirchGantt :tasks="tasks" :dependencies="dependencies" :height="560" @task-change="onTaskChange" />
</template>
```

**Angular**

```ts
import { ChangeDetectionStrategy, Component, input, output } from '@angular/core';
import { injectBirchWidget, withOverrides, type WidgetOutputs } from '@birchui/angular';
import { ganttDefinition, type GanttApi, type GanttEvents, type GanttOptions } from '@birchui/gantt';

@Component({
  selector: 'app-gantt',
  standalone: true,
  changeDetection: ChangeDetectionStrategy.OnPush,
  template: '',
  styles: ':host { display: block; height: 560px; }',
})
export class GanttComponent implements WidgetOutputs<GanttEvents> {
  readonly options = input<Partial<GanttOptions>>({});
  readonly tasks = input.required<GanttOptions['tasks']>();
  readonly dependencies = input<GanttOptions['dependencies']>();

  readonly ready = output<GanttEvents['ready']>();
  readonly taskClick = output<GanttEvents['taskClick']>();
  readonly taskDoubleClick = output<GanttEvents['taskDoubleClick']>();
  readonly taskChange = output<GanttEvents['taskChange']>();
  readonly taskAdd = output<GanttEvents['taskAdd']>();
  readonly taskRemove = output<GanttEvents['taskRemove']>();
  readonly tasksScheduled = output<GanttEvents['tasksScheduled']>();
  readonly dependencyCreate = output<GanttEvents['dependencyCreate']>();
  readonly dependencyRemove = output<GanttEvents['dependencyRemove']>();
  readonly selectionChange = output<GanttEvents['selectionChange']>();
  readonly viewportScroll = output<GanttEvents['viewportScroll']>();
  readonly cycleDetected = output<GanttEvents['cycleDetected']>();
  readonly viewPresetChanged = output<GanttEvents['viewPresetChanged']>();

  private readonly widget = injectBirchWidget(ganttDefinition, this, () =>
    withOverrides<GanttOptions>(this.options(), {
      tasks: this.tasks(),
      dependencies: this.dependencies(),
    }),
  );

  get api(): GanttApi | undefined {
    return this.widget.instance;
  }
}
```

**Svelte**

```svelte
<script lang="ts">
  import { createSvelteAction } from '@birchui/svelte';
  import { ganttDefinition, type GanttApi, type GanttDependency, type GanttTask } from '@birchui/gantt';

  const birchGantt = createSvelteAction(ganttDefinition);

  let { tasks, dependencies }: { tasks: GanttTask[]; dependencies: GanttDependency[] } = $props();
  let api: GanttApi | null = $state.raw(null);
</script>

<div
  style="height: 560px"
  use:birchGantt={{
    tasks,
    dependencies,
    on: { taskChange: ({ task }) => saveTask(task) },
    onReady: (gantt) => (api = gantt),
  }}
></div>
```

**Solid**

```tsx
import { createSolidComponent } from '@birchui/solid';
import { ganttDefinition } from '@birchui/gantt';

export const BirchGantt = createSolidComponent(ganttDefinition);

export function ProjectPlan(props: ProjectPlanProps) {
  return (
    <BirchGantt tasks={props.tasks} dependencies={props.dependencies} height={560} onTaskChange={({ task }) => saveTask(task)} />
  );
}
```

**Web Component**

```html
<birchui-gantt id="plan" view-preset="weekAndMonth"></birchui-gantt>

<script type="module">
  import { createElementClass } from '@birchui/element';
  import { ganttDefinition } from '@birchui/gantt';

  customElements.define(
    'birchui-gantt',
    createElementClass(ganttDefinition, {
      optionKeys: ['tasks', 'dependencies', 'calendars'],
      attributes: { 'view-preset': 'string', height: 'number', 'time-zone': 'string' },
      requiredOptions: ['tasks'],
    }),
  );

  const plan = document.getElementById('plan');
  plan.dependencies = dependencies;
  plan.tasks = tasks;
  plan.addEventListener('task-change', ({ detail }) => saveTask(detail.task));
</script>
```

Notes per adapter:

- **React and Solid**: options are props, events are `on…` props (`onTaskChange`, `onTasksScheduled`), and `ref` gives you the `GanttApi`.
- **Vue**: pass options as attributes or an `options` object; events are kebab-case (`@task-change`, `@dependency-create`); the component exposes `api`.
- **Angular**: `injectBirchWidget` needs one output per event, so the wrapper declares all 13. Give the host a height.
- **Svelte**: `createSvelteAction` gives you an action whose parameter is the options plus `on` and `onReady`.
- **Web Component**: `createElementClass` turns the definition into a custom element. With `requiredOptions: ['tasks']` the Gantt is created once `tasks` is set, so set `dependencies` and `calendars` first. Events are kebab-case `CustomEvent`s with the payload in `detail`, and `element.api` is the `GanttApi`.

Passing new `tasks` or `dependencies` arrays through any adapter reloads the project and **clears the undo history**. Keep the arrays stable while the user edits and read changes from the events. See [Saving changes](https://docs.birchui.com/gantt/api.md#saving-changes).

## Next steps

- [Tasks](https://docs.birchui.com/gantt/tasks.md) and [Dependencies](https://docs.birchui.com/gantt/dependencies.md): the data model.
- [Scheduling](https://docs.birchui.com/gantt/scheduling.md): how dates are computed.
- [Limitations](https://docs.birchui.com/gantt/limitations.md): what this release does not do.
