Skip to content

Charts: Add TimeSeriesForecastChart component#46844

Open
annacmc wants to merge 18 commits intotrunkfrom
add/time-series-forecast-chart
Open

Charts: Add TimeSeriesForecastChart component#46844
annacmc wants to merge 18 commits intotrunkfrom
add/time-series-forecast-chart

Conversation

@annacmc
Copy link
Contributor

@annacmc annacmc commented Jan 29, 2026

Related: CHARTS-145

Note: Testes & Docs added for this in followup #47152

Proposed changes:

  • Add new TimeSeriesForecastChart component for visualizing time series data with forecast periods
  • Add type definitions for forecast chart props and data structures
  • Add useForecastData hook for splitting data into historical and forecast segments
  • Add ForecastDivider component to visually separate historical from forecast data
  • Add SCSS styles for forecast-specific visual treatments (dashed lines, opacity changes)
  • Export component and types from the charts package
  • Add comprehensive Storybook stories demonstrating various configurations

Other information:

  • Have you written new tests for your changes, if applicable?
  • Have you checked the E2E test CI results, and verified that your changes do not break them?
  • Have you tested your changes on WordPress.com, if applicable (if so, you'll see a generated comment below with a script to run)?

Does this pull request change what data or activity we track or use?

No, it does not.

Testing instructions:

  • Checkout add/time-series-forecast-chart branch
  • Navigate to /jetpack/projects/js-packages/storybook
  • Run pnpm run storybook:dev
  • It will tell you which port it's running on, eg. http://localhost:50240/ and it should also auto load storybook into your browser
  • Go to Storybook -> Charts -> Types -> Time Series Forecast Chart
  • Verify the chart renders with both historical (solid) and forecast (dashed) line segments
  • Test the forecast divider appears at the correct date boundary
  • Test with different forecastStartDate values to ensure proper data splitting
  • Verify legend displays both "Historical" and "Forecast" series
  • Test responsive behavior at various container widths
  • Verify tooltips work correctly for both historical and forecast data points
  • Ensure no TypeScript errors in the component or stories

Copilot AI review requested due to automatic review settings January 29, 2026 23:17
@annacmc annacmc added the [Status] Needs Review This PR is ready for review. label Jan 29, 2026
@annacmc annacmc self-assigned this Jan 29, 2026
@github-actions
Copy link
Contributor

github-actions bot commented Jan 29, 2026

Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.

  • To test on WoA, go to the Plugins menu on a WoA dev site. Click on the "Upload" button and follow the upgrade flow to be able to upload, install, and activate the Jetpack Beta plugin. Once the plugin is active, go to Jetpack > Jetpack Beta, select your plugin (Jetpack), and enable the add/time-series-forecast-chart branch.
  • To test on Simple, run the following command on your sandbox:
bin/jetpack-downloader test jetpack add/time-series-forecast-chart

Interested in more tips and information?

  • In your local development environment, use the jetpack rsync command to sync your changes to a WoA dev blog.
  • Read more about our development workflow here: PCYsg-eg0-p2
  • Figure out when your changes will be shipped to customers here: PCYsg-eg5-p2

@github-actions
Copy link
Contributor

github-actions bot commented Jan 29, 2026

Thank you for your PR!

When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:

  • ✅ Include a description of your PR changes.
  • ✅ Add a "[Status]" label (In Progress, Needs Review, ...).
  • ✅ Add testing instructions.
  • ✅ Specify whether this PR includes any changes to data or privacy.
  • ✅ Add changelog entries to affected projects

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:

  1. Ensure all required checks appearing at the bottom of this PR are passing.
  2. Make sure to test your changes on all platforms that it applies to. You're responsible for the quality of the code you ship.
  3. You can use GitHub's Reviewers functionality to request a review.
  4. When it's reviewed and merged, you will be pinged in Slack to deploy the changes to WordPress.com simple once the build is done.

If you have questions about anything, reach out in #jetpack-developers for guidance!

@github-actions github-actions bot added [JS Package] Charts RNA [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. and removed [Status] Needs Review This PR is ready for review. labels Jan 29, 2026
Copy link
Contributor

Copilot AI left a 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 adds a new TimeSeriesForecastChart component to the charts package for visualizing time series data with forecast periods and uncertainty bands. The component provides a generic, type-safe way to display historical data alongside forecasted values with optional confidence intervals.

Changes:

  • New chart component with support for historical and forecast data visualization
  • Data transformation hook to split and process time series data
  • Comprehensive Storybook stories demonstrating various use cases
  • Package exports configuration for the new component

Reviewed changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
projects/js-packages/charts/src/index.ts Exports the new TimeSeriesForecastChart component and its types
projects/js-packages/charts/src/charts/time-series-forecast-chart/types.ts Type definitions for the component including props, accessors, and data structures
projects/js-packages/charts/src/charts/time-series-forecast-chart/time-series-forecast-chart.tsx Main component implementation with responsive wrapper
projects/js-packages/charts/src/charts/time-series-forecast-chart/time-series-forecast-chart.module.scss Component styling including tooltip, legend, and animation styles
projects/js-packages/charts/src/charts/time-series-forecast-chart/stories/index.stories.tsx Storybook stories showcasing different configurations and use cases
projects/js-packages/charts/src/charts/time-series-forecast-chart/stories/config.tsx Story configuration, sample data, and helper functions
projects/js-packages/charts/src/charts/time-series-forecast-chart/private/use-forecast-data.ts Data transformation hook that splits data into historical/forecast portions
projects/js-packages/charts/src/charts/time-series-forecast-chart/private/index.ts Internal exports for private utilities
projects/js-packages/charts/src/charts/time-series-forecast-chart/private/forecast-divider.tsx Visual divider component marking the forecast start point
projects/js-packages/charts/src/charts/time-series-forecast-chart/index.ts Public exports for the chart component and types
projects/js-packages/charts/package.json Package exports configuration for the new component
projects/js-packages/charts/changelog/add-time-series-forecast-chart Changelog entry documenting the new feature

@jp-launch-control
Copy link

jp-launch-control bot commented Jan 29, 2026

Code Coverage Summary

6 files are newly checked for coverage. Only the first 5 are listed here.

File Coverage
projects/js-packages/charts/src/charts/time-series-forecast-chart/private/forecast-divider.tsx 0/10 (0.00%) 💔
projects/js-packages/charts/src/charts/time-series-forecast-chart/private/use-forecast-data.ts 0/27 (0.00%) 💔
projects/js-packages/charts/src/charts/time-series-forecast-chart/time-series-forecast-chart.tsx 0/70 (0.00%) 💔
projects/js-packages/charts/src/charts/time-series-forecast-chart/index.ts 0/0 (—%) 🤷

Full summary · PHP report · JS report

Coverage check overridden by Coverage tests to be added later Use to ignore the Code coverage requirement check when tests will be added in a follow-up PR .

@annacmc annacmc changed the title Add TimeSeriesForecastChart component Charts: Add TimeSeriesForecastChart component Jan 30, 2026
@annacmc annacmc added the Enhancement Changes to an existing feature — removing, adding, or changing parts of it label Jan 30, 2026
@annacmc annacmc marked this pull request as draft January 30, 2026 00:38
@annacmc annacmc removed the [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. label Jan 30, 2026
@github-actions github-actions bot added [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. [Status] In Progress labels Jan 30, 2026
@annacmc annacmc added the Coverage tests to be added later Use to ignore the Code coverage requirement check when tests will be added in a follow-up PR label Jan 30, 2026
@annacmc annacmc force-pushed the add/time-series-forecast-chart branch from 767b628 to 6c926a5 Compare January 30, 2026 02:15
@annacmc annacmc requested a review from Copilot January 30, 2026 02:16
Copy link
Contributor

Copilot AI left a 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 12 out of 12 changed files in this pull request and generated 3 comments.

Copy link
Contributor

Copilot AI left a 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 12 out of 12 changed files in this pull request and generated 1 comment.

@annacmc annacmc force-pushed the add/time-series-forecast-chart branch from bc9caef to 5ec636d Compare February 17, 2026 02:58
@annacmc annacmc requested a review from adamwoodnz February 17, 2026 03:07
@annacmc
Copy link
Contributor Author

annacmc commented Feb 17, 2026

Thanks so much for taking a look @adamwoodnz ! I have addressed your comments inline.

It would be great to have some docs generated as part of this, and an API reference. I know you have a follow up PR in progress but I don't see docs in that either

Yep totally. I think this PR (and the followup) are just a bit big, so creating another PR right now to generate docs + API reference.

That PR is here: #47152

Comment on lines +132 to +139
const { color: bandColor } = getElementStyles( {
index: 1,
data: { group: 'primary', label: seriesKeys.band, data: [] },
} );
const { lineStyles: forecastLineStyles, shapeStyles: forecastShapeStyles } = getElementStyles( {
index: 1,
data: { group: 'primary', label: seriesKeys.forecast, data: [], options: {} },
} );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these could be combined? Not sure if the label makes any difference...

Suggested change
const { color: bandColor } = getElementStyles( {
index: 1,
data: { group: 'primary', label: seriesKeys.band, data: [] },
} );
const { lineStyles: forecastLineStyles, shapeStyles: forecastShapeStyles } = getElementStyles( {
index: 1,
data: { group: 'primary', label: seriesKeys.forecast, data: [], options: {} },
} );
const { color: bandColor, lineStyles: forecastLineStyles, shapeStyles: forecastShapeStyles } = getElementStyles( {
index: 1,
data: { group: 'primary', label: seriesKeys.band, data: [] },
} );

Comment on lines +141 to +149
// Create mock series data for theme hook
const mockSeriesData = useMemo(
() => [
{ label: seriesKeys.historical, data: [] },
{ label: seriesKeys.forecast, data: [] },
],
[ seriesKeys ]
);
const theme = useXYChartTheme( mockSeriesData );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

Code smell - why do we need a mock in production code?

@adamwoodnz
Copy link
Contributor

The tooltip box shadow needs to fade to transparent, it's currently fading to white, which is visible over the background and chart elements

Comment on lines +173 to +185
export const CustomYDomain: StoryObj< StoryArgs > = Template.bind( {} );
CustomYDomain.args = {
...timeSeriesForecastChartStoryArgs,
yDomain: [ 0, 200 ],
};

CustomYDomain.parameters = {
docs: {
description: {
story: 'Override the auto-calculated Y domain with a fixed range using the yDomain prop.',
},
},
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This story displays exactly the same as the Default story. I see the instruction to alter the yDomain prop, but I think it should be set differently from Default, otherwise it's not clear what effect it has.

story: 'Different grid visibility options: y (default), x, xy, or none.',
},
},
},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Best to make the container taller for this so that the story isn't cut off

Suggested change
},
},
args: {
containerHeight: 600,
},

Image

Comment on lines +379 to +381
'The chart supports generic data types via accessor functions. ' +
'This example uses a custom datum shape with timestamp (number) instead of Date, ' +
'and differently named fields for values and bounds.',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this being concatenated?

/**
* Legend at Top
*/
export const LegendAtTop: StoryObj< StoryArgs > = Template.bind( {} );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Vertical legend orientation doesn't seem to work

Image

}

svg {
overflow: visible;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this for tooltips?

/**
* Main component props (generic over datum type D)
*/
export interface TimeSeriesForecastChartProps< D > {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should extend BaseChartProps like other charts

Comment on lines +95 to +96
const providerTheme = useGlobalChartsTheme();
const { getElementStyles } = useGlobalChartsContext();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const providerTheme = useGlobalChartsTheme();
const { getElementStyles } = useGlobalChartsContext();
const { getElementStyles, theme: providerTheme } = useGlobalChartsContext();

Copy link
Contributor

@adamwoodnz adamwoodnz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Second pass done 🙂

A bit of cleanup to do. The only major is the resizing behaviour still isn't right.

kangzj

This comment was marked as duplicate.

@kangzj
Copy link
Contributor

kangzj commented Mar 2, 2026

Screenshots from Visual Testing

1. Default Story

Chart renders with historical (solid line) and forecast (dashed line) segments:

01-default-story

2. With Legend

Legend displays "Historical" and "Forecast" series labels:

02-with-legend

3. Fixed Dimensions

Chart respects explicit width/height props (600x300):

03-fixed-dimensions

4. Empty Data

Proper handling with "No data available" message:

04-empty-data

5. Tooltip Functionality

Tooltips work correctly across all data points:

05-tooltip

@adamwoodnz
Copy link
Contributor

Noting that we have a shared ChartLayout component for charts which support legends now, see #47554

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Coverage tests to be added later Use to ignore the Code coverage requirement check when tests will be added in a follow-up PR Enhancement Changes to an existing feature — removing, adding, or changing parts of it [JS Package] Charts RNA [Status] In Progress [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants