Charts: Standardize Legend stories and documentation#47545
Charts: Standardize Legend stories and documentation#47545adamwoodnz wants to merge 5 commits intotrunkfrom
Conversation
|
Cursor Agent can help with this pull request. Just |
|
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! |
|
@cursoragent fix the lint issues please |
Code Coverage SummaryThis PR did not change code coverage! That could be good or bad, depending on the situation. Everything covered before, and still is? Great! Nothing was covered before? Not so great. 🤷 |
… types CHARTS-183: Standardize legend stories to exactly two per chart type (WithLegend and WithCompositionLegend) and update Legend component docs to use composition API as the primary integration example. Story changes per chart: - BarChart: Replace WithInteractiveLegend with WithLegend, remove CustomLegendPositioning - LineChart: Replace WithInteractiveLegend with WithLegend, remove CustomLegendPositioning - PieChart: Remove InteractiveLegend and CustomLegendPositioning - Donut: Remove InteractiveLegend, CustomLegendPositioning, and CustomLegend - PieSemiCircleChart: Remove InteractiveLegend and CustomLegendPositioning - LeaderboardChart: Remove CustomLegendLabels and InteractiveLegend Documentation changes: - Update Legend docs Integration with Charts section to lead with composition API pattern - Update overview code example to show composition API first - Update interactive legend docs to show composition approach - Update Legend component stories to use composition API for chart integration examples (WithLineChart, WithBarChart) - Add consistent descriptions to all WithLegend and WithCompositionLegend stories Co-authored-by: Adam Wood <adamwoodnz@users.noreply.github.com>
Co-authored-by: Adam Wood <adamwoodnz@users.noreply.github.com>
abe592a to
2135f5a
Compare
WithCompositionLegend stories were passing legend config only to the
child Legend component, not the parent chart. This meant toggling
legendInteractive in Storybook rendered toggle buttons but the chart
never filtered series visibility.
Pass legend={ { interactive } } to the parent chart in all six
composition stories (bar, line, pie, donut, semi-circle, leaderboard).
The narrowed object avoids ChartLegendConfig<T> type mismatches.
Refs: CHARTS-187
The CustomLegend story demonstrates the render prop API for fully custom legend layouts — a pattern not covered by the standardized WithLegend/WithCompositionLegend stories.
|
@claude review please |
|
Claude finished @adamwoodnz's task in 2m 11s —— View job PR Review
Overall: Clean, well-executed standardization. The CHARTS-187 fix is correctly implemented across all charts. A few minor nits below. CHARTS-187 Fix: Legend InteractivityThe core fix is correct and consistent: all Minor Issues1. Missing
|
There was a problem hiding this comment.
Pull request overview
This PR standardizes legend stories across all chart types (BarChart, LineChart, PieChart, Donut, PieSemiCircleChart, LeaderboardChart) to a consistent WithLegend/WithCompositionLegend pattern, removes redundant stories, updates Legend documentation to prioritize the composition API, and fixes composition legend interactivity by wiring legend.interactive to the parent chart.
Changes:
- Consolidated legend stories to two per chart (
WithLegendfor props-based,WithCompositionLegendfor composition API), removingWithInteractiveLegend,CustomLegendPositioning, etc. - Fixed
WithCompositionLegendstories by passinglegend={ { interactive: legend?.interactive } }to the parent chart so interactivity toggling works. - Updated Legend documentation to recommend composition API as the primary integration pattern.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
charts/src/components/legend/stories/index.stories.tsx |
Replaced hook-based chart stories with composition API examples |
charts/src/components/legend/stories/index.docs.mdx |
Rewritten to prioritize composition API, removed hook-based examples |
charts/src/charts/pie-semi-circle-chart/stories/index.stories.tsx |
Standardized to WithLegend/WithCompositionLegend, removed redundant stories |
charts/src/charts/pie-chart/stories/index.stories.tsx |
Standardized to WithLegend/WithCompositionLegend, removed redundant stories |
charts/src/charts/pie-chart/stories/donut.stories.tsx |
Standardized to WithLegend/WithCompositionLegend, removed redundant stories |
charts/src/charts/line-chart/stories/index.stories.tsx |
Standardized to WithLegend/WithCompositionLegend, removed redundant stories |
charts/src/charts/leaderboard-chart/stories/index.stories.tsx |
Standardized to WithLegend/WithCompositionLegend, removed redundant stories |
charts/src/charts/bar-chart/stories/index.stories.tsx |
Standardized to WithLegend/WithCompositionLegend, removed redundant stories |
charts/changelog/CHARTS-183-legend-stories-and-documentation |
Changelog entry |
Add explicit args to BarChart and LineChart WithCompositionLegend stories so Storybook Controls panel shows initialized values, matching the pattern used by all other chart composition stories. Remove redundant orientation="horizontal" from legend stories and docs Source blocks since horizontal is already the default.


Fixes CHARTS-183: Standardize legend stories and docs
Fixes CHARTS-187: Fix composition legend interactivity in WithCompositionLegend stories
Proposed changes
WithLegend(props-based) andWithCompositionLegend(composition API).WithInteractiveLegend,CustomLegendPositioning) as their functionality is now covered by the standardized stories and shared controls.CustomLegenddonut story — it demonstrates the render prop API, a distinct pattern not covered by the standard two.Legendcomponent documentation (index.docs.mdx) to prioritize composition API examples for chart integration.Legendcomponent stories (index.stories.tsx) to include composition examples.orientation="horizontal"from stories and docs Source blocks where it matched the default.WithCompositionLegendstories not wiringlegend.interactiveto the parent chart component, so toggling interactivity in Storybook now correctly filters series visibility (CHARTS-187).argsto BarChart and LineChartWithCompositionLegendstories so Storybook Controls panel shows initialized values.Other information
Related product discussion/links
Does this pull request change what data or activity we track or use?
No.
Testing instructions
WithCompositionLegendstory, enable thelegendInteractivecontrol.Legendcomponent documentation in Storybook (/charts/?path=/docs/components-legend--docs).CustomLegendstory renders with the custom render prop layout (grid with formatted values and comparison deltas).Linear Issues: CHARTS-183, CHARTS-187