Skip to content
This repository was archived by the owner on Jun 6, 2025. It is now read-only.

Commit 8cf0484

Browse files
authored
Merge pull request #1786 from Shopify/fix-donut-double-format
Stop double formatting in label calculation
2 parents 5a84e48 + 5b15abf commit 8cf0484

File tree

3 files changed

+35
-3
lines changed

3 files changed

+35
-3
lines changed

packages/polaris-viz/CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
66
and adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
77

8-
<!-- ## Unreleased -->
8+
## Unreleased
9+
10+
### Fixed
11+
12+
- Double formatting in Donut Chart label calculations
913

1014
## [15.6.1] - 2024-12-18
1115

packages/polaris-viz/src/components/DonutChart/components/LegendValues/LegendValues.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ export function LegendValues({
8585
const longestLegendNameWidth = useMemo(() => {
8686
return legendData.reduce((previous, current) => {
8787
const estimatedLegendNameWidth = estimateStringWidth(
88-
`${seriesNameFormatter(`${current.name || ''}`)}`,
88+
current.name,
8989
characterWidths,
9090
);
9191

@@ -95,7 +95,7 @@ export function LegendValues({
9595

9696
return previous;
9797
}, 0);
98-
}, [legendData, seriesNameFormatter, characterWidths]);
98+
}, [legendData, characterWidths]);
9999

100100
const longestLegendValueWidth = useMemo(() => {
101101
return legendData.reduce((previous, current) => {
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import {mount} from '@shopify/react-testing';
2+
3+
import {LegendValues} from '../LegendValues';
4+
5+
const mockProps = {
6+
data: [
7+
{
8+
name: 'Shopify Payments',
9+
data: [{key: 'april - march', value: 50000}],
10+
},
11+
],
12+
activeIndex: 1,
13+
legendFullWidth: false,
14+
labelFormatter: (val) => `${val}!`,
15+
getColorVisionStyles: jest.fn(),
16+
getColorVisionEventAttrs: jest.fn(),
17+
seriesNameFormatter: (val) => `${val}!`,
18+
renderHiddenLegendLabel: jest.fn(),
19+
} as any;
20+
21+
describe('<LegendValues />', () => {
22+
it('renders a table with max width', async () => {
23+
const legendValues = mount(<LegendValues {...mockProps} />);
24+
expect(legendValues).toContainReactComponent('table', {
25+
style: {maxWidth: 197.22, width: '100%'},
26+
});
27+
});
28+
});

0 commit comments

Comments
 (0)