Skip to content

Conversation

@annacmc
Copy link
Contributor

@annacmc annacmc commented Sep 15, 2025

Proposed changes:

  • Fix container height calculation in BarChart, LineChart, PieChart, and PieSemiCircleChart components
  • Update container height to be height + (showLegend ? legendHeight : 0) to properly accommodate legend
  • Ensure chart content respects the specified height prop while legend is rendered in additional space
  • Add test to verify proper height behavior when legend is displayed

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 for any of the affected charts (BarChart, LineChart, PieChart, PieSemiCircleChart)
  • Set a specific height value (e.g., 300px)
  • Enable the legend via showLegend: true
  • Verify that:
    • The chart content area maintains the specified height
    • The legend appears below (or above if legendPosition: 'top') without reducing chart height
    • The total container height is taller than the specified height to accommodate the legend
  • Test with different legend positions (top and bottom)
  • Verify no visual regressions in chart rendering
  • Confirm that charts without legends maintain their original height behavior
  • Run the test suite to ensure all tests pass

@annacmc annacmc self-assigned this Sep 15, 2025
@annacmc annacmc added [Type] Bug When a feature is broken and / or not performing as intended [Status] In Progress labels Sep 15, 2025
@github-actions
Copy link
Contributor

github-actions bot commented Sep 15, 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 fix/charts-105-fix-chart-height-calculation-to-include-legend-height branch.
  • To test on Simple, run the following command on your sandbox:
bin/jetpack-downloader test jetpack fix/charts-105-fix-chart-height-calculation-to-include-legend-height

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 September 15, 2025 10:40
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 chart height calculation in chart components to properly accommodate legend height. When a legend is displayed, the container height is now calculated as height + legendHeight instead of just height, ensuring the chart content maintains its specified height while the legend appears in additional space.

Key changes:

  • Updated container height calculation in BarChart, LineChart, PieChart, and PieSemiCircleChart components
  • Modified the height style property to include legend height when showLegend is true
  • Added test coverage to verify proper height behavior when legend is displayed

Reviewed Changes

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

Show a summary per file
File Description
bar-chart.tsx Updated container height to include legend height
line-chart.tsx Modified height calculation to account for legend space
pie-chart.tsx Fixed container height to accommodate legend
pie-semi-circle-chart.tsx Added legend height to container height calculation
bar-chart.test.tsx Added test to verify container height accounts for legend
changelog Added changelog entry for the height calculation fix

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

@jp-launch-control
Copy link

jp-launch-control bot commented Sep 15, 2025

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

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

@dognose24 dognose24 left a comment

Choose a reason for hiding this comment

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

The chart content area maintains the specified height

In my testing, the .bar-chart container is expanded (420px) to the specified height (400px) plus the legend height (20px), but the chart section remains the original height (380px) of the specified height minus the legend height, showing an extra gap at the bottom. Should the chart height be expanded to 400px instead?

Before After
截圖 2025-09-15 晚上11 48 15 截圖 2025-09-15 晚上11 39 25
截圖 2025-09-15 晚上11 37 17

@annacmc
Copy link
Contributor Author

annacmc commented Sep 16, 2025

In my testing, the .bar-chart container is expanded (420px) to the specified height (400px) plus the legend height (20px), but the chart section remains the original height (380px) of the specified height minus the legend height, showing an extra gap at the bottom. Should the chart height be expanded to 400px instead?

Thanks for testing this out! I think you might have a good point, I am going to revisit this :)

@kangzj
Copy link
Contributor

kangzj commented Sep 18, 2025

Could it be related to the ratio of the withResponsive decorator?

@kangzj
Copy link
Contributor

kangzj commented Sep 18, 2025

Set a specific height value (e.g., 300px)
Enable the legend via showLegend: true
Verify that:
The chart content area maintains the specified height
The legend appears below (or above if legendPosition: 'top') without reducing chart height

I don't know whether we should be after this to be honest. AFAICS, the height we accept should be the overall height of all visuals, including both the chart and the legend. Thoughts 🤔

Copy link
Contributor Author

annacmc commented Sep 19, 2025

Thanks for your thoughts Jasper. I am still trying to wrap my head around exactly what we want. But I think it makes the most semantic sense to me that the height we accept should be the overall heigh of all visuals, so both chart + legend.

@annacmc annacmc force-pushed the fix/charts-105-fix-chart-height-calculation-to-include-legend-height branch from bd883e1 to b677a8b Compare September 19, 2025 12:00
@kangzj
Copy link
Contributor

kangzj commented Sep 22, 2025

I would expect something like the following, basically what bar chart is doing before this PR. However when the provided hight is greater than the required hight, taking up partial the space should be fine.

Screen.Recording.2025-09-22.at.1.15.34.PM.mov
Screen.Recording.2025-09-22.at.1.20.08.PM.mov

How the margins are calculated should probably be revisited too I think 🤔

@annacmc
Copy link
Contributor Author

annacmc commented Sep 22, 2025

I would expect something like the following, basically what bar chart is doing before this PR.

This is essentially what it's already doing without this PR. I'm trying to understand if there's value in pursuing this one right now or if we should close it up. The issue it stems from the statement "Height of chart isn't respecting the props, meaning height of legend isn't included in calculating the height "

I'm wondering if this would be better off as a very minor one-liner change to be something like only updating container height to be height + (showLegend ? legendHeight : 0) or potentially combining that with re-evaluaton of margin calculations?

@adamwoodnz
Copy link
Contributor

adamwoodnz commented Oct 7, 2025

I've been thinking about this and I feel like there are 2 scenarios:

  1. The consumer has a flexible space that the chart needs to fit in (eg. a Woo Analytics dashboard tile). They don't want to specify a height or width, and expect the chart to fill the available area. The size of the chart will need to be calculated based on the parent element size and the legend visibility and size. The chart should be responsive to changes in the parent size.
  2. The consumer wants a fixed height and/or width. They expect the chart to fill this space and not exceed it. The size of the chart will need to be calculated based on the specified dimension(s) and the legend visibility and size. The chart should not be responsive to changes in the parent size, and it is the consumer's responsibility to update the specified size.

In the case of Woo Analytics it may be desirable to be able to specify the exact height of just the chart, so that for example all the pie charts in the dashboard are the same size, rather than differing due to the number of legend items:

Screenshot 2025-10-06 at 4 47 37 PM

In this case where they have not specified an overall size but have specified a chart size, we should respect that height up until the point where it doesn't fit the parent space, and then reduce it to fit.

Does this make sense?

I think we can achieve this using some sort of shared layout wrapper using a flexbox column and a ResizeObserver. It will need to know about legend visibility and position. I'm not sure at this point how exactly that will play with the existing withResponsive wrapper.

Related:

@github-actions
Copy link
Contributor

github-actions bot commented Dec 7, 2025

This PR has been marked as stale. This happened because:

  • It has been inactive for the past 3 months.
  • It hasn't been labeled `[Pri] BLOCKER`, `[Pri] High`, `[Status] Keep Open`, etc.

If this PR is still useful, please do a [trunk merge or rebase](https://github.com/Automattic/jetpack/blob/trunk/docs/git-workflow.md#keeping-your-branch-up-to-date) and otherwise make sure it's up to date and has clear testing instructions. You may also want to ping possible reviewers in case they've forgotten about it. Please close this PR if you think it's not valid anymore — if you do, please add a brief explanation.

If the PR is not updated (or at least commented on) in another month, it will be automatically closed.

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. [Status] Stale [Tests] Includes Tests [Type] Bug When a feature is broken and / or not performing as intended

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants