Skip to content
GitHub
Examples / Core

Critical path

Highlight the chain of tasks and links currently pinning the chart's end date.

Kickoff → Design → Build → Launch has zero float, so it stays highlighted through --am-gantt-critical-bg and --am-gantt-critical-dependency-color. Kickoff → Research → Prototype shares Kickoff with that chain but finishes well before Launch, so it has slack and is never flagged critical — dragging it would not move the chart's end date. Try dragging Build later: Launch cascades with it, and the highlight is recomputed on that commit.

Live example

Jump to source
Loading chart…

Source code

The exact files used by the live example above.

demo.tsx
"use client";

import { useCallback, useState } from "react";
import { Gantt, type GanttTask, type TaskDependency } from "@art-tools/react-gantt";
import { criticalPathDependencies, criticalPathTasks } from "@/lib/demo-tasks";

/**
 * `criticalPath` is computed from the *actual* committed schedule, not a
 * hypothetical earliest-possible one (ADR-023) — so Research/Prototype, which
 * finishes nine days before Launch, never lights up even though it shares
 * Kickoff with the critical chain. Drag Design or Build and watch the
 * highlight follow whichever chain is currently pinning Launch's date; it
 * recomputes on commit, same cadence as the dependency cascade itself.
 */
export function CriticalPathDemo() {
  const [tasks, setTasks] = useState<GanttTask[]>(criticalPathTasks);
  const [dependencies, setDependencies] = useState<TaskDependency[]>(criticalPathDependencies);

  const handleCreate = useCallback((dep: TaskDependency) => {
    setDependencies((prev) => [...prev, dep]);
  }, []);

  const handleDelete = useCallback((dep: TaskDependency) => {
    setDependencies((prev) => prev.filter((d) => !(d.from === dep.from && d.to === dep.to)));
  }, []);

  return (
    <Gantt
      tasks={tasks}
      dependencies={dependencies}
      criticalPath
      onTasksChange={setTasks}
      onDependencyCreate={handleCreate}
      onDependencyDelete={handleDelete}
      height={340}
    />
  );
}