Skip to content

Conversation

annacmc
Copy link
Contributor

@annacmc annacmc commented Sep 24, 2025

Proposed changes:

  • Add legendMargin prop to BaseLegendProps interface to allow custom margin spacing around legends
  • Add legendStyle prop to BaseLegendProps interface to enable custom CSS styling of legend containers
  • Update BaseLegend component to apply both margin and style props to the legend wrapper
  • Add Storybook controls for both legendMargin and legendStyle props in legend configuration

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:

  • Go to Storybook -> Charts -> Legend Configuration
  • Use the legendMargin control to test different margin values:
    • Test with number values like 8, 16, 24 for uniform margins
    • Test with object values like {top: 10, right: 15, bottom: 10, left: 15} for custom margins
    • Verify margins are applied correctly around legend containers
  • Use the legendStyle control to test custom styling:
    • Test background colors: {backgroundColor: '#f0f0f0'}
    • Test borders: {border: '1px solid #ccc'}
    • Test padding: {padding: '8px'}
    • Test combinations of multiple style properties
  • Verify that both props work independently and together
  • Test across different chart types (Pie, Bar, Line) to ensure consistent legend styling
  • Confirm no TypeScript errors and proper prop type validation
  • Ensure backward compatibility - existing charts without these props should render unchanged
  • Verify no visual regressions in chart rendering, tooltips, or other legend functionality
image

@annacmc annacmc self-assigned this Sep 24, 2025
@annacmc annacmc added [Type] Enhancement Changes to an existing feature — removing, adding, or changing parts of it [Status] In Progress labels Sep 24, 2025
Copy link
Contributor

github-actions bot commented Sep 24, 2025

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 charts-103-add-legend-margin-and-styling-customization-props branch.
  • To test on Simple, run the following command on your sandbox:
bin/jetpack-downloader test jetpack charts-103-add-legend-margin-and-styling-customization-props

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

Copy link
Contributor

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 a "[Type]" label (Bug, Enhancement, Janitorial, Task).
  • ✅ 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!

@annacmc annacmc requested a review from Copilot September 24, 2025 07:55
Copy link
Contributor

@Copilot 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 customization options for legend appearance by introducing two new props: legendMargin for controlling margin spacing and legendStyle for custom CSS styling of legend containers.

  • Add legendMargin and legendStyle props to BaseLegendProps interface with proper TypeScript definitions
  • Update BaseLegend component to apply margin and style props to legend wrapper elements
  • Include comprehensive test coverage and Storybook controls for the new functionality

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
types.ts Adds TypeScript definitions for legendMargin and legendStyle props with JSDoc documentation
base-legend.tsx Implements the new props by applying margin and style to legend container
legend.test.tsx Adds comprehensive test cases for margin, styling, and their combination
legend-config.tsx Adds Storybook controls for legendMargin with descriptive documentation
changelog Documents the feature addition with minor significance

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

…rgin-and-styling-customization-props

Co-authored-by: Copilot <[email protected]>
Copy link

jp-launch-control bot commented Sep 24, 2025

Code Coverage Summary

2 files are newly checked for coverage.

File Coverage
projects/js-packages/charts/src/components/legend/utils/process-legend-margin.ts 14/14 (100.00%) 💚
projects/js-packages/charts/src/components/legend/types/legend-margin.ts 0/0 (—%) 🤷

Full summary · PHP report · JS report

@annacmc annacmc requested a review from Copilot September 24, 2025 10:43
Copy link
Contributor

@Copilot 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 10 out of 10 changed files in this pull request and generated 2 comments.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@annacmc annacmc requested a review from Copilot September 25, 2025 00:05
Copy link
Contributor

@Copilot 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 13 out of 13 changed files in this pull request and generated 2 comments.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@annacmc annacmc requested a review from Copilot September 25, 2025 01:55
Copy link
Contributor

@Copilot 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 14 out of 14 changed files in this pull request and generated 2 comments.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@annacmc annacmc marked this pull request as ready for review September 25, 2025 02:07
@annacmc annacmc added the [Status] Needs Review This PR is ready for review. label Sep 25, 2025
@annacmc annacmc requested a review from a team September 25, 2025 02:07
Copy link
Contributor

@kangzj kangzj left a comment

Choose a reason for hiding this comment

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

Like I commented here before, we probably don't want more props to control legend because there are already a few - Consumers could achieve similar styling by passing in a className.

I'll be more than happy to approve the PR if we allow passing in a legendItemClassName so that consumers have full control of both the legend and the legend items.

As a follow up, this issue CHARTS-36 might be worth looking at to clean things up a bit.

More customization could be achieved with this one CHARTS-119.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[JS Package] Charts RNA [Status] In Progress [Status] Needs Review This PR is ready for review. [Tests] Includes Tests [Type] Enhancement Changes to an existing feature — removing, adding, or changing parts of it
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants