Skip to content

fix(widgets): preserve fractional start positions in GanttChart-#2436#2926

Open
Rakshak05 wants to merge 4 commits into
Karanjot786:mainfrom
Rakshak05:issue-#2436
Open

fix(widgets): preserve fractional start positions in GanttChart-#2436#2926
Rakshak05 wants to merge 4 commits into
Karanjot786:mainfrom
Rakshak05:issue-#2436

Conversation

@Rakshak05

@Rakshak05 Rakshak05 commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Description

This PR fixes an issue where the GanttChart widget ignored fractional task start positions because it rounded the starting column down using Math.floor. The rendering logic was rewritten to calculate both start positions and durations in sub-cells (8 per column) and render appropriate fractional block symbols (, , and standard left-aligned bar symbols) depending on the alignment.

Related Issue

Closes #2436

Which package(s)?

@termuijs/widgets

Type of Change

  • 🐛 Bug fix (type:bug)
  • ✨ Feature (type:feature)
  • 📝 Docs (type:docs)
  • 🧪 Tests (type:testing)
  • ♻️ Refactor (type:refactor)
  • 🎨 Design / UX (type:design)
  • ♿ Accessibility (type:accessibility)
  • ⚡ Performance (type:performance)
  • 🔧 DevOps / CI (type:devops)
  • 🔒 Security (type:security)

Checklist

  • ⭐ You starred the repo. The needs-star check blocks your merge otherwise.
  • Tests pass locally: bun vitest run
  • Build passes: bun run build
  • Typecheck passes: bun run typecheck
  • You read CONTRIBUTING.md.
  • Your PR title follows type: short description.
  • Widget state mutators call markDirty() (if your change affects rendering).
  • No new any types without an inline comment explaining why.
  • No unrelated refactors bundled into this PR.

GSSoC 2026 Participation

  • I'm a GSSoC 2026 contributor.
  • My GSSoC profile: https://gssoc.girlscript.org/profile/e3386d85-b6ea-4c6e-b3c9-1c559eea6b33

Screenshots / Recordings (UI changes)

Screenshot 2026-07-23 110227

Notes for the Reviewer

  • Fractional start offsets are mapped to sub-cells (Math.round(cols * 8)).
  • When a task begins inside a cell (i.e. cellStart > 0), it renders the corresponding right-aligned block character \u2595 () for width <= 2, \u2590 () for width <= 5, and full block \u2588 () for width >= 6.
  • ASCII fallbacks have also been fully updated and tested to render correctly using = and - characters when caps.unicode is false.

Summary by CodeRabbit

  • Bug Fixes
    • Improved Gantt chart bar positioning for tasks with fractional start times.
    • Bars now render with finer sub-cell precision, preserving fine-grained timeline alignment.
    • When Unicode is unavailable, the Gantt chart now consistently uses ASCII fallback glyphs.
  • Tests
    • Added coverage to verify fractional alignment and correct glyph selection under both Unicode-enabled and ASCII-only modes.

@Rakshak05
Rakshak05 requested a review from Karanjot786 as a code owner July 23, 2026 05:34
@github-actions github-actions Bot added type:bug +10 pts. Bug fix. area:widgets @termuijs/widgets type:testing +10 pts. Tests. labels Jul 23, 2026
@coderabbitai

coderabbitai Bot commented Jul 23, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@Rakshak05, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 23 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: ff7bbb90-b395-4f85-9621-a29c73b852bb

📥 Commits

Reviewing files that changed from the base of the PR and between 8a4a8c8 and 2acd9ec.

📒 Files selected for processing (1)
  • packages/core/src/terminal/env-caps.ts
📝 Walkthrough

Walkthrough

GanttChart bar rendering now accounts for fractional task start positions using eight subcells per cell. Terminal capability overrides support Unicode and ASCII rendering tests, which cover fractional alignment in both modes.

Changes

GanttChart sub-cell alignment

Layer / File(s) Summary
Terminal capability overrides
packages/core/src/terminal/env-caps.ts
caps.unicode and caps.motion now use environment-based accessors with mutable overrides for tests.
Sub-cell bar rendering and coverage
packages/widgets/src/data/GanttChart.ts, packages/widgets/src/data/GanttChart.test.ts
Bar drawing computes per-column overlap from fractional positions and tests the resulting Unicode and ASCII glyphs.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related PRs

Suggested labels: gssoc:approved, quality:clean, level:intermediate

Suggested reviewers: karanjot786, ashrion

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly matches the main fix: preserving fractional GanttChart start positions in widgets.
Description check ✅ Passed The PR description includes the required sections, issue link, package, change type, checklist, screenshots, and notes.
Linked Issues check ✅ Passed The change addresses issue #2436 by preserving fractional task start offsets and adding coverage for the new rendering behavior.
Out of Scope Changes check ✅ Passed The additional env-caps accessor change supports the GanttChart unicode test behavior and is not unrelated to the fix.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 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.

Inline comments:
In `@packages/widgets/src/data/GanttChart.test.ts`:
- Line 105: Replace the plain data-property test seam for caps.unicode with a
supported getter accessor in the env-caps implementation, or provide an
equivalent accessor-based seam. Update all repeated vi.spyOn(caps, "unicode",
"get") mocks in Histogram, StackedBarChart, GanttChart, and Tooltip tests to
target that seam.

In `@packages/widgets/src/data/GanttChart.ts`:
- Around line 163-180: The partial-bar glyph selection in GanttChart must
incorporate both cellStart and width instead of choosing solely by width,
preserving distinct alignments including right-aligned 7/8 segments; update the
logic around the cellEnd === 8 and middle-block branches accordingly. In
packages/widgets/src/data/GanttChart.test.ts lines 94-100, replace the
full-block-only expectation with cases demonstrating that same-width bars at
different fractional starts render different glyphs.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 115e49c3-70fa-4177-85f3-d99db419cddb

📥 Commits

Reviewing files that changed from the base of the PR and between 452dcec and 5c399f7.

📒 Files selected for processing (2)
  • packages/widgets/src/data/GanttChart.test.ts
  • packages/widgets/src/data/GanttChart.ts

Comment thread packages/widgets/src/data/GanttChart.test.ts
Comment thread packages/widgets/src/data/GanttChart.ts Outdated
@github-actions github-actions Bot added the area:core @termuijs/core label Jul 23, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
packages/core/src/terminal/env-caps.ts (1)

3-5: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Make capability overrides resettable.

After either setter is called, the corresponding mock permanently overrides environment detection for the module lifetime. This can leak test state and prevents restoring NO_UNICODE/TERM/NO_MOTION/CI-derived behavior. Accept undefined as a reset value or add an explicit reset helper, with tests for both paths.

Also applies to: 29-39

🤖 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/core/src/terminal/env-caps.ts` around lines 3 - 5, The capability
override state in mockUnicode and mockMotion is not resettable, causing test
state to persist across module use. Update the corresponding setter functions to
accept undefined and clear their override when provided, or add an explicit
reset helper, while preserving environment-based detection when no override is
set; add tests covering setting overrides and restoring both Unicode and motion
detection.
🤖 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.

Inline comments:
In `@packages/core/src/terminal/env-caps.ts`:
- Around line 29-30: Update the exported caps object around the unicode setter
and related runtime setters so its public TypeScript type keeps direct overrides
writable. Remove the readonly inference caused by as const, or expose the object
through an explicit writable Caps type, while preserving the existing setter
behavior for caps.unicode, caps.motion, and other mutable members.

---

Nitpick comments:
In `@packages/core/src/terminal/env-caps.ts`:
- Around line 3-5: The capability override state in mockUnicode and mockMotion
is not resettable, causing test state to persist across module use. Update the
corresponding setter functions to accept undefined and clear their override when
provided, or add an explicit reset helper, while preserving environment-based
detection when no override is set; add tests covering setting overrides and
restoring both Unicode and motion detection.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: ef3d6cfd-b926-455b-b128-a35d6552cd4e

📥 Commits

Reviewing files that changed from the base of the PR and between 5c399f7 and 8a4a8c8.

📒 Files selected for processing (3)
  • packages/core/src/terminal/env-caps.ts
  • packages/widgets/src/data/GanttChart.test.ts
  • packages/widgets/src/data/GanttChart.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • packages/widgets/src/data/GanttChart.test.ts
  • packages/widgets/src/data/GanttChart.ts

Comment thread packages/core/src/terminal/env-caps.ts
@Karanjot786

Copy link
Copy Markdown
Owner

Thanks — the GanttChart fractional-start fix is correct (sub-cell overlap math verified, both unicode and ASCII paths, two focused tests pass). One blocker: the PR also bundles an unrelated refactor of packages/core/src/terminal/env-caps.ts (converting caps.unicode/caps.motion to get/set accessors backed by module-level mock state, dropping as const). That is a shared, dependency-free core file used by every package, and the change is unnecessary — vi.spyOn(caps, "unicode", "get") already works against the original plain-value object (verified). Per AGENTS.md "No unrelated refactors bundled." Please drop the env-caps.ts hunk and keep only GanttChart.ts + its test; then this is good to merge.

Checklist: [ ] env-caps.ts changes reverted [ ] only GanttChart.ts + test remain

@Karanjot786 Karanjot786 added the quality:needs-work Needs changes before merge. label Jul 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:core @termuijs/core area:widgets @termuijs/widgets quality:needs-work Needs changes before merge. type:bug +10 pts. Bug fix. type:testing +10 pts. Tests.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug] GanttChart ignores fractional task start positions, causing incorrect bar alignment

3 participants