jetpack icon indicating copy to clipboard operation
jetpack copied to clipboard

Charts-143: Add Sparkline chart component

Open annacmc opened this issue 2 months ago • 6 comments

Proposed changes:

  • Add new Sparkline chart component for inline trend visualization
  • Add display property to AxisOptions type for controlling axis visibility
  • Use existing gridVisibility prop for grid control
  • Sparkline provides a simplified API (number[] data) while using LineChart internally
  • Handle edge cases: empty data, single point (circle), negative values, flat lines
  • Support theme integration and responsive behavior via withResponsive HOC

Implementation Details:

Types changes:

  • New display?: boolean property in AxisOptions type (default: true) - controls individual axis rendering

LineChart changes:

  • Uses gridVisibility prop for grid control (already existed in BaseChartProps)
  • Uses options.axis.x.display and options.axis.y.display for axis control

Sparkline wrapper:

  • Transforms number[] to SeriesData[] format for LineChart
  • Preconfigures: gridVisibility="none", options.axis.x/y.display=false, withTooltips={false}, showLegend={false}
  • Uses monotone curve interpolation
  • Handles edge cases (empty data, single point) with custom rendering
image

Other information:

  • [x] Have you written new tests for your changes, if applicable?
  • [x] 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:

  • Go to Storybook -> JS Packages -> Charts -> Types -> Line Chart -> Sparkline
  • Test available stories:
    • Default: Basic sparkline with controls
    • Responsive: Container-based responsive sizing
    • Dashboard: Metric card integration example
    • EmptyData: Empty state handling
    • SinglePoint: Single point rendering (circle)
    • TwoPoints: Minimal line rendering
  • Test LineChart with minimal rendering:
    • Use gridVisibility="none" to hide grid
    • Use options={{ axis: { x: { display: false }, y: { display: false } } }} to hide axes

annacmc avatar Dec 02 '25 11:12 annacmc

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/new-chart-sparkline branch.
  • To test on Simple, run the following command on your sandbox:
bin/jetpack-downloader test jetpack add/new-chart-sparkline

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[bot] avatar Dec 02 '25 11:12 github-actions[bot]

Thank you for your PR!

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

  • :white_check_mark: Include a description of your PR changes.
  • :white_check_mark: Add a "[Status]" label (In Progress, Needs Review, ...).
  • :white_check_mark: Add a "[Type]" label (Bug, Enhancement, Janitorial, Task).
  • :white_check_mark: Add testing instructions.
  • :white_check_mark: Specify whether this PR includes any changes to data or privacy.
  • :white_check_mark: 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 :robot:


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[bot] avatar Dec 02 '25 11:12 github-actions[bot]

Code Coverage Summary

Coverage changed in 1 file.

File Coverage Δ% Δ Uncovered
projects/js-packages/charts/src/charts/line-chart/line-chart.tsx 136/141 (96.45%) 1.42% -2 💚

3 files are newly checked for coverage.

File Coverage
projects/js-packages/charts/src/charts/sparkline/sparkline.tsx 34/34 (100.00%) 💚
projects/js-packages/charts/src/charts/sparkline/index.ts 0/0 (—%) 🤷

Full summary · PHP report · JS report

jp-launch-control[bot] avatar Dec 02 '25 11:12 jp-launch-control[bot]

Thanks for the PR 🙂

I'm on support rotation this week so I'd like to review properly next week if possible.

One initial thought is that this looks a lot like a widget based on a LineChart (with no axes displayed), rather than a new primitive chart type. Did you consider that?

adamwoodnz avatar Dec 03 '25 20:12 adamwoodnz

Thanks that would be amazing if you have some space to look next week (either at this or I do have ~3 components I am attempting to add in this week) - I have considered a line chart widget, but put that idea down at the time when I pursued this direction, not for any great reason. You might be onto something here though I will definitely look into that possibility once more.

annacmc avatar Dec 03 '25 22:12 annacmc

OK I've had a bit of a play around - I've refactored Sparkline to use LineChart internally with new showAxes and showGrid props, so it's now a preconfigured variant rather than a separate primitive - what do you think of this approach @adamwoodnz ?

annacmc avatar Dec 03 '25 23:12 annacmc