Skip to content

Charts- 81: Leaderboard chart supports custom label for greater flexibility. #44751

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Aug 18, 2025

Conversation

halfo
Copy link
Contributor

@halfo halfo commented Aug 12, 2025

Fixes #CHARTS-81

Proposed changes:

  • We can pass a JSX.Element as label to enable more customization. It’s common for labels to include pre/post icons, custom styles etc. This approach makes the label for customizable and flexible.
image
  • Added another boolean prop withOverlayLabel which overlays the label on top of each corresponding bar.

    • Image with custom label and withOverlayLabel.
    image
    • Image with withOverlayLabel and withComparison.
    image
    • Image with withOverlayLabel.
    image

Note that the --bar-border custom CSS property has been introduced to control the border of each bar. While a custom CSS property may be less discoverable than a prop, this is a niche use case, and we can always introduce it as a prop if needed.

Also, the bar height is determined by the label’s height, while its width is based on currentShare and the overall width of the leaderboard component.

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)?

Jetpack product discussion

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

Testing instructions:

Copy link
Contributor

github-actions bot commented Aug 12, 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 add/charts-81-leaderboard-chart-supports-custom-label branch.
  • To test on Simple, run the following command on your sandbox:
bin/jetpack-downloader test jetpack add/charts-81-leaderboard-chart-supports-custom-label

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

github-actions bot commented Aug 12, 2025

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!

@github-actions github-actions bot added the [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. label Aug 12, 2025
Copy link

jp-launch-control bot commented Aug 12, 2025

Code Coverage Summary

Coverage changed in 1 file.

File Coverage Δ% Δ Uncovered
projects/js-packages/charts/src/components/leaderboard-chart/leaderboard-chart.tsx 24/25 (96.00%) -4.00% 1 ❤️‍🩹

Full summary · PHP report · JS report

@halfo halfo requested a review from a team August 13, 2025 06:35
@halfo halfo force-pushed the add/charts-81-leaderboard-chart-supports-custom-label branch from e88773d to bd5974a Compare August 13, 2025 13:19
@kangzj
Copy link
Contributor

kangzj commented Aug 14, 2025

Currently, there’s no way to change the bar’s border-radius. While it’s possible to target the bar with a CSS selector, that exposes internal implementation details. Should we support a custom CSS property like --bar-border-radius, add a dedicated prop, or both?

Happy not to add additional props and I think we don't need that at the stage. We could use the border radius in the design for bars when the pictures are in place.

Both changes in this PR were made with future requests in mind. I’m not yet sure if I’ve been overthinking this, or if I should have designed it so that providing just one or two props would give the desired output, as the following.

I prefer to start simple 🙂

image
We can achieve the ticket’s request by providing customized label, changing primary color and border radius.

Let's fully achieve that as a story to showcase it.

@halfo halfo force-pushed the add/charts-81-leaderboard-chart-supports-custom-label branch from bd5974a to fe22c94 Compare August 14, 2025 05:28
@halfo halfo force-pushed the add/charts-81-leaderboard-chart-supports-custom-label branch 2 times, most recently from fb3ee5a to 8f1112b Compare August 14, 2025 07:21
@halfo halfo force-pushed the add/charts-81-leaderboard-chart-supports-custom-label branch from 8f1112b to a6f3d81 Compare August 14, 2025 07:29
@halfo halfo added the [Status] Needs Review This PR is ready for review. label Aug 14, 2025
@halfo halfo marked this pull request as ready for review August 14, 2025 09:43
@github-actions github-actions bot added [Status] In Progress and removed [Status] Needs Review This PR is ready for review. labels Aug 14, 2025
@halfo halfo added [Type] Enhancement Changes to an existing feature — removing, adding, or changing parts of it [Status] Needs Review This PR is ready for review. and removed [Status] In Progress labels Aug 14, 2025
@halfo halfo force-pushed the add/charts-81-leaderboard-chart-supports-custom-label branch from 556cb22 to 2aaf7f4 Compare August 14, 2025 10:03
Nikschavan
Nikschavan previously approved these changes Aug 14, 2025
Copy link
Member

@Nikschavan Nikschavan left a comment

Choose a reason for hiding this comment

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

Looks great! Added non-blocking suggestions

{ typeof entry.label === 'string' ? <Text>{ entry.label }</Text> : entry.label }

<div className={ styles.progressContainer }>
<ProgressBar
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems ProgressBar wouldn't satisfy the needs here, so we should probably just use our custom implementation in ProgressBarWithOverlayLabel.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks @kangzj. I created this ticket to address this.

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.

LGTM! Nice one 👍

One nitpick:

When withOverlayLabel is true and the data has images, we probably want to the images with the start of the progress bars.

Screenshot 2025-08-15 at 11 32 24 AM

border-radius: var(--bar-border, 9999px);
z-index: -1; /* places it behind the label */

transition: width 0.3s ease-in-out;
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's not use animation yet.

@halfo halfo merged commit 2734e4b into trunk Aug 18, 2025
86 checks passed
@halfo halfo deleted the add/charts-81-leaderboard-chart-supports-custom-label branch August 18, 2025 05:29
@github-actions github-actions bot removed [Status] Needs Review This PR is ready for review. [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. labels Aug 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[JS Package] Charts RNA [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.

3 participants