Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue with bar with when data changes from zero values #1588

Merged
merged 1 commit into from
Sep 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .github/workflows/chromatic-main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ on: push
jobs:
chromatic:
runs-on: ubuntu-latest
if: ${{ github.actor != 'dependabot[bot]' }}
if: github.ref == 'refs/heads/main'
continue-on-error: true
steps:
- name: Checkout 🛎️
Expand All @@ -19,7 +19,6 @@ jobs:
- name: Install and Build 🔧
run: yarn
- name: Publish to Chromatic and auto accept changes
if: github.ref == 'refs/heads/main'
uses: chromaui/action@v1
with:
projectToken: ${{ secrets.CHROMATIC_PROJECT_TOKEN }}
Expand Down
6 changes: 5 additions & 1 deletion packages/polaris-viz/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

<!-- ## Unreleased -->
## Unreleased

### Fixed

- Fixed issue where `<BarChart />` bar width would be 1px when data changes from all 0 values to data with non-zero values.

## [9.12.0] - 2023-09-19

Expand Down
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({});
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export const VerticalBar = memo(function Bar({
}: VerticalBarProps) {
const selectedTheme = useTheme();
const borderRadius = selectedTheme.bar.borderRadius;
const treatAsNegative = rawValue < 0 || rawValue === 0;
const treatAsNegative = rawValue < 0;
const zeroValue = rawValue === 0;

const yPosition = useMemo(() => {
Expand All @@ -67,7 +67,7 @@ export const VerticalBar = memo(function Bar({
);

const springConfig = useBarSpringConfig({animationDelay});
const rotate = `${treatAsNegative ? 'rotate(180)' : ''}`;
const rotate = `${treatAsNegative ? 'rotate(180)' : 'rotate(0)'}`;

const {pathD, transform} = useSpring({
from: {
Expand Down