Skip to content

Fix horizontal bar chart tooltip clipping off the right edge#132

Open
robsfletch wants to merge 1 commit into
mainfrom
fix/horizontal-bar-tooltip-overflow
Open

Fix horizontal bar chart tooltip clipping off the right edge#132
robsfletch wants to merge 1 commit into
mainfrom
fix/horizontal-bar-tooltip-overflow

Conversation

@robsfletch

Copy link
Copy Markdown

Summary

  • BarChart's horizontal-orientation tooltip (handleMouseMove and handleKeyDown) pinned the tooltip past the plot's right edge with transform: none and never measured its width — unlike the vertical branch, which already flips the tooltip left when it would overflow.
  • Long tooltip content (long series/value labels) got clipped by the consuming app's container.
  • Fix mirrors the existing vertical-branch pattern: measure tooltip.offsetWidth, and flip the tooltip to grow leftward from the plot's right edge when it would overflow the container width.

Test plan

  • Added BarHorizontalNarrow story (narrow container + long series label) and a new Playwright CT test asserting the tooltip's right edge stays within the container bounds on hover.
  • Verified the new test fails against the pre-fix code and passes against the fix.
  • npx vitest run: 410/411 pass (1 pre-existing unrelated failure: Icon registry > exports exactly 215 icons, icon count drift unrelated to this change).
  • npx playwright test -c playwright-ct.config.ts src/components/Chart/Chart.test.tsx: 69/69 pass.
  • npx tsc --noEmit: clean.

Context

Reported downstream in lightsparkdev/analytics#2511 (Agent Analytics dashboard, horizontal bar plot). Consuming repo will bump @lightsparkdev/origin once this is released.

The horizontal-orientation branch in BarChart's handleMouseMove/handleKeyDown
pinned the tooltip past the plot's right edge with transform: none and never
measured its width, unlike the vertical branch which already flips left when
it would overflow. Long tooltip content (e.g. long series/value labels) got
clipped by the consuming app's container overflow.

Mirrors the vertical branch: measure tooltip width, and flip it to grow
leftward from the plot's right edge when it would overflow the container.
@greptile-apps

greptile-apps Bot commented Jul 14, 2026

Copy link
Copy Markdown

Greptile Summary

This PR keeps horizontal bar-chart tooltips from overflowing the right edge. The main changes are:

  • Measures tooltip width during pointer and keyboard interaction.
  • Flips overflowing tooltips to the left of the plot edge.
  • Adds a narrow-chart fixture and right-edge containment test.

Confidence Score: 4/5

Oversized horizontal tooltips can still be clipped on the left in narrow containers.

  • The new right-edge fit check handles the reported overflow.
  • The left fallback has no guard for a tooltip wider than the available chart space.
  • Pointer and keyboard paths share the same boundary bug.

src/components/Chart/BarChart.tsx

Important Files Changed

Filename Overview
src/components/Chart/BarChart.tsx Adds width-aware horizontal tooltip placement, but the fallback can overflow the container's left edge.
src/components/Chart/Chart.test-stories.tsx Adds a narrow horizontal bar-chart fixture with a long tooltip label.
src/components/Chart/Chart.test.tsx Adds right-edge containment coverage, but does not check left-edge containment.
Prompt To Fix All With AI
Fix the following 1 code review issue. Work through them one at a time, proposing concise fixes.

---

### Issue 1 of 1
src/components/Chart/BarChart.tsx:270-272
**Left Flip Can Still Clip**

When the tooltip is wider than `padLeft + plotWidth - TOOLTIP_GAP`, translating it left by its full width produces a negative left edge. In a narrow chart with a long unbroken label, an overflow-clipping container will crop the tooltip on the left instead of the right, so this fallback must constrain both edges.

Reviews (1): Last reviewed commit: "Fix horizontal bar chart tooltip clippin..." | Re-trigger Greptile

Comment on lines +270 to +272
} else {
tip.style.left = `${padLeft + plotWidth - TOOLTIP_GAP}px`;
tip.style.transform = 'translateX(-100%)';

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Left Flip Can Still Clip

When the tooltip is wider than padLeft + plotWidth - TOOLTIP_GAP, translating it left by its full width produces a negative left edge. In a narrow chart with a long unbroken label, an overflow-clipping container will crop the tooltip on the left instead of the right, so this fallback must constrain both edges.

Context Used: Chart component color and usage conventions (source)

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/components/Chart/BarChart.tsx
Line: 270-272

Comment:
**Left Flip Can Still Clip**

When the tooltip is wider than `padLeft + plotWidth - TOOLTIP_GAP`, translating it left by its full width produces a negative left edge. In a narrow chart with a long unbroken label, an overflow-clipping container will crop the tooltip on the left instead of the right, so this fallback must constrain both edges.

**Context Used:** Chart component color and usage conventions ([source](https://app.greptile.com/lightspark/github/lightsparkdev/origin/-/custom-context?memory=2070e049-47f8-4317-b8d3-707fd915a94b))

How can I resolve this? If you propose a fix, please make it concise.

@robsfletch
robsfletch requested a review from coreymartin July 14, 2026 00:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant