feat(XAxis): support height="auto" to size the axis to its tick labels#7570
Conversation
Mirror the existing YAxis width="auto" behavior. When height="auto", the axis height is measured from the rendered tick labels and axis label after layout and dispatched back into axis state, so rotated or multi-line tick labels are not clipped and do not need manual margin.bottom tuning. Opt-in; the default height (30) is unchanged. Fixes recharts#7301.
|
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 (12)
WalkthroughChangesXAxis automatic height
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant XAxisImpl
participant CartesianAxis
participant XAxisUtils
participant CartesianAxisSlice
XAxisImpl->>CartesianAxis: render axis and label refs
XAxisImpl->>CartesianAxis: request calculated height
CartesianAxis->>XAxisUtils: measure ticks and label
XAxisUtils-->>XAxisImpl: return rounded height
XAxisImpl->>CartesianAxisSlice: dispatch updateXAxisHeight
Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 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 14.39kB (0.25%) ⬆️. This is within the configured threshold ✅ Detailed changes
ℹ️ *Bundle size includes cached data from a previous commit Affected Assets, Files, and Routes:view changes for bundle: recharts/bundle-cjsAssets Changed:
view changes for bundle: recharts/bundle-treeshaking-treemapAssets Changed:
view changes for bundle: recharts/bundle-es6Assets Changed:
view changes for bundle: recharts/bundle-treeshaking-sankeyAssets Changed:
view changes for bundle: recharts/bundle-treeshaking-sunburstAssets Changed:
view changes for bundle: recharts/bundle-umdAssets Changed:
view changes for bundle: recharts/bundle-treeshaking-polarAssets Changed:
view changes for bundle: recharts/bundle-treeshaking-cartesianAssets Changed:
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #7570 +/- ##
==========================================
+ Coverage 88.20% 88.22% +0.02%
==========================================
Files 615 620 +5
Lines 14276 14443 +167
Branches 3591 3672 +81
==========================================
+ Hits 12592 12743 +151
- Misses 1494 1506 +12
- Partials 190 194 +4 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
Example on the website would be nice |
Fixes #7301.
Adds
height="auto"toXAxis, mirroring the existingYAxiswidth="auto"(#5880). When set, the axis height is measured from the rendered tick labels and axis label after layout, then dispatched back into the axis state, so rotated or multi-line tick labels are no longer clipped and don't need manualmargin.bottomtuning.The implementation mirrors the Y-axis path end to end:
getCalculatedXAxisHeightmeasures the tallest tick label plus tick size/margin and the axis label (analog ofgetCalculatedYAxisWidth).CartesianAxisexposesgetCalculatedHeight()on its ref.XAxisImplruns auseLayoutEffectthat dispatchesupdateXAxisHeightwhenheight === 'auto', with the same oscillation guard, and the same skips whenlabelis a function or a React element.heightis typednumber | 'auto'; the size and offset selectors fall back toDEFAULT_X_AXIS_HEIGHT(30) until measured, so the default behavior is unchanged.Tests
New
test/cartesian/XAxis/XAxis.autoHeight.spec.tsxcovers the fixed-height control case and the dynamic"auto"case (calculated height 88 = 80 tick + 6 tick size + 2 tick margin).Local checks:
tsc --noEmitclean, eslint clean, existing XAxis/YAxis/state suites (848 tests) still green.Summary by CodeRabbit
New Features
"auto"in addition to numeric values.Bug Fixes
Tests