Skip to content

Update website examples for new hooks#6979

Merged
ckifer merged 2 commits intomainfrom
hook-examples
Feb 9, 2026
Merged

Update website examples for new hooks#6979
ckifer merged 2 commits intomainfrom
hook-examples

Conversation

@PavelVanecek
Copy link
Collaborator

@PavelVanecek PavelVanecek commented Feb 9, 2026

Summary by CodeRabbit

Release Notes

  • New Features

    • Added interactive examples demonstrating data snap and axis tick snap coordinate conversions, allowing users to see real-time pixel-to-data value translations.
    • Extended example components with initialization support for better testing and demonstration scenarios.
  • Documentation

    • Clarified inverse scale behavior for categorical domains in documentation.
  • Tests

    • Added visual regression tests for coordinate system examples.
    • Expanded test coverage for coordinate-related APIs.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 9, 2026

Caution

Review failed

Failed to post review comments

Walkthrough

This PR introduces new API examples for axis inverse snap scale and tick hooks, adds corresponding example components demonstrating data and tick snapping with pixel-to-data conversions, refactors the coordinate systems guide, and enhances example retrieval logic with component name normalization and API page filtering.

Changes

Cohort / File(s) Summary
Example reader logic
omnidoc/readExamples.ts
Added component name cleaning (trim) and hasOwnApiPage flag detection; adjusted filtering to prioritize explicit API entries for components with their own API page while preserving non-API examples.
Example verification tests
omnidoc/verifyExamples.spec.ts, omnidoc/readExamples.spec.ts
Removed several exports from exportsThatNeedExamples list; added test case verifying type-based example retrieval for InverseScaleFunction.
Hooks documentation
src/hooks.ts
Updated categorical scale descriptions for useXAxisInverseScale, useXAxisInverseTickSnapScale, useYAxisInverseScale, and useYAxisInverseDataSnapScale to reference corresponding data-snap variants.
Visual regression tests
test-vr/tests/www/AreaChartApiExamples.spec-vr.tsx, test-vr/tests/www/CoordinateSystems.spec-vr.tsx
Added initialPointers parameter to CrosshairExample test; introduced VR tests for DataSnapExample and AxisTickSnapExample with initialPointers setup.
Coordinate systems guide
www/src/components/GuideView/CoordinateSystems/*
Removed ScaleConversionExample.tsx; replaced with DataSnapExample and added AxisTickSnapExample in the guide index with corresponding source imports.
CrosshairExample enhancement
www/src/docs/apiExamples/getRelativeCoordinate/CrosshairExample.tsx
Added optional initialPointers prop (defaulting to empty array); renamed internal Crosshair component to PixelCrosshair; changed pointer state to ReadonlyArray type.
Axis inverse data snap scale examples
www/src/docs/apiExamples/useAxisInverseDataSnapScale/*
Added DataSnapExample component showcasing pixel-to-data conversion using useXAxisInverseDataSnapScale and useYAxisInverseDataSnapScale with pointer tracking; registered in index.ts.
Axis inverse tick snap scale examples
www/src/docs/apiExamples/useAxisInverseTickSnapScale/*
Added AxisTickSnapExample component demonstrating tick snapping using inverse tick snap scale hooks; registered in index.ts.
Axis tick examples
www/src/docs/apiExamples/useXAxisTicks/index.ts, www/src/docs/apiExamples/useYAxisTicks/index.ts
Added new API example entries mapping useXAxisTicks and useYAxisTicks to AxisTickSnapExample with devtools configuration.
API examples registry
www/src/docs/apiExamples/index.tsx
Extended imports and allApiExamples mapping with six new entries: useXAxisInverseDataSnapScale, useYAxisInverseDataSnapScale, useXAxisInverseTickSnapScale, useYAxisInverseTickSnapScale, useXAxisTicks, useYAxisTicks.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • PR #6897: Directly modifies the same ExampleReader logic in omnidoc/readExamples.ts (cleanName/hasOwnApiPage behavior) that is being enhanced in this PR.
  • PR #6911: Both PRs modify the exportsThatNeedExamples list in omnidoc/verifyExamples.spec.ts, adjusting which exports are expected to have examples.

Suggested reviewers

  • ckifer
🚥 Pre-merge checks | ✅ 1 | ❌ 2
❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Description check ⚠️ Warning The pull request description is missing entirely; no description content was provided by the author, leaving all template sections (Description, Related Issue, Motivation, Testing, etc.) unfilled. Add a comprehensive description covering: the motivation for these example updates, which new hooks are being documented, how the changes were tested (especially VR tests), and any related issues.
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Update website examples for new hooks' is directly related to the changeset, which adds new API example files and updates existing example components for newly documented hooks.

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

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch hook-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.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@www/src/docs/apiExamples/useAxisInverseDataSnapScale/DataSnapExample.tsx`:
- Line 139: The YAxis in DataSnapExample (YAxis domain={[0, 7000]}) is set far
below the mock data (sales up to ~50,000), causing the line to render off-chart;
update the YAxis domain in the DataSnapExample component to cover the data range
(e.g., domain={[0, 50000]} or a computed max) or reduce/mock the sales values to
match 0–7000, or add an inline comment explaining deliberate clipping if that
behavior is intended.
🧹 Nitpick comments (5)
omnidoc/readExamples.ts (1)

29-31: Minor inconsistency: includes vs strict equality for URL matching.

Line 30 uses ex.url.includes(...) to determine hasOwnApiPage, while line 38 uses ex.url === ... for the explicit match. Since URLs follow a consistent /api/{name}/ pattern, includes won't cause false positives today, but switching to strict equality here would be more consistent and future-proof.

Suggested change
-    const hasOwnApiPage = Array.from(this.fileToExamples.values()).some(exList =>
-      exList.some(ex => ex.url.includes(`/api/${cleanName}/`)),
-    );
+    const hasOwnApiPage = Array.from(this.fileToExamples.values()).some(exList =>
+      exList.some(ex => ex.url === `/api/${cleanName}/`),
+    );
www/src/components/GuideView/CoordinateSystems/index.tsx (1)

235-245: Both examples share the same stackBlitzTitle — consider differentiating them.

Lines 238 and 244 both use "Recharts Scale Conversion Example". If a user opens both in StackBlitz, they'll have identical titles. Consider giving the second one a distinct title, e.g., "Recharts Axis Tick Snap Example".

Proposed diff
       <CodeEditorWithPreview
         Component={AxisTickSnapExample}
         sourceCode={AxisTickSnapExampleSource}
-        stackBlitzTitle="Recharts Scale Conversion Example"
+        stackBlitzTitle="Recharts Axis Tick Snap Example"
       />
www/src/docs/apiExamples/useYAxisTicks/index.ts (1)

2-3: Inconsistent file extension on raw import.

Line 2 imports the component with .tsx extension, but line 3 omits it for the ?raw import. Other files in this PR (e.g., CoordinateSystems/index.tsx lines 11-12) consistently include .tsx before ?raw. This may work depending on bundler config, but it's inconsistent.

Proposed fix
-import AxisTickSnapExampleSource from '../useAxisInverseTickSnapScale/AxisTicksSnapExample?raw';
+import AxisTickSnapExampleSource from '../useAxisInverseTickSnapScale/AxisTicksSnapExample.tsx?raw';
www/src/docs/apiExamples/useXAxisTicks/index.ts (1)

2-3: Same raw import extension inconsistency as useYAxisTicks/index.ts.

Line 2 uses .tsx, line 3 omits it for the ?raw import.

Proposed fix
-import AxisTickSnapExampleSource from '../useAxisInverseTickSnapScale/AxisTicksSnapExample?raw';
+import AxisTickSnapExampleSource from '../useAxisInverseTickSnapScale/AxisTicksSnapExample.tsx?raw';
www/src/docs/apiExamples/useAxisInverseTickSnapScale/AxisTicksSnapExample.tsx (1)

1-149: Heavy duplication with DataSnapExample.tsx — consider extracting shared logic.

This file is nearly identical to DataSnapExample.tsx, differing only in the inverse scale hooks used (useXAxisInverseTickSnapScale vs useXAxisInverseDataSnapScale) and component names. The mock data, event handlers, chart layout, and crosshair rendering pattern are all duplicated.

Since these are documentation examples meant to be viewed as standalone source (via ?raw), full deduplication might hurt readability for the end user. But extracting the shared event handling and chart wrapper into a small shared module (leaving only the crosshair component unique) could reduce maintenance burden without hurting example clarity.

>
<CartesianGrid strokeDasharray="3 3" />
<XAxis dataKey="name" />
<YAxis domain={[0, 7000]} />
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Y-axis domain [0, 7000] is far below the data range (max 50,000).

The mock data has sales values up to 50,000, but the Y-axis domain caps at 7,000. This will cause the line to extend well beyond the visible chart area. If this is intentional to demonstrate clipping behavior, consider adding a comment. Otherwise, adjust the domain or the data to keep the example visually coherent.

🤖 Prompt for AI Agents
In `@www/src/docs/apiExamples/useAxisInverseDataSnapScale/DataSnapExample.tsx` at
line 139, The YAxis in DataSnapExample (YAxis domain={[0, 7000]}) is set far
below the mock data (sales up to ~50,000), causing the line to render off-chart;
update the YAxis domain in the DataSnapExample component to cover the data range
(e.g., domain={[0, 50000]} or a computed max) or reduce/mock the sales values to
match 0–7000, or add an inline comment explaining deliberate clipping if that
behavior is intended.

@codecov
Copy link

codecov bot commented Feb 9, 2026

Codecov Report

❌ Patch coverage is 30.50193% with 180 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.10%. Comparing base (fb0cd6b) to head (3451934).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...es/useAxisInverseDataSnapScale/DataSnapExample.tsx 12.63% 83 Missing ⚠️
...eAxisInverseTickSnapScale/AxisTicksSnapExample.tsx 12.63% 83 Missing ⚠️
...c/components/GuideView/CoordinateSystems/index.tsx 36.36% 7 Missing ⚠️
...xamples/getRelativeCoordinate/CrosshairExample.tsx 12.50% 7 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6979      +/-   ##
==========================================
- Coverage   90.45%   90.10%   -0.36%     
==========================================
  Files         517      522       +5     
  Lines       38618    38844     +226     
  Branches     5347     5347              
==========================================
+ Hits        34933    35000      +67     
- Misses       3676     3835     +159     
  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.

@codecov
Copy link

codecov bot commented Feb 9, 2026

Bundle Report

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

Detailed changes
Bundle name Size Change
recharts/bundle-cjs 1.25MB 140 bytes (0.01%) ⬆️
recharts/bundle-es6 1.09MB 140 bytes (0.01%) ⬆️

Affected Assets, Files, and Routes:

view changes for bundle: recharts/bundle-es6

Assets Changed:

Asset Name Size Change Total Size Change (%)
hooks.js 140 bytes 21.32kB 0.66%
view changes for bundle: recharts/bundle-cjs

Assets Changed:

Asset Name Size Change Total Size Change (%)
hooks.js 140 bytes 23.59kB 0.6%

@github-actions
Copy link
Contributor

github-actions bot commented Feb 9, 2026

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.

@ckifer ckifer merged commit bff7456 into main Feb 9, 2026
45 of 48 checks passed
@ckifer ckifer deleted the hook-examples branch February 9, 2026 20:51
@coderabbitai coderabbitai bot mentioned this pull request Mar 1, 2026
7 tasks
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.

2 participants