Charts: Make PieSemiCircleChart responsive by default#47312
Charts: Make PieSemiCircleChart responsive by default#47312adamwoodnz merged 10 commits intotrunkfrom
Conversation
…ments. Update BarChart, LineChart, and PieChart interfaces to include the new prop, and reflect this change in their respective documentation. Remove redundant gap prop definitions from the interfaces.
The chart previously hardcoded a 400px width and derived height by subtracting legend height from the chart area. This caused incorrect sizing when the container had height constraints or the legend position changed. The chart now fills its parent container and measures the available SVG wrapper area to maintain a 2:1 width-to-height ratio, constrained by both available width and height. Explicit width/height props override the responsive behavior. - Replace fixed width default with responsive container measurement - Use @wordpress/ui Stack for gap spacing between chart elements - Add configurable gap prop using design system tokens - Wrap SVG in a flex measurement div for accurate sizing Co-authored-by: Cursor <cursoragent@cursor.com>
|
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! |
There was a problem hiding this comment.
Pull request overview
This PR makes PieSemiCircleChart responsive by default, so it fills its parent container when no explicit dimensions are provided, while preserving a strict 2:1 width-to-height ratio based on available space. It also standardizes inter-element spacing via a shared gap prop and updates Storybook/docs/tests accordingly.
Changes:
- Implement responsive-by-default sizing for
PieSemiCircleChartusing measured available space and a constrained 2:1 ratio. - Replace the legend layout hack with
@wordpress/uiStack, and introduce a sharedgapprop onBaseChartProps. - Update Storybook stories/docs and adjust unit tests for the new responsive behavior.
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| projects/js-packages/charts/src/types.ts | Adds shared gap prop to BaseChartProps so charts can use a consistent spacing API. |
| projects/js-packages/charts/src/charts/pie-semi-circle-chart/test/pie-semi-circle-chart.test.tsx | Updates tests to reflect responsive-by-default behavior and constrained sizing. |
| projects/js-packages/charts/src/charts/pie-semi-circle-chart/stories/index.stories.tsx | Updates default story to be responsive and adds a fixed-dimensions story using the unresponsive export. |
| projects/js-packages/charts/src/charts/pie-semi-circle-chart/stories/index.api.mdx | Updates API docs for responsive width behavior and documents the new gap prop. |
| projects/js-packages/charts/src/charts/pie-semi-circle-chart/pie-semi-circle-chart.tsx | Implements measured sizing, 2:1 constraint logic, and Stack-based layout with configurable gap. |
| projects/js-packages/charts/src/charts/pie-semi-circle-chart/pie-semi-circle-chart.module.scss | Adds responsive/container-filling styles and an SVG wrapper that can be measured and flexed. |
| projects/js-packages/charts/src/charts/pie-chart/pie-chart.tsx | Removes duplicated gap typing now that it’s in BaseChartProps. |
| projects/js-packages/charts/src/charts/line-chart/types.ts | Removes duplicated gap typing now that it’s in BaseChartProps. |
| projects/js-packages/charts/src/charts/line-chart/stories/index.api.mdx | Documents gap for LineChart API. |
| projects/js-packages/charts/src/charts/bar-chart/stories/index.api.mdx | Documents gap for BarChart API. |
| projects/js-packages/charts/src/charts/bar-chart/bar-chart.tsx | Removes duplicated gap typing now that it’s in BaseChartProps. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
projects/js-packages/charts/src/charts/pie-semi-circle-chart/pie-semi-circle-chart.tsx
Outdated
Show resolved
Hide resolved
projects/js-packages/charts/src/charts/pie-semi-circle-chart/stories/index.api.mdx
Outdated
Show resolved
Hide resolved
…onsive fix Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
858a52d to
3ce083e
Compare
Correct docs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Code Coverage SummaryCoverage changed in 1 file.
|
The invalid-data render path hardcoded width and ignored propHeight, so the error SVG could overflow a height-constrained container. Apply the same 2:1 aspect-ratio constraint used by the valid chart. Co-authored-by: Cursor <cursoragent@cursor.com>
Stories were still using fixed widths and container overrides from the old sizing model. Now that the chart is responsive by default, most stories no longer need explicit width/containerWidth props. - Add height range control to Storybook argTypes - Remove redundant Responsiveness story (all stories are responsive) - Simplify composition and interactive legend examples - Use height prop instead of width where a size constraint is needed Co-authored-by: Cursor <cursoragent@cursor.com>
The flex/column properties are now handled by the Stack component, and margin declarations have no effect on SVG <Text> elements. Co-authored-by: Cursor <cursoragent@cursor.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 13 out of 13 changed files in this pull request and generated 4 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
...ects/js-packages/charts/src/charts/pie-semi-circle-chart/test/pie-semi-circle-chart.test.tsx
Show resolved
Hide resolved
...ects/js-packages/charts/src/charts/pie-semi-circle-chart/test/pie-semi-circle-chart.test.tsx
Show resolved
Hide resolved
...ects/js-packages/charts/src/charts/pie-semi-circle-chart/test/pie-semi-circle-chart.test.tsx
Show resolved
Hide resolved
projects/js-packages/charts/src/charts/pie-semi-circle-chart/pie-semi-circle-chart.tsx
Outdated
Show resolved
Hide resolved
The error-state SVG ignored an explicit height prop, always defaulting to 400px width regardless. When only propHeight was provided (e.g. 400), the error rendered at 400×200 instead of the expected 800×400. Extracts the repeated `propWidth || 400` fallback into a DEFAULT_WIDTH constant and effectiveWidth variable, then reworks the error-state calculation so an explicit height correctly derives width via the 2:1 aspect ratio. Co-authored-by: Cursor <cursoragent@cursor.com>
The docs described responsive as opt-in ("omit width to be
responsive") when the chart is now responsive by default. This
was inconsistent with line, bar, and pie chart docs which all
frame it as "fills parent container, use width/height to
constrain."
Rewrites the responsive section to match the shared pattern,
fixes Source blocks to match their Canvas stories, adds the
missing height prop to the API reference, and fixes a broken
Responsiveness story reference.
Co-authored-by: Cursor <cursoragent@cursor.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 14 out of 14 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| } } | ||
| > | ||
| <div | ||
| <Stack |
Fixes: https://linear.app/a8c/issue/CHARTS-169
Summary
This PR is one in a series that make chart components responsive by default, so they fill their parent container without requiring explicit dimensions.
The PR applies the same pattern used for Line, Bar and Pie charts to the
PieSemiCircleChart. It also standardises thegapprop across all chart types and aligns the Storybook docs with the responsive-by-default conventions established in the earlier PRs.Proposed changes:
PieSemiCircleChartresponsive by default — fills its parent container when no explicitwidth/heightis provideduseElementSizeon the SVG wrapperwidthand/orheightprops (e.g.height={400}correctly deriveswidth=800)@wordpress/uiStackfor layout; add configurablegappropgapprop to sharedBaseChartPropsand remove duplicateGapSizeimports fromBarChart,LineChart, andPieChartwidth/heightare constraints, not enablers<Source>code blocks in docs to match their<Canvas>stories (data, props, responsive defaults)Responsivenessstory reference in docs; addFixedDimensionsCanvasheightprop to the API referenceResponsivenessstory, drop hardcodedwidth/containerWidthprops, addheightcontrol and fixed-dimensions storyOther information:
Testing instructions:
cd projects/js-packages/charts && pnpm storybookPieSemiCircleChartstoriestopandbottompositionscd projects/js-packages/charts && pnpm testChangelog
See
projects/js-packages/charts/changelog/charts-169-fix-chart-height-and-size-calculation-for-pie-semi-circle-chartDoes this pull request change what data or activity we track or use?
No. This PR only changes how
PieSemiCircleChartcalculates and renders its dimensions — no data collection, tracking, or analytics are added or modified.