Charts: Improve TimeSeriesForecastChart with composition pattern and legend props#46845
Charts: Improve TimeSeriesForecastChart with composition pattern and legend props#46845annacmc wants to merge 36 commits intoadd/time-series-forecast-chart-docsfrom
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 SummaryNo summary data is available for parent commit be4a64d, so cannot calculate coverage changes. 😴 If that commit is a feature branch rather than a trunk commit, this is expected. Otherwise, this should be updated once coverage for be4a64d is available. Full summary · PHP report · JS report Coverage check overridden by
Coverage tests to be added later
|
767b628 to
6c926a5
Compare
…into add/area-chart-component # Conflicts: # projects/js-packages/charts/src/charts/time-series-forecast-chart/private/use-forecast-data.ts # projects/js-packages/charts/src/charts/time-series-forecast-chart/stories/config.tsx # projects/js-packages/charts/src/charts/time-series-forecast-chart/time-series-forecast-chart.module.scss # projects/js-packages/charts/src/charts/time-series-forecast-chart/time-series-forecast-chart.tsx # projects/js-packages/charts/src/charts/time-series-forecast-chart/types.ts
There was a problem hiding this comment.
Pull request overview
This PR enhances TimeSeriesForecastChart by expanding legend customization options, adding a compound composition API for extensibility, and integrating chart registration/i18n improvements for dashboard usage.
Changes:
- Add compound composition support (
.SVG,.HTML, and.Legend) and introduceSingleChartContextusage. - Add legend prop parity (orientation, alignment, max width, text overflow, item class, shape).
- Add i18n defaults for series labels and register chart metadata via
useChartRegistration.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| projects/js-packages/charts/src/charts/time-series-forecast-chart/types.ts | Extends public props with legend customization options and children for compound composition. |
| projects/js-packages/charts/src/charts/time-series-forecast-chart/time-series-forecast-chart.tsx | Implements composition API + legend prop pass-through, adds i18n defaults, and registers chart metadata. |
| projects/js-packages/charts/src/charts/time-series-forecast-chart/private/use-forecast-data.ts | Adjusts forecast split comment and changes y-domain calculation behavior. |
| projects/js-packages/charts/changelog/add-area-chart-component | Adds a changelog entry for the new composition + legend API behavior. |
| const TimeSeriesForecastChart = attachSubComponents( | ||
| withResponsive< TimeSeriesForecastChartProps< unknown > >( | ||
| TimeSeriesForecastChartWithProvider as FC< TimeSeriesForecastChartProps< unknown > > | ||
| ), | ||
| { | ||
| Legend, | ||
| SVG: ChartSVG, | ||
| HTML: ChartHTML, | ||
| } |
There was a problem hiding this comment.
The composition API attaches Legend, SVG, and HTML subcomponents, but the PR description/testing instructions mention a TimeSeriesForecastChart.Tooltip compound subcomponent. Either expose a Tooltip subcomponent here (and handle it via useChartChildren similarly to other compound parts) or update the PR description to match what’s actually shipped.
| // Add some padding to y domain (ensure minimum padding to avoid zero-height scales) | ||
| const yPadding = Math.max( ( maxY - minY ) * 0.1, 1 ); | ||
| const yDomain: [ number, number ] = [ minY - yPadding, maxY + yPadding ]; | ||
| const yDomain: [ number, number ] = [ Math.max( 0, minY - yPadding ), maxY + yPadding ]; |
There was a problem hiding this comment.
Clamping the lower yDomain bound to 0 will break charts that legitimately contain negative values (they’ll be rendered off-scale). If the intent is only to prevent padding from pushing an all-positive series below zero, clamp conditionally (e.g., only clamp when minY >= 0), otherwise preserve negative ranges.
| const yDomain: [ number, number ] = [ Math.max( 0, minY - yPadding ), maxY + yPadding ]; | |
| const yMinWithPadding = minY - yPadding; | |
| const yDomain: [ number, number ] = [ | |
| minY >= 0 ? Math.max( 0, yMinWithPadding ) : yMinWithPadding, | |
| maxY + yPadding, | |
| ]; |
| Significance: minor | ||
| Type: added | ||
|
|
||
| TimeSeriesForecastChart: add compound composition pattern and full legend prop parity |
There was a problem hiding this comment.
Changelog entry doesn’t follow the repo’s changelog conventions: it should be user-facing, use imperative mood, start with a capital letter, and end with a period. Consider adjusting to something like “TimeSeriesForecastChart: Add compound composition pattern and full legend prop parity.”
| TimeSeriesForecastChart: add compound composition pattern and full legend prop parity | |
| TimeSeriesForecastChart: Add compound composition pattern and full legend prop parity. |
| </XYChart> | ||
|
|
||
| { /* Render SVG children from TimeSeriesForecastChart.SVG */ } | ||
| { svgChildren } | ||
|
|
There was a problem hiding this comment.
svgChildren extracted from TimeSeriesForecastChart.SVG are rendered outside of XYChart, but useChartChildren/ChartSVG are documented as content that should be rendered inside the chart’s SVG. As-is, SVG nodes like <g>, <line>, etc. will end up in the HTML flow (or be invalid) instead of inside the VisX SVG. Move the { svgChildren } rendering into the XYChart children tree (e.g., after the series/divider) so it renders within the chart SVG/context.
| </XYChart> | |
| { /* Render SVG children from TimeSeriesForecastChart.SVG */ } | |
| { svgChildren } | |
| { /* Render SVG children from TimeSeriesForecastChart.SVG */ } | |
| { svgChildren } | |
| </XYChart> |
bc9caef to
5ec636d
Compare
…t-component # Conflicts: # projects/js-packages/charts/src/charts/time-series-forecast-chart/private/use-forecast-data.ts # projects/js-packages/charts/src/charts/time-series-forecast-chart/time-series-forecast-chart.module.scss # projects/js-packages/charts/src/charts/time-series-forecast-chart/time-series-forecast-chart.tsx # projects/js-packages/charts/src/charts/time-series-forecast-chart/types.ts
Proposed changes:
showLegend,legendOrientation,legendValueDisplay, etc.)useChartRegistrationhook for dashboard integrationdisplayNameto component for better debugginguseChartLegendItemsimportxAxisTickFormatwrapperOther information:
Does this pull request change what data or activity we track or use?
No, it does not.
Testing instructions:
TimeSeriesForecastChart.Legend,TimeSeriesForecastChart.SVG,TimeSeriesForecastChart.HTMLsubcomponentsshowLegend: Toggle legend visibilitylegendOrientation: Test 'horizontal' and 'vertical' layoutslegendValueDisplay: Test 'percentage', 'value', 'valueDisplay', 'none' options