Skip to content

Fix activeBar highlighting with missing/null data#7001

Merged
PavelVanecek merged 4 commits into
mainfrom
copilot/fix-active-bar-missing-data
Feb 15, 2026
Merged

Fix activeBar highlighting with missing/null data#7001
PavelVanecek merged 4 commits into
mainfrom
copilot/fix-active-bar-missing-data

Conversation

Copilot AI commented Feb 12, 2026

Copy link
Copy Markdown
Contributor

Description

activeBar highlighting jumps to wrong bars when data contains null values. The tooltip's activeIndex references the original data array, but bar rendering uses the filtered array (nulls removed), causing index mismatch.

Changes:

  • Added originalDataIndex field to BarRectangleItem to preserve data position before null filtering
  • Updated BarRectangleWithActiveState to compare using originalDataIndex instead of filtered array index
  • Added tests validating correct highlighting with sparse data

Example with missing data:

const data = [
  { name: 'A', value: 100 },
  { name: 'B', value: null },  // filtered out
  { name: 'C', value: 200 },
  { name: 'D', value: null },  // filtered out
  { name: 'E', value: 300 },
];

// Before: hovering 'E' (originalIndex=4) incorrectly highlighted bar at filteredIndex=2
// After: correctly highlights 'E' by matching originalDataIndex=4 to activeIndex=4
<Bar activeBar dataKey="value" />

Related Issue

See linked issue for reproduction case and screenshot showing incorrect highlighting offset.

Motivation and Context

Filtering null bars renumbers array indices, breaking the activeBar/tooltip index contract. This is fundamental to correct hover behavior with sparse data.

How Has This Been Tested?

  • Added unit tests with missing data patterns (nulls at various positions)
  • Verified all 13,888 existing tests pass
  • TypeScript compilation verified
  • CodeQL security scan passed

Screenshots (if appropriate):

See issue for before/after showing highlight jumping to wrong bar.

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
Original prompt

This section details on the original issue you should resolve

<issue_title>activeBar doesn't work properly if there is a missing data</issue_title>
<issue_description>## What is the current behavior?

Image

The active state scales to the next bar by a value equal to the number of missing data.

What is the expected behavior?

active state remains on the current bar ( bar in hover)

Please provide a demo of the problem in a sandbox

https://stackblitz.com/edit/bdua6xbz?file=src%2FExample.tsx

Which versions of Recharts, and which browser / OS are affected by this issue? Did this work in previous versions of Recharts?

3.7.0
</issue_description>

<agent_instructions>Begin by writing a unit test to reproduce</agent_instructions>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI changed the title [WIP] Fix activeBar scaling issue due to missing data Fix activeBar highlighting with missing/null data Feb 12, 2026
Copilot AI requested a review from PavelVanecek February 12, 2026 15:32
@PavelVanecek
PavelVanecek marked this pull request as ready for review February 13, 2026 13:24
@codecov

codecov Bot commented Feb 13, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.10%. Comparing base (c23ca6b) to head (7676334).
⚠️ Report is 9 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #7001   +/-   ##
=======================================
  Coverage   90.10%   90.10%           
=======================================
  Files         522      522           
  Lines       38848    38851    +3     
  Branches     5347     5348    +1     
=======================================
+ Hits        35004    35007    +3     
  Misses       3835     3835           
  Partials        9        9           

☔ View full report in Codecov by Sentry.
📢 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.

@github-actions

Copy link
Copy Markdown
Contributor

Staging Deployment Details

These deployments will remain available for 30 days.

To update snapshots: Comment /update-snapshots on this PR to automatically update the baseline screenshots.

@PavelVanecek

Copy link
Copy Markdown
Collaborator
image

@codecov

codecov Bot commented Feb 13, 2026

Copy link
Copy Markdown

Bundle Report

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

Detailed changes
Bundle name Size Change
recharts/bundle-cjs 1.25MB 309 bytes (0.02%) ⬆️
recharts/bundle-es6 1.09MB 309 bytes (0.03%) ⬆️
recharts/bundle-umd 539.31kB 38 bytes (0.01%) ⬆️

Affected Assets, Files, and Routes:

view changes for bundle: recharts/bundle-cjs

Assets Changed:

Asset Name Size Change Total Size Change (%)
cartesian/Bar.js 309 bytes 28.14kB 1.11%
view changes for bundle: recharts/bundle-umd

Assets Changed:

Asset Name Size Change Total Size Change (%)
Recharts.js 38 bytes 539.31kB 0.01%
view changes for bundle: recharts/bundle-es6

Assets Changed:

Asset Name Size Change Total Size Change (%)
cartesian/Bar.js 309 bytes 26.39kB 1.18%

@PavelVanecek
PavelVanecek merged commit 4437af2 into main Feb 15, 2026
46 of 47 checks passed
@PavelVanecek
PavelVanecek deleted the copilot/fix-active-bar-missing-data branch February 15, 2026 08:24
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.

activeBar doesn't work properly if there is a missing data

2 participants