Skip to content

fix(BarStack): normalize a lone rectangle so single negative bars round at the outer end - #7896

Merged
PavelVanecek merged 1 commit into
recharts:mainfrom
charan-rathore:fix/bar-stack-single-negative-bar
Oct 3, 2026
Merged

PavelVanecek merged 1 commit into
recharts:mainfrom
charan-rathore:fix/bar-stack-single-negative-bar

Conversation

@charan-rathore

@charan-rathore charan-rathore commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

In a BarStack with negative values, an index with only one bar got its rounded corners at the zero line instead of at the outer end of the bar. With two or more bars at the same index it was fine. expandRectangle merges the bar rectangles of a stack and normalizes them with min and max, but when there was only one rectangle it returned it unchanged and kept its negative height, so the corner radius landed at y + height, which is the zero line. Now a single rectangle goes through the same normalization. Thanks to the reporter of #7895 for the report, the rendered clip path comparison and the pointer to expandRectangle.

Tests: unit tests for a lone rectangle with negative height and width, and a chart test with one single-bar index and one two-bar index. The test results come from the patch builder and I did not rerun them. Full npm test, storybook, visual regression and build were not run.

Fixes #7895.

Summary by CodeRabbit

  • Bug Fixes
    • Fixed stacked bar rendering when a data point has only one bar, so its rectangle spans the bar’s actual bounds instead of the zero line.
    • Corrected rectangles with negative width or height to use non-negative dimensions, including when only one rectangle is present. This improves display of stacks containing negative values.

@coderabbitai

coderabbitai Bot commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

🧰 Additional context used
📚 Code guidelines (1)
CONTRIBUTING.md — configured

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: b6473a42-03aa-4300-be7b-e75840b6378f

📥 Commits

Reviewing files that changed from the base of the PR and between ed131bf and 8bc6c75.

📒 Files selected for processing (2)
  • src/state/selectors/barStackSelectors.ts
  • test/state/selectors/barStackSelectors.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

expandRectangle now normalizes a lone rectangle using endpoint bounds and returns undefined when both inputs are absent. Tests cover negative rectangle dimensions and single-bar negative stack bounds.

Changes

Single-bar rectangle bounds

Layer / File(s) Summary
Normalize lone rectangles and verify stack bounds
src/state/selectors/barStackSelectors.ts, test/state/selectors/barStackSelectors.spec.tsx
expandRectangle normalizes a lone rectangle and returns undefined when both inputs are absent. Tests check negative dimensions and verify the bounds of a single negative bar in a stack.

Priority: ⬇️ Low

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

Change: Bug fix · Severity of issue fixed: Low

Merge Risk: ⚪ Minimal · up to 8bc6c

The change normalizes lone stack rectangles, and the added tests cover negative dimensions and single negative bars. No actionable merge risk remains beyond normal checks.

Architecture Summary

Architecture risk: 🔵 Low · up to 8bc6c

The change affects 2 systems.

Changed systems: src, test

Architecture concerns
No architecture-level concerns identified.

Review details

Systems and components

  • observed — src (service) was modified; 1 changed file maps to changed impact.
  • observed — test (service) was modified; 1 changed file maps to changed impact.

Before / after behavior

  • observed — Modified behavior in src/state/selectors/barStackSelectors.ts: expandRectangle now returns undefined if both inputs are absent and uses the available rectangle for both bounds operands when only one is supplied. This replaces returning a lone rectangle unchanged, so lone rectangles with negative width or height are normalized by the endpoint-based bounds calculation.
  • observed — Modified behavior in test/state/selectors/barStackSelectors.spec.tsx: Adds a negative-value stackOffset="sign" case with two data indices, where the second bar is zero at the first index. The test expects two stack rectangles, both with positive height.
  • observed — Modified behavior in test/state/selectors/barStackSelectors.spec.tsx: Adds a check that the first stack rectangle’s vertical bounds match the single negative bar’s endpoints, rather than extending from the zero line.
  • observed — Modified behavior in test/state/selectors/barStackSelectors.spec.tsx: Adds expandRectangle tests asserting that a single rectangle with negative height or width is normalized to positive dimensions, whether passed as the first or second argument.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the main change: normalizing a lone rectangle in BarStack so negative bars round at the outer end.
Description check ✅ Passed The description explains the defect, cause, fix, related issue, tests, and testing limitations. It does not use the template headings or complete the change-type and checklist items, but the required …
Linked Issues check ✅ Passed Issue #7895 requires a lone negative BarStack rectangle to use normalized bounds, so rounding occurs at the outer end. expandRectangle now applies the existing min/max calculation when either inpu…
Out of Scope Changes check ✅ Passed The changes are limited to expandRectangle and focused selector tests. The implementation, regression tests, and negative-dimension coverage directly support issue #7895. No unrelated production or …
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 2…
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Autopilot is currently an internal CodeRabbit preview.


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.

@8bnns 8bnns 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.

@8bnns 8bnns 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.

@8bnns 8bnns 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.

@8bnns 8bnns 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.

@codecov

codecov Bot commented Oct 3, 2026

Copy link
Copy Markdown

Bundle Report

Changes will increase total bundle size by 681 bytes (0.01%) ⬆️. This is within the configured threshold ✅

Detailed changes
Bundle name Size Change
recharts/bundle-cjs 1.63MB 224 bytes (0.01%) ⬆️
recharts/bundle-es6 1.44MB 224 bytes (0.02%) ⬆️
recharts/bundle-umd 628.29kB 9 bytes (0.0%) ⬆️
recharts/bundle-treeshaking-cartesian 810.03kB 224 bytes (0.03%) ⬆️

Affected Assets, Files, and Routes:

view changes for bundle: recharts/bundle-cjs

Assets Changed:

Asset Name Size Change Total Size Change (%)
state/selectors/barStackSelectors.js 224 bytes 4.48kB 5.26% ⚠️
view changes for bundle: recharts/bundle-umd

Assets Changed:

Asset Name Size Change Total Size Change (%)
Recharts.js 9 bytes 628.29kB 0.0%
view changes for bundle: recharts/bundle-treeshaking-cartesian

Assets Changed:

Asset Name Size Change Total Size Change (%)
bundle.js 224 bytes 810.03kB 0.03%
view changes for bundle: recharts/bundle-es6

Assets Changed:

Asset Name Size Change Total Size Change (%)
state/selectors/barStackSelectors.js 224 bytes 3.93kB 6.04% ⚠️

@codecov

codecov Bot commented Oct 3, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 88.85%. Comparing base (ed131bf) to head (8bc6c75).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #7896   +/-   ##
=======================================
  Coverage   88.85%   88.85%           
=======================================
  Files         643      643           
  Lines       15744    15744           
  Branches     4128     4129    +1     
=======================================
  Hits        13990    13990           
  Misses       1560     1560           
  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 3, 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
8bc6c75 ✅ Passed 3024 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.

@PavelVanecek
PavelVanecek merged commit 9ce1a70 into recharts:main Oct 3, 2026
64 checks passed
@charan-rathore
charan-rathore deleted the fix/bar-stack-single-negative-bar branch October 3, 2026 12:06
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.

BarStack radius: a single bar below zero is rounded at the zero line

3 participants