Sub topic 3
Draw the Chart in Mermaid and Python
This chapter assumes you can compute earliest start and finish dates with a forward pass, and that you have Python 3 with matplotlib installed.
Draw the chart in Mermaid and Python
Mermaid is a text format that renders a Gantt chart from a short definition. Each task line gives a name, optional status tags, an ID, a start, and a duration. The crit tag marks critical tasks, and milestone marks a zero-duration event.
To draw the same schedule in Python, run this script. It computes the forward pass and plots one bar per task.
import matplotlib.pyplot as plt
tasks = {
"Wireframes": (5, []),
"Mockups": (7, ["Wireframes"]),
"Backend": (12, ["Wireframes"]),
"Frontend": (10, ["Mockups"]),
"Integration": (4, ["Frontend", "Backend"]),
}
start, finish = {}, {}
for name, (duration, preds) in tasks.items():
start[name] = max((finish[p] for p in preds), default=0)
finish[name] = start[name] + duration
fig, ax = plt.subplots(figsize=(8, 3))
for row, name in enumerate(tasks):
ax.barh(row, finish[name] - start[name], left=start[name], height=0.5)
ax.set_yticks(range(len(tasks)))
ax.set_yticklabels(tasks)
ax.invert_yaxis()
ax.set_xlabel("Day")
plt.tight_layout()
plt.show()Use slack to plan flexibility
A backward pass sets each task's latest finish without delaying the project. Slack is the latest finish minus the earliest finish. Backend finishes on day 17, but Integration cannot start before day 22, so Backend has 5 days of slack. Mockups and Frontend have zero slack and form the critical path.
Track progress against a baseline
Save the planned dates as a baseline before work starts. Then compare each task's actual or forecast finish against it.
| Task | Baseline finish (day) | Forecast finish (day) | Variance (days) |
|---|---|---|---|
| Mockups | 12 | 14 | +2 |
Variance is the forecast finish minus the baseline finish. Do not overwrite the baseline when you update the plan.
Avoid common mistakes
- Counting weekends and holidays as working days when your calendar excludes them.
- Leaving out dependencies, which makes the chart show tasks that can start too early.
- Treating a milestone as a task with duration.
- Replacing the baseline after every update, which hides slippage.
Exercise
Backend slips 6 days, so it finishes on day 23 instead of day 17. What day does the project finish?
Show answer
Integration starts on day 23 and finishes on day 27. Backend had 5 days of slack, so the 6-day slip delays the project by 1 day.