Skip to content

Commit

Permalink
Stop double formatting in label calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
carysmills committed Dec 19, 2024
1 parent 5a84e48 commit 760c8c2
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export function LegendValues({
const longestLegendNameWidth = useMemo(() => {
return legendData.reduce((previous, current) => {
const estimatedLegendNameWidth = estimateStringWidth(
`${seriesNameFormatter(`${current.name || ''}`)}`,
current.name,
characterWidths,
);

Expand All @@ -95,7 +95,7 @@ export function LegendValues({

return previous;
}, 0);
}, [legendData, seriesNameFormatter, characterWidths]);
}, [legendData, characterWidths]);

const longestLegendValueWidth = useMemo(() => {
return legendData.reduce((previous, current) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import {mount} from '@shopify/react-testing';

import {LegendValues} from '../LegendValues';

const mockProps = {
data: [
{
name: 'Shopify Payments',
data: [{key: 'april - march', value: 50000}],
},
],
activeIndex: 1,
legendFullWidth: false,
labelFormatter: (val) => `${val}!`,
getColorVisionStyles: jest.fn(),
getColorVisionEventAttrs: jest.fn(),
seriesNameFormatter: (val) => `${val}!`,
renderHiddenLegendLabel: jest.fn(),
} as any;

describe('<LegendValues />', () => {
it('renders a table', async () => {
const legendValues = mount(<LegendValues {...mockProps} />);
expect(legendValues).toContainReactComponent('table', {
style: {maxWidth: 197.22, width: '100%'},
});
});
});

0 comments on commit 760c8c2

Please sign in to comment.