-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix issue with bar with when data changes from zero values
- Loading branch information
Showing
3 changed files
with
113 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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
106 changes: 106 additions & 0 deletions
106
packages/polaris-viz/src/components/BarChart/stories/playground/ZeroDataChange.stories.tsx
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
import type {Story} from '@storybook/react'; | ||
|
||
import {BarChart, BarChartProps} from '../../../../components'; | ||
import {META} from '../meta'; | ||
import {useState} from 'react'; | ||
|
||
export default { | ||
...META, | ||
title: `${META.title}/Playground`, | ||
}; | ||
|
||
const DATA = [ | ||
{ | ||
data: [ | ||
{ | ||
value: 4, | ||
key: '0', | ||
}, | ||
{ | ||
value: 3, | ||
key: '1', | ||
}, | ||
{ | ||
value: 0, | ||
key: '2', | ||
}, | ||
{ | ||
value: 0, | ||
key: '3', | ||
}, | ||
{ | ||
value: 0, | ||
key: '4', | ||
}, | ||
{ | ||
value: 1, | ||
key: '5', | ||
}, | ||
{ | ||
value: 0, | ||
key: '6', | ||
}, | ||
{ | ||
value: 4, | ||
key: '7', | ||
}, | ||
{ | ||
value: 3, | ||
key: '8', | ||
}, | ||
{ | ||
value: 4, | ||
key: '9', | ||
}, | ||
{ | ||
value: 8, | ||
key: '10', | ||
}, | ||
{ | ||
value: 8, | ||
key: '11', | ||
}, | ||
{ | ||
value: 5, | ||
key: '12', | ||
}, | ||
{ | ||
value: 7, | ||
key: '13', | ||
}, | ||
{ | ||
value: 5, | ||
key: '14', | ||
}, | ||
], | ||
name: 'First-time', | ||
}, | ||
]; | ||
|
||
const ZERO_DATA = [ | ||
{...DATA[0], data: DATA[0].data.map((data) => ({...data, value: 0}))}, | ||
]; | ||
|
||
const Template: Story<BarChartProps> = () => { | ||
const [data, setData] = useState(DATA); | ||
|
||
return ( | ||
<> | ||
<button | ||
onClick={() => { | ||
console.warn('SWAP'); | ||
setData((data) => { | ||
return data === DATA ? ZERO_DATA : DATA; | ||
}); | ||
}} | ||
> | ||
Flip | ||
</button> | ||
<div style={{width: 600, height: 400}}> | ||
<BarChart data={data} /> | ||
</div> | ||
</> | ||
); | ||
}; | ||
|
||
export const ZeroData = Template.bind({}); |
This file contains 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