Skip to content

fix(Bar): pass the original data index to sparse bar mouse events - #7929

Merged
PavelVanecek merged 1 commit into
recharts:mainfrom
charan-rathore:fix/bar-sparse-event-index
Oct 17, 2026
Merged

PavelVanecek merged 1 commit into
recharts:mainfrom
charan-rathore:fix/bar-sparse-event-index

Conversation

@charan-rathore

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

Copy link
Copy Markdown
Contributor

Description

When a bar is skipped (for example a zero value), the rendered rectangles no longer line up with the data array by position. Two adaptEventsOfChild call sites in Bar.tsx bind onMouseMove, onMouseDown, onMouseUp, onMouseOver and onMouseOut with the rendered position i, so those handlers receive the wrong index and payload for sparse data. The sibling onClick/onMouseEnter/onMouseLeave handlers already use entry.originalDataIndex.

This change passes entry.originalDataIndex at both call sites (the bar rectangle and the background rectangle), making all eight callbacks consistent.

A new spec test/cartesian/Bar.sparseEvents.spec.tsx adds 10 parameterized cases: for both the bar and the background rectangle, each of the five affected events must receive the original data index and the matching payload.

Related Issue

Fixes #7928

Motivation and Context

Consumers reading the index argument of these callbacks (to look up the datum, sync external state, etc.) get the wrong entry whenever any bar is skipped, and the behavior disagrees with the click handler on the same rectangle.

How Has This Been Tested?

  • The 10 new cases fail on unpatched main (10/10 red: handlers receive index 0 and category A's payload for the category B rectangle) and pass with the change (10/10 green).
  • Four relevant suites pass post-change: Bar.sparseEvents.spec.tsx, Bar/Bar.spec.tsx, BarChart.spec.tsx, BarStack.spec.tsx - 253 tests green.
  • Prettier and ESLint clean on the changed files.
  • Full library suite: not claimed green. One full run completed 337 suites with 6,757 passed and 2 failed, both 5s timeouts in test/polar/Pie/Pie.typed.spec.tsx during a window overlapping a heap-heavy typecheck; that spec passes 5/5 on isolated reruns against both unpatched main (119ms) and this change (120ms), so the timeouts are resource contention, but a clean full-suite run is not claimed.
  • Not run: the test-wide TypeScript check (hit heap limits without a captured completion), storybook tests, and the Playwright visual-regression suite.

Screenshots (if appropriate):

N/A

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

This change was prepared with AI assistance and verified locally as described above.

Summary by CodeRabbit

  • Bug Fixes
    • Bar chart mouse events now report the correct data index and payload when the data includes zero values.

@coderabbitai

coderabbitai Bot commented Oct 7, 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: 0bfb4357-547a-4f1a-919d-5bf26a435b30
📥 Commits

Reviewing files that changed from the base of the PR and between e6c5168 and 6e903ce.

📒 Files selected for processing (2)
  • src/cartesian/Bar.tsx
  • test/cartesian/Bar.sparseEvents.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

Bar rectangle and background mouse event handlers now receive each entry’s original data index. Tests cover five mouse events when sparse data causes the first bar to be skipped.

Changes

Bar sparse-data events

Layer / File(s) Summary
Use original indices for mouse events
src/cartesian/Bar.tsx, test/cartesian/Bar.sparseEvents.spec.tsx
Bar and background event adapters pass the entry’s original data index. Tests check five mouse events and verify the index and payload for sparse data.

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 6e903

Bar mouse callbacks will now report the original data index when bars are skipped for sparse data. This matches the other Bar callbacks, and no merge-blocking risk was found.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ 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 2 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the fix: passing the original data index to sparse bar mouse events.
Description check ✅ Passed The description is complete and follows the repository template. It explains the bug, links issue #7928, describes the motivation, documents targeted tests and limitations, and marks the bug-fix and t…
Linked Issues check ✅ Passed Issue #7928 requires all Bar mouse callbacks to use the original data-array index for sparse data, including bar and background rectangles. The change in src/cartesian/Bar.tsx passes `entry.original…
Out of Scope Changes check ✅ Passed The changes are limited to the two adaptEventsOfChild call sites in src/cartesian/Bar.tsx and focused regression tests in test/cartesian/Bar.sparseEvents.spec.tsx. Both changes directly support …
  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autopilot · 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 7, 2026

Copy link
Copy Markdown

Bundle Report

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

Detailed changes
Bundle name Size Change
recharts/bundle-cjs 1.64MB 44 bytes (0.0%) ⬆️
recharts/bundle-es6 1.45MB 44 bytes (0.0%) ⬆️
recharts/bundle-umd 631.55kB 36 bytes (0.01%) ⬆️
recharts/bundle-treeshaking-cartesian 816.6kB 44 bytes (0.01%) ⬆️

Affected Assets, Files, and Routes:

view changes for bundle: recharts/bundle-es6

Assets Changed:

Asset Name Size Change Total Size Change (%)
cartesian/Bar.js 44 bytes 37.35kB 0.12%
view changes for bundle: recharts/bundle-treeshaking-cartesian

Assets Changed:

Asset Name Size Change Total Size Change (%)
bundle.js 44 bytes 816.6kB 0.01%
view changes for bundle: recharts/bundle-cjs

Assets Changed:

Asset Name Size Change Total Size Change (%)
cartesian/Bar.js 44 bytes 39.22kB 0.11%
view changes for bundle: recharts/bundle-umd

Assets Changed:

Asset Name Size Change Total Size Change (%)
Recharts.js 36 bytes 631.55kB 0.01%

@codecov

codecov Bot commented Oct 7, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 88.97%. Comparing base (e6c5168) to head (6e903ce).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #7929   +/-   ##
=======================================
  Coverage   88.97%   88.97%           
=======================================
  Files         647      647           
  Lines       15872    15872           
  Branches     4172     4172           
=======================================
  Hits        14122    14122           
  Misses       1556     1556           
  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 7, 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
6e903ce ✅ Passed 2765 passed · 443 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 Author

This is green on CI and conflict-free on my end. Is there anything you'd like changed before it can land? Happy to adjust.

@PavelVanecek
PavelVanecek merged commit 3dbb1b4 into recharts:main Oct 17, 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.

Bar mouse events report the wrong data index for sparse data (onMouseMove/Down/Up/Over/Out)

2 participants