fix: added support for percentFormat in Segment Label#744
Merged
c-lamoureux merged 2 commits intoadobe:mainfrom Apr 7, 2026
Merged
fix: added support for percentFormat in Segment Label#744c-lamoureux merged 2 commits intoadobe:mainfrom
c-lamoureux merged 2 commits intoadobe:mainfrom
Conversation
Contributor
|
Changes look great. Can we add the prop and description to the Docs package? |
Made-with: Cursor
c-lamoureux
approved these changes
Apr 7, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Added a new percentFormat prop to the SegmentLabel component that allows customizing the d3 format specifier used for percentage labels on donut chart segments. Previously, the percentage format was hardcoded to '.0%' (whole percentages like "45%"), making it impossible to display decimal percentages (e.g., "45.3%"). This also caused precision loss through rounding — for example, values like 0.4% and 1.2% would both round to "0%" and "1%" respectively, making it difficult to distinguish between small but meaningfully different segments.
The change spans both the main (vega-spec-builder) and S2 (vega-spec-builder-s2) packages, keeping them in sync.
Related Issue
N/A — discovered while consuming the library in a downstream project where valueFormat was being passed with percent: true, but had no effect on the percentage display.
Motivation and Context
When using , there was no way to control the precision of the percentage label. The format was hardcoded to '.0%' in getSegmentLabelValueText(). The existing valueFormat prop only applies to the metric value (when value: true), not to the percentage — which was not obvious from the API surface. Adding percentFormat gives consumers explicit control over percentage formatting while maintaining backward compatibility with the '.0%' default.
How Has This Been Tested?
Screenshots (if appropriate):
Added 4 new unit tests (2 per spec-builder package) covering:
Custom percentFormat with percent: true only
Custom percentFormat in combined percent + value mode
All 39 existing tests continue to pass (yarn test -- --testPathPattern="segmentLabelUtils")
Locally tested with a downstream consumer app via pnpm link to verify the percentage labels render with the custom format
Screenshots (if appropriate):

Types of changes
Checklist: