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

Commit 5a871f7

Browse files
authored
Merge pull request #1794 from Shopify/envex/all-negative-labels
Move 0 value labels to left when all value are negative
2 parents 896180b + 027b017 commit 5a871f7

File tree

3 files changed

+73
-1
lines changed

3 files changed

+73
-1
lines changed

packages/polaris-viz/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ and adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
1010
### Fixed
1111

1212
- Fixed issue in `<SimpleBarChart />` where the trend indicator was not being positioned correctly when the value was `null`.
13+
- Fixed issue in `<SimpleBarChart />` where labels are not positioned correctly when all values were negative and `0`.
1314

1415
## [15.8.0] - 2025-01-16
1516

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import type {Story} from '@storybook/react';
2+
3+
import {SimpleBarChart, SimpleBarChartProps} from '../../../../components';
4+
import {META} from '../meta';
5+
import type {SimpleBarChartDataSeries} from '../../types';
6+
import {
7+
DEFAULT_THEME_NAME,
8+
PolarisVizProvider,
9+
} from '@shopify/polaris-viz-core';
10+
11+
export default {
12+
...META,
13+
title: `${META.title}/Playground`,
14+
};
15+
16+
const DATA: SimpleBarChartDataSeries[] = [
17+
{
18+
name: '',
19+
data: [
20+
{key: 'One', value: 0},
21+
{key: 'Two', value: 0},
22+
{key: 'Three', value: -22.1},
23+
{key: 'Four', value: 0},
24+
{key: 'Five', value: -17.5},
25+
],
26+
metadata: {
27+
trends: {
28+
'0': {},
29+
},
30+
},
31+
},
32+
{
33+
name: '',
34+
data: [
35+
{key: 'One', value: 0},
36+
{key: 'Two', value: 0},
37+
{key: 'Three', value: 0},
38+
{key: 'Four', value: 0},
39+
{key: 'Five', value: 0},
40+
],
41+
},
42+
];
43+
44+
const Template: Story<SimpleBarChartProps> = () => {
45+
const svgStyle = `
46+
svg {
47+
background: rgba(0, 255, 0, 0.1);
48+
}
49+
`;
50+
51+
return (
52+
<div style={{height: 600, width: 800}}>
53+
<style>{svgStyle}</style>
54+
<PolarisVizProvider
55+
animated={{} as any}
56+
themes={{
57+
[DEFAULT_THEME_NAME]: {
58+
chartContainer: {
59+
backgroundColor: 'rgba(255, 0, 0, 0.1)',
60+
padding: '20px',
61+
},
62+
},
63+
}}
64+
>
65+
<SimpleBarChart data={DATA} showLegend={false} />
66+
</PolarisVizProvider>
67+
</div>
68+
);
69+
};
70+
71+
export const AllNegative = Template.bind({});

packages/polaris-viz/src/components/shared/HorizontalBars/HorizontalBars.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ export function HorizontalBars({
126126
min: 1,
127127
});
128128

129-
if (isNegative) {
129+
if (areAllNegative || isNegative) {
130130
return {
131131
labelX: -(clampedWidth + leftLabelOffset),
132132
barWidth: clampedWidth,

0 commit comments

Comments
 (0)