-
Notifications
You must be signed in to change notification settings - Fork 839
Charts: Extract common legend container logic into shared helper #45630
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: trunk
Are you sure you want to change the base?
Charts: Extract common legend container logic into shared helper #45630
Conversation
|
Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.
Interested in more tips and information?
|
|
Thank you for your PR! When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:
This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖 Follow this PR Review Process:
If you have questions about anything, reach out in #jetpack-developers for guidance! |
Code Coverage SummaryCoverage changed in 2 files.
1 file is newly checked for coverage.
|
There was a problem hiding this 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 extracts duplicated legend positioning logic from multiple chart components into a shared helper hook and CSS module, improving code maintainability and consistency.
Key Changes:
- Created
useLegendLayouthook to centralize chart height and margin calculations for legend positioning - Added shared
chart-container.module.scssfor flex layout styling using BEM convention - Refactored 5 chart components to use the shared utilities, eliminating ~20 lines of duplicated code
Reviewed Changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| chart-container.module.scss | New shared CSS module defining flex layout classes for legend positioning |
| use-legend-layout.ts | New hook that calculates adjusted chart height, margin, and container class based on legend position |
| hooks/index.ts | Exports the new useLegendLayout hook |
| pie-semi-circle-chart.tsx | Refactored to use shared hook and CSS classes instead of inline styles |
| pie-chart.tsx | Refactored to use shared hook and CSS classes instead of inline styles |
| line-chart.tsx | Refactored to use shared hook and CSS classes instead of inline styles |
| leaderboard-chart.tsx | Refactored to use shared CSS classes for container layout |
| bar-chart.tsx | Refactored to use shared hook and CSS classes instead of inline styles |
| bar-chart.module.scss | Updated class name to use BEM convention and removed redundant display/flex-direction properties |
| changelog | Added changelog entry for this refactoring |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Copilot reviewed 10 out of 10 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
projects/js-packages/charts/src/components/pie-semi-circle-chart/pie-semi-circle-chart.tsx
Outdated
Show resolved
Hide resolved
projects/js-packages/charts/src/components/pie-chart/pie-chart.tsx
Outdated
Show resolved
Hide resolved
…as required properties
Proposed changes:
chart-container.module.scss) for chart container flex layout using BEM conventionuseLegendLayouthook to centralize chart height and margin adjustment calculations for legend positioninguseLegendLayoutfrom hooks indexThis refactoring eliminates ~20 lines of duplicated legend positioning logic across 5 chart components, improving maintainability and ensuring consistent behavior.
Other information:
Does this pull request change what data or activity we track or use?
No, it does not.
Testing instructions:
Automated Tests
pnpm test- all 530 tests should passpnpm lint- no linting errors should be presentManual Testing - Legend Positioning
For each chart type (BarChart, LineChart, PieChart, PieSemiCircleChart, LeaderboardChart):
Test Bottom Legend (default):
showLegend={true}andlegendPosition="bottom"Test Top Legend:
showLegend={true}andlegendPosition="top"column-reverseflex direction)Test No Legend:
showLegend={false}Visual Regression Testing