Skip to content

Add new example where chart animates by scroll#7484

Merged
PavelVanecek merged 1 commit into
mainfrom
animation-examples
Jun 22, 2026
Merged

Add new example where chart animates by scroll#7484
PavelVanecek merged 1 commit into
mainfrom
animation-examples

Conversation

@PavelVanecek

@PavelVanecek PavelVanecek commented Jun 22, 2026

Copy link
Copy Markdown
Collaborator

Website example using the new animation props

Summary by CodeRabbit

  • Documentation
    • Added a new example demonstrating bar chart animation synchronized with page scroll position

@coderabbitai

coderabbitai Bot commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

Adds a new ScrollAnimateBarChart example component that implements a custom AnimationController driving bar chart animation from window.scrollY. The component is registered in the barChartExamples map, and the verifyExamples test exclusion list is updated to remove exports that now have example coverage.

Changes

Scroll-Driven BarChart Animation Example

Layer / File(s) Summary
ScrollAnimateBarChart component and custom controller
www/src/docs/exampleComponents/BarChart/ScrollAnimateBarChart.tsx
Implements scrollAnimationController that computes animation time from window.scrollY normalized by document height, ticks an AnimationHandle, and manages a scroll event listener. Defines the ScrollAnimateBarChart component wrapping a horizontal typed BarChart in AnimationControllerProvider with two Bar series and RechartsDevtools, then default-exports the component.
Register example in barChartExamples
www/src/docs/exampleComponents/BarChart/index.tsx
Imports ScrollAnimateBarChart and its raw source, then adds an "Animate by Scroll" entry to the barChartExamples map with Component, sourceCode, name, and description.
Update verifyExamples test exclusions
omnidoc/verifyExamples.spec.ts
Removes createHorizontalChart and several Animation*/controller-related exports (AnimationController, provider/handle, CancelableTimeout, OnAnimationStateUpdate) from the exportsThatNeedExamples exclusion list, as they now have example coverage.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • recharts/recharts#6741: Also adds new entries to the same barChartExamples map in www/src/docs/exampleComponents/BarChart/index.tsx.
  • recharts/recharts#7476: Directly modifies the same exportsThatNeedExamples exclusion logic in omnidoc/verifyExamples.spec.ts.
  • recharts/recharts#7481: Touches omnidoc/verifyExamples.spec.ts and refactors/exports the AnimationControllerProvider API surface consumed by the new scroll example.

Suggested reviewers

  • ckifer
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description is incomplete and vague. It does not address most required template sections including Related Issue, Motivation/Context, Testing details, or Types of changes. Complete the description template by adding Related Issue link, Motivation and Context explaining why this example was added, How Has This Been Tested section, and checking appropriate boxes in Types of changes and Checklist sections.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately and concisely summarizes the main change: adding a new example where a chart animates based on scroll position.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch animation-examples

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 and usage tips.

@codecov

codecov Bot commented Jun 22, 2026

Copy link
Copy Markdown

Bundle Report

Bundle size has no change ✅

@chromatic-com

chromatic-com Bot commented Jun 22, 2026

Copy link
Copy Markdown

Tip

All tests passed and all changes approved!

🟢 UI Tests: 198 tests unchanged
🟢 UI Review: 198 stories published -- no changes
Storybook icon Storybook Publish: 198 stories published

@codecov

codecov Bot commented Jun 22, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 57.89474% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 88.06%. Comparing base (a2c4171) to head (b77d69a).

Files with missing lines Patch % Lines
...ampleComponents/BarChart/ScrollAnimateBarChart.tsx 57.89% 8 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7484      +/-   ##
==========================================
- Coverage   88.10%   88.06%   -0.04%     
==========================================
  Files         603      604       +1     
  Lines       13975    13994      +19     
  Branches     3523     3523              
==========================================
+ Hits        12312    12324      +12     
- Misses       1476     1483       +7     
  Partials      187      187              

☔ 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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@www/src/docs/exampleComponents/BarChart/ScrollAnimateBarChart.tsx`:
- Around line 32-45: The handleScroll function has two issues: first, when
animationFinishesAt equals zero (on non-scrollable pages), the division
scrollTop / animationFinishesAt produces NaN or Infinity; second, the
unconditional animationHandle.tick(0) call on line 43 always initializes to time
zero, even when the page loads mid-scroll. Fix this by guarding
animationFinishesAt against zero by using Math.max with a minimum fallback value
to ensure it's never zero, and replace the hardcoded tick(0) initialization with
a calculation that uses the actual current scroll position and scroll fraction,
matching the same logic used inside the handleScroll function body.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: d570a3d1-f998-4dfa-846d-86f777798a4d

📥 Commits

Reviewing files that changed from the base of the PR and between a2c4171 and b77d69a.

📒 Files selected for processing (3)
  • omnidoc/verifyExamples.spec.ts
  • www/src/docs/exampleComponents/BarChart/ScrollAnimateBarChart.tsx
  • www/src/docs/exampleComponents/BarChart/index.tsx
💤 Files with no reviewable changes (1)
  • omnidoc/verifyExamples.spec.ts

Comment on lines +32 to +45
const handleScroll = () => {
const scrollTop = window.scrollY;
const docHeight = document.documentElement.scrollHeight - window.innerHeight;
const animationFinishesAt = docHeight / 2;
const scrollFraction = Math.min(Math.max(scrollTop / animationFinishesAt, 0), 1);
const animationDuration = animationHandle.getAnimationDuration();
const currentTime = scrollFraction * animationDuration;
animationHandle.tick(currentTime);
listener(animationHandle.getInterpolated());
};

animationHandle.tick(0);

window.addEventListener('scroll', handleScroll);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Initialize scroll-driven time from actual scroll and guard zero-height pages.

On Line 35-38, animationFinishesAt can be 0 when the page is not scrollable, so scrollTop / animationFinishesAt may become NaN/Infinity. Also, Line 43 forces tick(0) even when the page loads mid-scroll, so initial state can be wrong until the next scroll event.

Suggested fix
 const scrollAnimationController: AnimationController = (
   _timeoutController,
   animationHandle: AnimationHandle,
   listener: OnAnimationStateUpdate,
 ): CancelableTimeout => {
   const handleScroll = () => {
     const scrollTop = window.scrollY;
     const docHeight = document.documentElement.scrollHeight - window.innerHeight;
-    const animationFinishesAt = docHeight / 2;
+    const animationFinishesAt = Math.max(docHeight / 2, 1);
     const scrollFraction = Math.min(Math.max(scrollTop / animationFinishesAt, 0), 1);
     const animationDuration = animationHandle.getAnimationDuration();
     const currentTime = scrollFraction * animationDuration;
     animationHandle.tick(currentTime);
     listener(animationHandle.getInterpolated());
   };

-  animationHandle.tick(0);
-
   window.addEventListener('scroll', handleScroll);
+  handleScroll();

   return () => {
     window.removeEventListener('scroll', handleScroll);
   };
 };
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@www/src/docs/exampleComponents/BarChart/ScrollAnimateBarChart.tsx` around
lines 32 - 45, The handleScroll function has two issues: first, when
animationFinishesAt equals zero (on non-scrollable pages), the division
scrollTop / animationFinishesAt produces NaN or Infinity; second, the
unconditional animationHandle.tick(0) call on line 43 always initializes to time
zero, even when the page loads mid-scroll. Fix this by guarding
animationFinishesAt against zero by using Math.max with a minimum fallback value
to ensure it's never zero, and replace the hardcoded tick(0) initialization with
a calculation that uses the actual current scroll position and scroll fraction,
matching the same logic used inside the handleScroll function body.

@github-actions

Copy link
Copy Markdown
Contributor

@PavelVanecek
PavelVanecek merged commit 6dbe130 into main Jun 22, 2026
63 of 65 checks passed
@PavelVanecek
PavelVanecek deleted the animation-examples branch June 22, 2026 22:56
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