Skip to content

Conversation

@annacmc
Copy link
Contributor

@annacmc annacmc commented Oct 28, 2025

Proposed changes:

  • Fix LineChart to respect user-provided margin.top when legend is positioned at top
  • Fix BarChart to respect user-provided margin.top when legend is positioned at top
  • Update margin calculation to use margin?.top ?? defaultMargin.top pattern
  • Add test coverage for LineChart margin behavior with legend at top/bottom
  • Add test coverage for BarChart margin behavior with legend at top/bottom
  • Ensure legend height is added to user's margin value rather than replacing it

Previously, when the legend was positioned at the top, user-provided margin.top values were overridden by the legend calculation. Now the user's margin takes precedence and the legend height is properly added to it.

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:

  • Test LineChart with custom margin and legend at top:
    <LineChart
      data={sampleData}
      showLegend={true}
      legendPosition="top"
      margin={{ top: 50, right: 20, bottom: 20, left: 20 }}
    />
  • Verify that the custom margin.top value (50px) is respected and the legend height is added to it
  • Test BarChart with the same configuration
  • Verify charts render correctly with legend at top and custom margins
  • Verify charts still work with default margins when none are provided
  • Verify charts work correctly with legend at bottom position
  • Run the test suite: pnpm test
  • All 539 tests should pass including 6 new margin-related tests
@annacmc annacmc added [Type] Enhancement Changes to an existing feature — removing, adding, or changing parts of it [Status] Needs Review This PR is ready for review. labels Oct 28, 2025
@annacmc annacmc self-assigned this Oct 28, 2025
@annacmc annacmc added [Type] Enhancement Changes to an existing feature — removing, adding, or changing parts of it [Status] Needs Review This PR is ready for review. labels Oct 28, 2025
@github-actions
Copy link
Contributor

github-actions bot commented Oct 28, 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-43-legends-ensure-that-the-user-provided-margin-prop-takes branch.
  • To test on Simple, run the following command on your sandbox:
bin/jetpack-downloader test jetpack charts-43-legends-ensure-that-the-user-provided-margin-prop-takes

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

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 October 28, 2025 11:43
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 fixes a bug where user-provided margin.top values were being overridden when legends were positioned at the top in LineChart and BarChart components. The fix ensures that custom margin values take precedence and the legend height is properly added to them rather than replacing them.

Key Changes:

  • Updated margin calculation logic in both LineChart and BarChart to use margin?.top ?? defaultMargin.top pattern
  • Added comprehensive test coverage (6 new tests) for margin behavior with legends at different positions

Reviewed Changes

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

Show a summary per file
File Description
line-chart.tsx Fixed margin.top calculation to respect user-provided values when legend is at top
bar-chart.tsx Fixed margin.top calculation to respect user-provided values when legend is at top
line-chart.test.tsx Added 3 tests covering margin behavior with legend positioning
bar-chart.test.tsx Added 3 tests covering margin behavior with legend positioning
changelog/charts-43-legends-ensure-that-the-user-provided-margin-prop-takes Added changelog entry documenting the fix

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@jp-launch-control
Copy link

Code Coverage Summary

This 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. 🤷

Full summary · PHP report · JS report

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

2 participants