Skip to content

Allow rendering Labels as nested children in XAxis and YAxis. and Reference elements#6219

Merged
ckifer merged 2 commits intomainfrom
label-context-2
Aug 15, 2025
Merged

Allow rendering Labels as nested children in XAxis and YAxis. and Reference elements#6219
ckifer merged 2 commits intomainfrom
label-context-2

Conversation

@PavelVanecek
Copy link
Collaborator

@PavelVanecek PavelVanecek commented Aug 15, 2025

Description

Instead of parsing array of children, pass the viewBox in React context where Label can read it.

Related Issue

Fixes #6156

#5768

Motivation and Context

Removing findAllByType

How Has This Been Tested?

VR tests, storybook

Screenshots (if appropriate):

No visual difference

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

Copilot AI review requested due to automatic review settings August 15, 2025 08:43
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR enables rendering Labels as nested children in XAxis and YAxis components by introducing a React context-based approach to pass viewBox data. This replaces the previous array parsing mechanism with a more React-friendly pattern.

Key changes:

  • Introduces CartesianLabelContext to provide viewBox data to nested Label components
  • Updates CartesianAxis to render children Labels through context instead of direct child parsing
  • Adds new CartesianLabelFromLabelProp component for handling label prop compatibility

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
test-vr/playwright-ct.config.ts Adds expect timeout configuration for test stability
storybook/stories/API/cartesian/XAxis.stories.tsx Updates story to demonstrate nested Label components in XAxis
src/component/Label.tsx Implements CartesianLabelContext and provider for passing viewBox to nested Labels
src/cartesian/CartesianAxis.tsx Updates axis rendering to use context provider and support nested Label children

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
You can also share your feedback on Copilot code review for a chance to win a $100 gift card. Take the survey.

if (isValidElement(label)) {
if (label.type === Label) {
return cloneElement<LabelProps>(label, { key: 'label-implicit', ...commonProps });
return cloneElement<SVGElement>(label, { key: 'label-implicit', ...commonProps });
Copy link

Copilot AI Aug 15, 2025

Choose a reason for hiding this comment

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

The type parameter SVGElement is incorrect for cloneElement when cloning a Label component. This should be LabelProps to match the original typing and ensure proper prop typing.

Suggested change
return cloneElement<SVGElement>(label, { key: 'label-implicit', ...commonProps });
return cloneElement<LabelProps>(label, { key: 'label-implicit', ...commonProps });

Copilot uses AI. Check for mistakes.
@codecov
Copy link

codecov bot commented Aug 15, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.68%. Comparing base (5a5989f) to head (e943f5b).
⚠️ Report is 7 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6219      +/-   ##
==========================================
- Coverage   96.70%   96.68%   -0.02%     
==========================================
  Files         221      221              
  Lines       19880    19926      +46     
  Branches     4102     4106       +4     
==========================================
+ Hits        19224    19265      +41     
- Misses        650      655       +5     
  Partials        6        6              

☔ 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 Aug 15, 2025

Bundle Report

Changes will increase total bundle size by 4.9kB (0.2%) ⬆️. This is within the configured threshold ✅

Detailed changes
Bundle name Size Change
recharts/bundle-cjs 1.03MB 2.2kB (0.21%) ⬆️
recharts/bundle-es6 886.17kB 2.16kB (0.24%) ⬆️
recharts/bundle-umd 484.64kB 546 bytes (0.11%) ⬆️

Affected Assets, Files, and Routes:

view changes for bundle: recharts/bundle-umd

Assets Changed:

Asset Name Size Change Total Size Change (%)
Recharts.js 546 bytes 484.64kB 0.11%
view changes for bundle: recharts/bundle-es6

Assets Changed:

Asset Name Size Change Total Size Change (%)
component/Label.js 1.25kB 17.39kB 7.77% ⚠️
cartesian/CartesianAxis.js 321 bytes 13.03kB 2.53%
cartesian/ReferenceLine.js 194 bytes 7.55kB 2.64%
cartesian/ReferenceArea.js 194 bytes 6.05kB 3.31%
cartesian/ReferenceDot.js 194 bytes 5.5kB 3.66%
view changes for bundle: recharts/bundle-cjs

Assets Changed:

Asset Name Size Change Total Size Change (%)
component/Label.js 1.48kB 19.0kB 8.44% ⚠️
cartesian/CartesianAxis.js 275 bytes 14.19kB 1.98%
cartesian/ReferenceLine.js 148 bytes 8.7kB 1.73%
cartesian/ReferenceArea.js 148 bytes 7.11kB 2.13%
cartesian/ReferenceDot.js 148 bytes 6.5kB 2.33%

@PavelVanecek PavelVanecek changed the title Allow rendering Labels as nested children in XAxis and YAxis Allow rendering Labels as nested children in XAxis and YAxis. and Reference elements Aug 15, 2025
@PavelVanecek PavelVanecek added enhancement Enhancement to a current API feature request Issues that are feature requests labels Aug 15, 2025
@ckifer ckifer merged commit e5daa61 into main Aug 15, 2025
25 of 27 checks passed
@ckifer ckifer deleted the label-context-2 branch August 15, 2025 13:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Enhancement to a current API feature request Issues that are feature requests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Axis labels cannot be wrapped in a custom component

3 participants