Skip to content

Allow Gantt tasks to use "duration, until <taskId | endDate>" and automatically calculate the start date#7409

Open
Shahir-47 wants to merge 8 commits intomermaid-js:developfrom
Shahir-47:feature/7407_add-backward-scheduling-to-gantt
Open

Allow Gantt tasks to use "duration, until <taskId | endDate>" and automatically calculate the start date#7409
Shahir-47 wants to merge 8 commits intomermaid-js:developfrom
Shahir-47:feature/7407_add-backward-scheduling-to-gantt

Conversation

@Shahir-47
Copy link
Contributor

@Shahir-47 Shahir-47 commented Feb 19, 2026

📑 Summary

This PR adds support for Gantt tasks written as duration, until <taskId | endDate> so users do not need to provide a start date.

For this syntax, both values are used:

  • until <taskId | endDate> sets the task end point
  • duration sets the task length

Mermaid then calculates the start date automatically by subtracting the duration from the resolved end.

gantt
    banana :crit, b, 2017-09-1, 1d
    kiwi   :d, 10d, until b
1

In this example, kiwi gets start date 2017-08-22 automatically.

Resolves #7407

📏 Design Decisions

  • Added detection helpers for:
    • duration-like input (for example 7d)
    • until ... expressions
  • In task parsing, introduced a dedicated flow for duration + until ... so the start date is derived from the end date.
  • In task compilation:
    1. resolve end date first from until ... (task reference(s) or end date in dateFormat)
    2. subtract duration to derive start date
  • Added parser and gantt DB tests for:
    • duration, until <taskId>
    • duration, until <endDate>
    • with and without explicit task IDs
  • Updated Gantt syntax documentation to reflect until <taskId|endDate> behavior.

📋 Tasks

Make sure you

  • 📖 have read the contribution guidelines
  • 💻 have added necessary unit/e2e tests.
  • 📓 have added documentation. Make sure MERMAID_RELEASE_VERSION is used for all new features.
  • 🦋 If your PR makes a change that should be noted in one or more packages' changelogs, generate a changeset by running pnpm changeset and following the prompts. Changesets that add features should be minor and those that fix bugs should be patch. Please prefix changeset messages with feat:, fix:, or chore:.

@netlify
Copy link

netlify bot commented Feb 19, 2026

Deploy Preview for mermaid-js ready!

Name Link
🔨 Latest commit 323e2a7
🔍 Latest deploy log https://app.netlify.com/projects/mermaid-js/deploys/69b760815c34c20008af7089
😎 Deploy Preview https://deploy-preview-7409--mermaid-js.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@changeset-bot
Copy link

changeset-bot bot commented Feb 19, 2026

🦋 Changeset detected

Latest commit: 323e2a7

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
mermaid Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions github-actions bot added the Type: Enhancement New feature or request label Feb 19, 2026
@pkg-pr-new
Copy link

pkg-pr-new bot commented Feb 19, 2026

Open in StackBlitz

@mermaid-js/examples

npm i https://pkg.pr.new/@mermaid-js/examples@7409

mermaid

npm i https://pkg.pr.new/mermaid@7409

@mermaid-js/layout-elk

npm i https://pkg.pr.new/@mermaid-js/layout-elk@7409

@mermaid-js/layout-tidy-tree

npm i https://pkg.pr.new/@mermaid-js/layout-tidy-tree@7409

@mermaid-js/mermaid-zenuml

npm i https://pkg.pr.new/@mermaid-js/mermaid-zenuml@7409

@mermaid-js/parser

npm i https://pkg.pr.new/@mermaid-js/parser@7409

@mermaid-js/tiny

npm i https://pkg.pr.new/@mermaid-js/tiny@7409

commit: 323e2a7

@codecov
Copy link

codecov bot commented Feb 19, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 3.65%. Comparing base (277c496) to head (323e2a7).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           develop   #7409      +/-   ##
==========================================
+ Coverage     3.52%   3.65%   +0.12%     
==========================================
  Files          509     508       -1     
  Lines        49790   49845      +55     
  Branches       785     799      +14     
==========================================
+ Hits          1754    1820      +66     
+ Misses       48036   48025      -11     
Flag Coverage Δ
unit 3.65% <100.00%> (+0.12%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
packages/mermaid/src/diagrams/gantt/ganttDb.js 78.86% <100.00%> (+1.87%) ⬆️

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@argos-ci
Copy link

argos-ci bot commented Feb 19, 2026

The latest updates on your projects. Learn more about Argos notifications ↗︎

Build Status Details Updated (UTC)
default (Inspect) ⚠️ Changes detected (Review) 1 added Mar 16, 2026, 1:55 AM

@Shahir-47
Copy link
Contributor Author

@sidharthv96, this PR is ready to be merged. I’ve added duration, until <taskId | endDate> support with tests and docs. Please let me know if you spot any issues or want any changes before merging.

@Shahir-47 Shahir-47 changed the title Allow Gantt tasks to use "duration, until <taskId>" and automatically calculate the start date Allow Gantt tasks to use "duration, until <taskId | endDate>" and automatically calculate the start date Feb 19, 2026
Copy link
Collaborator

@knsv knsv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[sisyphus-bot]

PR #7409 — Backward scheduling for Gantt tasks

Thanks for this contribution, @Shahir-47! Backward scheduling from deadlines is a really practical feature — the use cases in the issue (release planning, exam prep) are spot-on, and the implementation is clean. Let's get this across the finish line.


What's working well

🎉 [praise] The deriveStartFromEnd approach is well-designed. Introducing a new startTime type that gets resolved during compileTasks() fits naturally into the existing two-phase parse→compile architecture. The helper functions looksLikeDuration and looksLikeUntilReference are clearly documented and keep the parseData() switch cases readable.

🎉 [praise] Good test coverage — three ganttDb unit tests and three parser tests covering the key variants (duration + until task ID, duration + until fixed date, with and without explicit task ID). Codecov confirms all modified lines are covered.


Things to address

🔴 [blocking]Missing changeset. The changeset-bot already flagged this. This is a user-facing feature, so it requires a changeset:

pnpm changeset
# Select `mermaid`, bump `minor`, message: "feat: add backward scheduling with `duration, until <taskId|endDate>` syntax for Gantt tasks"

🟡 [important]No E2E visual regression tests. Unit tests confirm the logic is correct, but there are no Cypress snapshot tests to verify the rendered Gantt chart looks right with backward-scheduled tasks. A visual regression test is the primary safety net for rendering features in this project. It would be great to add at least one imgSnapshotTest in cypress/integration/rendering/gantt.spec.js covering a diagram like:

gantt
    dateFormat YYYY-MM-DD
    section Backward Scheduling
    Release    :milestone, release, 2024-03-01, 0d
    Development :dev, 14d, until release
    Planning   :plan, 7d, until dev

This confirms the backward-computed start dates render correctly and provides regression coverage.

💡 [suggestion]Date vs task ID priority in until parsing (ganttDb.js:~375-380). The new getEndDate checks whether the until target is a valid date before looking up task IDs. This is sensible behavior, but it means a task ID that happens to match the dateFormat pattern would be silently interpreted as a date instead. This edge case is unlikely in practice and the current order is the right default — just worth a brief comment in the code noting the precedence so future maintainers understand the intent.


Summary

Severity Count
🔴 blocking 1
🟡 important 1
💡 suggestion 1
🎉 praise 2

Verdict: REQUEST_CHANGES — the changeset is required before merge, and E2E visual tests would strengthen confidence. The core implementation is solid — these are mostly process items. Looking forward to the updated PR!

@Shahir-47
Copy link
Contributor Author

@knsv Thanks for the review. I addressed all requested items:

  • Added the changeset (minor)
  • Added E2E visual tests in cypress/integration/rendering/gantt.spec.js
  • Added comments in getEndDate to explain date versus task ID precedence in until parsing

Everything is now ready for review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Type: Enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Extend until keyword to support duration for backward scheduling in Gantt charts

2 participants