criticalPath
Description
Optional. Enables critical path calculation and visualization in GanttThe criticalPath property enables built-in Critical Path Method (CPM) analysis in the Gantt chart. It identifies the sequence of tasks that defines the minimum project duration.
If there are multiple parallel paths with the same duration, the chart will highlight the first valid path.
Usage
criticalPath?: {
type: "strict" | "flexible";
};
Parameters
The property accepts an object specifying the calculation mode.
type- (required) - defines the algorithm used to compute the critical path:- "strict" - classical CPM mode that identifies tasks with exactly zero total slack. Uses backward traversal from project end, selecting only predecessors with zero slack. When multiple zero-slack predecessors exist, chooses the one with highest path count (longest path). Returns an empty array if no complete zero-slack path exists.
- "flexible" - flexible mode for near-critical path analysis. Uses forward traversal from project start, greedily selecting the successor with minimum adjusted slack at each decision point. Always returns a path, making it useful when no complete zero-slack path exists or when analyzing near-critical tasks.
The following Gantt props influence strict critical-path calculations:
Example
<script>
import { getData } from "../data";
import { Gantt } from "@svar/svelte-gantt";
const data = getData("critical");
let api = $state();
let mode = "flexible";
let projectStart = new Date(2024, 3, 2);
let projectEnd = new Date(2024, 3, 12);
</script>
<Gantt
tasks={data.tasks}
links={data.links}
scales={data.scales}
criticalPath={{ type: mode }}
{projectStart}
{projectEnd}
/>