Skip to content

fix(ErrorBar): clip error bars with their graphical item - #8054

Merged
PavelVanecek merged 1 commit into
recharts:mainfrom
b84330808:fix/clip-error-bars-with-allow-data-overflow
Oct 26, 2026
Merged

PavelVanecek merged 1 commit into
recharts:mainfrom
b84330808:fix/clip-error-bars-with-allow-data-overflow

Conversation

@b84330808

@b84330808 b84330808 commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Description

ErrorBar renders in its own ZIndexLayer, which is portalled out of the graphical item's layer, so it does not inherit the clip path that Bar and Scatter put on their layers when an axis has allowDataOverflow. Line only clips its curve and dots, so its error bars were not clipped either.

This adds a clipPath to ErrorBarContext. Line, Bar and Scatter pass their own clip path, or undefined when they are not clipped, and ErrorBar sets it on the recharts-errorBars layer. That is the same clip path 2.x applied to the error bars since #3300.

Related Issue

Fixes #8053

Motivation and Context

With allowDataOverflow and a domain smaller than the error range, the whiskers are drawn over the axes and the chart margin while the item itself is clipped. This was reported in #2978, fixed in 2.4.0, and came back in 3.x.

How Has This Been Tested?

  • Added tests to test/cartesian/ErrorBar.spec.tsx that render Line, Bar and Scatter with <YAxis domain={[0, 100]} allowDataOverflow /> and check that every error bar is inside an element clipped by the item's clip path, plus one that checks nothing is clipped without allowDataOverflow. The three clipping tests fail on main and pass with this change.
  • npx vitest run --project unit:lib, npm run test-omnidoc, npm run check-types-lib, npm run check-types-test, and eslint and prettier on the changed files.
  • Rendered Line, Bar and Scatter charts with YAxis domain={[0, 100]} allowDataOverflow and compared them in Chrome before and after.

Screenshots (if appropriate):

Before: the whiskers of the points above 100 and below 0 are drawn above the plot area and over the XAxis tick labels, in all three charts.
After: they are cut at the edges of the plot area, like the line, bars and dots.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • I have added a storybook story or VR test, or extended an existing story or VR test to show my changes

I used Claude Code to write this change.

Summary by CodeRabbit

  • Bug Fixes
    • Error bars now correctly follow their parent chart element’s clipping behavior in Line, Bar, and Scatter charts.
    • Error bars are clipped when data overflow is enabled and remain unclipped when overflow is disallowed.

When an axis has allowDataOverflow, Line, Bar and Scatter clip their
shapes to the plot area, but ErrorBar renders in its own zIndex layer
and so it escaped that clip path. Pass the clip path of the graphical
item through ErrorBarContext and set it on the error bars layer, as 2.x
did since #3300.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@coderabbitai

coderabbitai Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 45c73a06-03d6-4e26-b536-34c2c5e0bf6b
📥 Commits

Reviewing files that changed from the base of the PR and between 1727250 and b67a25c.

📒 Files selected for processing: 6
  • src/cartesian/Bar.tsx
  • src/cartesian/ErrorBar.tsx
  • src/cartesian/Line.tsx
  • src/cartesian/Scatter.tsx
  • src/context/ErrorBarContext.tsx
  • test/cartesian/ErrorBar.spec.tsx

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

Walkthrough

Error bars now inherit the clip path of their parent Line, Bar, or Scatter when axis data overflow clipping is enabled. Tests cover clipping behavior for all three chart elements.

Changes

ErrorBar clipping

Layer / File(s) Summary
Pass parent clip paths through context
src/context/ErrorBarContext.tsx, src/cartesian/Bar.tsx, src/cartesian/Line.tsx, src/cartesian/Scatter.tsx
ErrorBarContext now includes an optional clipPath. Line, Bar, and Scatter pass their conditional clip paths through the context.
Apply clipping to error bars
src/cartesian/ErrorBar.tsx, test/cartesian/ErrorBar.spec.tsx
ErrorBar applies the context-provided clip path to its outer layer. Tests check that ErrorBars inherit the parent clip path when overflow is allowed and have no clip path otherwise.

Priority: ➖ Normal

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

Change: Bug fix · Severity of issue fixed: Medium

Suggested reviewers: pavelvanecek

Merge Risk: ⚪ Minimal · up to b67a2

Error bars use their parent items’ clip paths where overflow clipping is enabled; no merge-blocking issue is established.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 6 functions across 6 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description check Passed The description is complete and follows the repository template. It explains the bug, links issue #8053, describes the motivation, documents testing, identifies the change as a bug fix, and confirms a…
Title check Passed The title clearly and concisely describes the main change: clipping ErrorBar elements with their graphical item.
Linked Issues check Passed Issue #8053 requires ErrorBar elements in Line, Bar, and Scatter to use the same clip path as the graphical item when allowDataOverflow is enabled. The PR adds clipPath to ErrorBarContext. Line, Bar, …
Out of Scope Changes check Passed The changes are limited to ErrorBarContext, ErrorBar, Line, Bar, Scatter, and focused ErrorBar tests. These changes implement or verify issue #8053. No unrelated behavior or files are identified.
Full details: Description check

Explanation

The description is complete and follows the repository template. It explains the bug, links issue #8053, describes the motivation, documents testing, identifies the change as a bug fix, and confirms added tests.

Full details: Linked Issues check

Explanation

Issue #8053 requires ErrorBar elements in Line, Bar, and Scatter to use the same clip path as the graphical item when allowDataOverflow is enabled. The PR adds clipPath to ErrorBarContext. Line, Bar, and Scatter pass their item clip path, or undefined when clipping is not required. ErrorBar applies the value to the recharts-errorBars layer. The added ErrorBar tests cover clipping for all three chart types and no clipping without allowDataOverflow.

  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

@codecov

codecov Bot commented Oct 22, 2026

Copy link
Copy Markdown

Bundle Report

Changes will increase total bundle size by 1.06kB (0.02%) ⬆️. This is within the configured threshold ✅

Detailed changes
Bundle name Size Change
recharts/bundle-cjs 1.68MB 301 bytes (0.02%) ⬆️
recharts/bundle-es6 1.5MB 301 bytes (0.02%) ⬆️
recharts/bundle-umd 640.62kB 156 bytes (0.02%) ⬆️
recharts/bundle-treeshaking-cartesian 851.27kB 301 bytes (0.04%) ⬆️

Affected Assets, Files, and Routes:

view changes for bundle: recharts/bundle-cjs

Assets Changed:

Asset Name Size Change Total Size Change (%)
cartesian/Bar.js 77 bytes 43.2kB 0.18%
cartesian/Scatter.js 51 bytes 36.01kB 0.14%
cartesian/Line.js 81 bytes 28.33kB 0.29%
cartesian/ErrorBar.js 69 bytes 14.28kB 0.49%
context/ErrorBarContext.js 23 bytes 3.48kB 0.67%
view changes for bundle: recharts/bundle-es6

Assets Changed:

Asset Name Size Change Total Size Change (%)
cartesian/Bar.js 77 bytes 41.12kB 0.19%
cartesian/Scatter.js 51 bytes 34.15kB 0.15%
cartesian/Line.js 81 bytes 26.64kB 0.3%
cartesian/ErrorBar.js 69 bytes 13.15kB 0.53%
context/ErrorBarContext.js 23 bytes 2.48kB 0.94%
view changes for bundle: recharts/bundle-umd

Assets Changed:

Asset Name Size Change Total Size Change (%)
Recharts.js 156 bytes 640.62kB 0.02%
view changes for bundle: recharts/bundle-treeshaking-cartesian

Assets Changed:

Asset Name Size Change Total Size Change (%)
bundle.js 301 bytes 851.27kB 0.04%

@codecov

codecov Bot commented Oct 22, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.14%. Comparing base (1727250) to head (b67a25c).
⚠️ Report is 4 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #8054   +/-   ##
=======================================
  Coverage   89.14%   89.14%           
=======================================
  Files         653      653           
  Lines       16194    16196    +2     
  Branches     4299     4301    +2     
=======================================
+ Hits        14436    14438    +2     
  Misses       1564     1564           
  Partials      194      194           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@flakiness-io

flakiness-io Bot commented Oct 22, 2026

Copy link
Copy Markdown

Test Results Summary

This comment shows the latest test results for this pull request.

Commit Status Test Results CI Runs
b67a25c ✅ Passed 3249 passed · 522 skipped 9 runs

View full report

ℹ️ About Flakiness.io in GitHub

Your team has set up Flakiness.io pull request comments. This comment is updated when

  • The first test results arrive for this pull request
  • A later run reports more results for the same commit
  • A new commit is pushed and tested

Flakiness.io rewrites the comment in place, so it always reflects the most recently tested commit.

@charan-rathore

Copy link
Copy Markdown
Contributor

Ran this on your branch. ErrorBar spec: 46/46 pass, including the four new clipping tests. On main with only your test file applied, the three "should clip" tests fail and the "should not clip" case passes, so the tests pin the fix. Line, Bar and Scatter specs still pass (41 tests), and tsc is clean.

One thing I checked while reading: the no-overflow case leaves clipPath undefined, so error bars outside an allowDataOverflow axis keep their current unclipped rendering - that matches the 2.x behavior you referenced. Nicely covered by the negative test.

Small note for reviewers: the change threads the parent's clip path through ErrorBarContext, so custom content rendering an ErrorBar outside a Line/Bar/Scatter gets clipPath undefined and behaves exactly as before. Nothing to change, just confirming the fallback.

@PavelVanecek
PavelVanecek merged commit b1f2c5b into recharts:main Oct 26, 2026
64 checks passed
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.

ErrorBar is not clipped when an axis has allowDataOverflow (regression of #2978)

3 participants