Skip to content

fix(gantt): don't render task bars ending on an excluded day - #8047

Open
himanshu-2l wants to merge 2 commits into
mermaid-js:developfrom
himanshu-2l:fix/6421_gantt-render-end-time-weekend-offset
Open

himanshu-2l wants to merge 2 commits into
mermaid-js:developfrom
himanshu-2l:fix/6421_gantt-render-end-time-weekend-offset

Conversation

@himanshu-2l

@himanshu-2l himanshu-2l commented Aug 9, 2026 •

Copy link
Copy Markdown

Summary

Fixes a bug where a gantt task's rendered bar could visually end on an excluded day (e.g. a Saturday) instead of the next valid day, when excludes: weekends (or similar) pushes the end date out to skip excluded days.

Root cause

In fixTaskDates() (ganttDb.js), renderEndTime was only refreshed to match the padded endTime if the loop happened to run at least one more iteration after the last excluded day was resolved. When a run of excluded days extended through to the very end of the naive duration window, the loop exited before that catch-up iteration occurred, leaving renderEndTime stuck on a stale, excluded date - which ganttRenderer.js then uses directly for the bar's rendered width/endpoint (timeScale(d.renderEndTime || d.endTime) - timeScale(d.startTime)).

Example from the issue: Act2: 2025-07-09, 3d with excludes weekends correctly computed endTime = 2025-07-14 (Monday) for scheduling purposes, but renderEndTime was 2025-07-12 - a Saturday - so the bar was drawn two days short.

Fix

renderEndTime is now always set to the fully-adjusted endTime once the loop completes (or stays null for a zero/negative-span task, matching existing behavior for that edge case). This removes the one-iteration lag entirely.

Three existing test assertions in ganttDb.spec.ts asserted the old, buggy renderEndTime values (e.g. expecting a renderEndTime that lands on an excluded day) - these are corrected to the now-consistent values, which also match endTime in every case. A new regression test reproduces the exact scenario from the issue.

Test plan

Ran locally:

  • npx eslint --quiet packages/mermaid/src/diagrams/gantt/ganttDb.js packages/mermaid/src/diagrams/gantt/ganttDb.spec.ts → clean
  • npx prettier --check packages/mermaid/src/diagrams/gantt/ganttDb.js packages/mermaid/src/diagrams/gantt/ganttDb.spec.ts → All matched files use Prettier code style!
  • pnpm lint:jison → clean
  • npx tsx scripts/tsc-check.ts → tsc-check OK
  • npx vitest run packages/mermaid/src/diagrams/gantt → Test Files 2 passed (2), Tests 77 passed | 1 skipped (78)
  • npx vitest run packages/mermaid (full package suite) → Test Files 48 passed (48), Tests 1032 passed | 1 skipped (1033)
  • pnpm build → succeeds, all dist artifacts produced

Verified the new test actually catches the bug: reverted the ganttDb.js change only and reran the spec file - both the new regression test and one pre-existing test failed with the exact expected wrong dates (2025-07-12/Saturday and 2019-02-02/Saturday respectively), then restored the fix and confirmed all 77 tests pass.

Includes a changeset (patch, since this is a bug fix with no API changes).

Fixes #6421

Summary

  • Fixed Gantt task bars that ended on excluded days when excludes: weekends is enabled.
  • Updated fixTaskDates() to assign renderEndTime after all date adjustments.
  • Preserved null for zero- or negative-span tasks.
  • Updated assertions and added a regression test for weekend offsets.
  • Added a patch changeset.
  • Lint, type-check, test, and build commands pass.

fixTaskDates() tracked renderEndTime using the invalid flag from the previous loop iteration instead of the current one. If a run of excluded (e.g. weekend) days extended all the way through the end of a task's naive duration window, the loop would exit before renderEndTime ever caught up to the fully-adjusted endTime - leaving it stuck on an excluded day and causing the rendered task bar to visually end mid-weekend.

renderEndTime is now always set to the final, fully-adjusted endTime (or null if the task has zero/negative span, preserving existing behavior for that case).

Also corrects three existing test assertions in ganttDb.spec.ts that had encoded this buggy behavior as expected, and adds a regression test using the exact scenario from the issue.

Fixes mermaid-js#6421
@changeset-bot

changeset-bot Bot commented Aug 9, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: eb7d020

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

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

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

@netlify

netlify Bot commented Aug 9, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for mermaid-js ready!

Name Link
🔨 Latest commit eb7d020
🔍 Latest deploy log https://app.netlify.com/projects/mermaid-js/deploys/6a9082d300aa2400081a74f5
😎 Deploy Preview https://deploy-preview-8047--mermaid-js.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

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

@github-actions github-actions Bot added the Type: Bug / Error Something isn't working or is incorrect label Aug 9, 2026
@coderabbitai

coderabbitai Bot commented Aug 9, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

Next included review available in 57 minutes.

View limit details

Limit details: You’ve used all 10 included reviews currently available.

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 324f5486-beb9-49a2-ba93-3ba8831ec5a3

📥 Commits

Reviewing files that changed from the base of the PR and between b134d15 and eb7d020.

📒 Files selected for processing (3)
  • .changeset/gantt-render-end-time-weekend-offset.md
  • packages/mermaid/src/diagrams/gantt/ganttDb.js
  • packages/mermaid/src/diagrams/gantt/ganttDb.spec.ts
📝 Walkthrough

Walkthrough

The Gantt date adjustment now computes renderEndTime from the fully adjusted endTime. Weekend-exclusion tests validate dates that cross excluded days and document the patch.

Changes

Gantt end-time correction

Layer / File(s) Summary
Align rendered and adjusted end dates
packages/mermaid/src/diagrams/gantt/ganttDb.js
fixTaskDates now assigns renderEndTime after excluded-date adjustment completes.
Update weekend exclusion coverage
packages/mermaid/src/diagrams/gantt/ganttDb.spec.ts, .changeset/gantt-render-end-time-weekend-offset.md
Tests expect adjusted rendered end dates and cover a three-day task that crosses a weekend. The changeset records the patch.

Estimated code review effort: 2 (Simple) | ~10 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main Gantt rendering fix.
Description check ✅ Passed The description explains the bug, root cause, fix, tests, linked issue, and changeset; the missing template checklist is non-critical.
Linked Issues check ✅ Passed The implementation directly fixes issue #6421 by aligning renderEndTime with the adjusted endTime when weekends are excluded.
Out of Scope Changes check ✅ Passed All changes are related to the Gantt date-rendering fix, including implementation, regression tests, documentation, and the patch changeset.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@pkg-pr-new

pkg-pr-new Bot commented Aug 9, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

@mermaid-js/examples

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

mermaid

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

@mermaid-js/layout-elk

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

@mermaid-js/layout-tidy-tree

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

@mermaid-js/mermaid-zenuml

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

@mermaid-js/parser

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

@mermaid-js/tiny

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

commit: eb7d020

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
packages/mermaid/src/diagrams/gantt/ganttDb.spec.ts (1)

270-285: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Cover the zero-span branch.

fixTaskDates() explicitly preserves null when the adjusted startTime is after endTime. Add a zero-duration task case with exclusions and assert that renderEndTime remains null.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/mermaid/src/diagrams/gantt/ganttDb.spec.ts` around lines 270 - 285,
Extend the Gantt date tests near the existing excluded-weekend case to cover a
zero-duration task whose adjusted startTime exceeds endTime. Configure date
format and exclusions, add the zero-span task, then assert its renderEndTime
remains null, exercising the null-preservation branch in fixTaskDates().
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@packages/mermaid/src/diagrams/gantt/ganttDb.spec.ts`:
- Around line 270-285: Extend the Gantt date tests near the existing
excluded-weekend case to cover a zero-duration task whose adjusted startTime
exceeds endTime. Configure date format and exclusions, add the zero-span task,
then assert its renderEndTime remains null, exercising the null-preservation
branch in fixTaskDates().

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 2163c830-1502-4989-b6cf-3ae81e147609

📥 Commits

Reviewing files that changed from the base of the PR and between 3d521b1 and c8dd224.

📒 Files selected for processing (3)
  • .changeset/gantt-render-end-time-weekend-offset.md
  • packages/mermaid/src/diagrams/gantt/ganttDb.js
  • packages/mermaid/src/diagrams/gantt/ganttDb.spec.ts

@codecov

codecov Bot commented Aug 9, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 76.94%. Comparing base (b134d15) to head (eb7d020).

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #8047      +/-   ##
===========================================
- Coverage    79.52%   76.94%   -2.58%     
===========================================
  Files          607      607              
  Lines        83393    83397       +4     
  Branches     14491    16838    +2347     
===========================================
- Hits         66319    64173    -2146     
- Misses       16040    18335    +2295     
+ Partials      1034      889     -145     
Flag Coverage Δ
e2e 61.58% <100.00%> (-12.19%) ⬇️
unit 76.78% <100.00%> (+<0.01%) ⬆️

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 84.96% <100.00%> (+0.07%) ⬆️

... and 132 files 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

argos-ci Bot commented Aug 9, 2026 •

Copy link
Copy Markdown

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

Build Status Details Updated (UTC)
default (Inspect) ⚠️ Changes detected (Review) 4 changed Aug 27, 2026, 7:45 PM

This branch has not been deployed

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

Labels

Type: Bug / Error Something isn't working or is incorrect

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Weekends appear to be offset in gantt diagrams

2 participants