fix(Label): pass computed position attributes to custom label content#7549
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
💤 Files with no reviewable changes (1)
🚧 Files skipped from review as they are similar to previous changes (1)
Walkthrough
ChangesLabel positioning
Estimated code review effort: 3 (Moderate) | ~20 minutes Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
Bundle ReportChanges will increase total bundle size by 7.75kB (0.14%) ⬆️. This is within the configured threshold ✅ Detailed changes
Affected Assets, Files, and Routes:view changes for bundle: recharts/bundle-treeshaking-cartesianAssets Changed:
view changes for bundle: recharts/bundle-es6Assets Changed:
view changes for bundle: recharts/bundle-treeshaking-polarAssets Changed:
view changes for bundle: recharts/bundle-treeshaking-treemapAssets Changed:
view changes for bundle: recharts/bundle-cjsAssets Changed:
view changes for bundle: recharts/bundle-umdAssets Changed:
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #7549 +/- ##
==========================================
+ Coverage 88.18% 88.20% +0.01%
==========================================
Files 613 615 +2
Lines 14258 14276 +18
Branches 3589 3592 +3
==========================================
+ Hits 12574 12592 +18
Misses 1494 1494
Partials 190 190 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Description
Custom label content (
contentas element or function, e.g.<YAxis label={<MyLabel />} />) returned early fromLabelbefore the position was ever calculated, so it only receivedviewBoxand the passthrough props — never the computedx/y/textAnchor/verticalAnchorthe built-inTextlabel gets. That's the mechanism ckifer described in the issue thread ("does these calculations only if you aren't using a custom component").This hoists the position calculation above the custom-content branches and merges the computed attributes into the props handed to
cloneElement/createElement. It's additive: explicitly passed props still win, the built-inTextpath renders exactly as before, and radial polar labels (insideStart/insideEnd/end) are unchanged since their rendering isn't attribute-based.Two existing specs asserted the exact prop set custom content receives, so they now include the new attributes (
Label.spec.tsx,Bar.spec.tsx) — the values they pin down (e.g. center of the viewBox) double as verification that the computed positions are correct.Related Issue
Fixes #5067
Motivation and Context
Custom labels currently have to re-derive their own position from
viewBox, duplicating logic recharts already has, and axis labels in particular land at (0,0)/unpositioned. With this change a custom label can just useprops.x/props.ylike the built-in label does.How Has This Been Tested?
New regression test rendering
<YAxis label={<CustomLabel />} />in aLineChartand asserting the custom element receives numericx/y— fails on current main, passes with this change. Updated prop-set assertions inLabel.spec.tsx(6 sites) andBar.spec.tsxalso fail on main and pass now. FullLabel,LabelListandBarsuites pass (165 tests), plustscand eslint on the changed files; the rest of the unit suite matches the baseline.Screenshots (if appropriate):
n/a — no visual change for built-in labels; custom labels keep rendering whatever they render, they just receive more props.
Types of changes
Checklist:
Summary by CodeRabbit
xandycoordinates.