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: barchart disappearance bars issue #72

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
24 changes: 12 additions & 12 deletions packages/ez-dev/jest/snapshots/recipes/bar/BarChart.spec.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ exports[`BarChart renders a bar chart 1`] = `
data-testid="ez-bar"
fill="red"
height="100.00000000000001"
width="0"
width="250"
x="0"
y="275"
>
Expand All @@ -41,7 +41,7 @@ exports[`BarChart renders a bar chart 1`] = `
data-testid="ez-bar"
fill="green"
height="100.00000000000001"
width="250"
width="375"
x="0"
y="25"
>
Expand Down Expand Up @@ -75,7 +75,7 @@ exports[`BarChart renders a bar chart 1`] = `
transform="translate(0, 0) rotate(0 0 0)"
y="9"
>
50
0
</text>
</g>
<g
Expand All @@ -95,7 +95,7 @@ exports[`BarChart renders a bar chart 1`] = `
transform="translate(0, 0) rotate(0 0 0)"
y="9"
>
55
10
</text>
</g>
<g
Expand All @@ -115,7 +115,7 @@ exports[`BarChart renders a bar chart 1`] = `
transform="translate(0, 0) rotate(0 0 0)"
y="9"
>
60
20
</text>
</g>
<g
Expand All @@ -135,7 +135,7 @@ exports[`BarChart renders a bar chart 1`] = `
transform="translate(0, 0) rotate(0 0 0)"
y="9"
>
65
30
</text>
</g>
<g
Expand All @@ -155,7 +155,7 @@ exports[`BarChart renders a bar chart 1`] = `
transform="translate(0, 0) rotate(0 0 0)"
y="9"
>
70
40
</text>
</g>
<g
Expand All @@ -175,7 +175,7 @@ exports[`BarChart renders a bar chart 1`] = `
transform="translate(0, 0) rotate(0 0 0)"
y="9"
>
75
50
</text>
</g>
<g
Expand All @@ -195,7 +195,7 @@ exports[`BarChart renders a bar chart 1`] = `
transform="translate(0, 0) rotate(0 0 0)"
y="9"
>
80
60
</text>
</g>
<g
Expand All @@ -215,7 +215,7 @@ exports[`BarChart renders a bar chart 1`] = `
transform="translate(0, 0) rotate(0 0 0)"
y="9"
>
85
70
</text>
</g>
<g
Expand All @@ -235,7 +235,7 @@ exports[`BarChart renders a bar chart 1`] = `
transform="translate(0, 0) rotate(0 0 0)"
y="9"
>
90
80
</text>
</g>
<g
Expand All @@ -255,7 +255,7 @@ exports[`BarChart renders a bar chart 1`] = `
transform="translate(0, 0) rotate(0 0 0)"
y="9"
>
95
90
</text>
</g>
<g
Expand Down
9 changes: 5 additions & 4 deletions packages/ez-react/src/recipes/bar/BarChart.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,17 @@ const TemplateWithParentDimensions: Story<BarChartProps> = (args) => {
);
};

// By passing using the Args format for exported stories, you can control the props for a component for reuse in a test
// https://storybook.js.org/docs/react/workflows/unit-testing
// By passing using the Args format for exported stories,
// you can control the props for a component for reuse in a test
// https://storybook.js.org/docs/vue/workflows/unit-testing
export const Resizable = TemplateWithParentDimensions.bind({});

const initialArguments = {
colors,
grid: { directions: [] },
xAxis: {
domainKey: 'value',
title: 'Count',
nice: 2,
},
yAxis: {
domainKey: 'name',
Expand All @@ -66,5 +68,4 @@ Default.args = {
dimensions,
};

export const Resizable = TemplateWithParentDimensions.bind({});
Resizable.args = initialArguments;
7 changes: 7 additions & 0 deletions packages/ez-react/src/recipes/bar/BarChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
Position,
RawData,
} from 'eazychart-core/src/types';
import { getDomainByKeys } from 'eazychart-core/src/utils';
import { Axis } from '@/components/scales/Axis';
import { Chart } from '@/components/Chart';
import { Bars } from '@/components/Bars';
Expand Down Expand Up @@ -75,6 +76,11 @@ export const BarChart: FC<BarChartProps> = ({
colors
);

const [, xAxisDomainMaxValue] = getDomainByKeys(
[xAxis.domainKey],
activeData
);

return (
<Chart
dimensions={dimensions}
Expand All @@ -93,6 +99,7 @@ export const BarChart: FC<BarChartProps> = ({
domainKey: xAxis.domainKey,
nice: xAxis.nice || 0,
reverse: isRTL,
domain: [0, xAxisDomainMaxValue],
Comment on lines 100 to +102
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
nice: xAxis.nice || 0,
reverse: isRTL,
domain: [0, xAxisDomainMaxValue],
nice: typeof xAxis.nice !== 'undefined' ? xAxis.nice : 1,
reverse: isRTL,

Note that values could be negative, so we cannot set zero as lower band. By default the scale will compute the min and max by using the xAxis.domainKey, so there's no need to re-calculate the max value. I think we should set nice to "1" if none is provided to solve the issue.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @marrouchi still have the problem after applying the request update
image

},
}}
yScaleConfig={{
Expand Down
12 changes: 1 addition & 11 deletions packages/ez-vue/src/recipes/bar/BarChart.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
ResizableChartWrapper,
} from '@/lib/storybook-utils';
import {
animationOptions,
colors,
dimensions,
rawData,
Expand Down Expand Up @@ -50,7 +49,6 @@ const TemplateWithParentDimensions: Story = (_args, { argTypes }) => ({
// By passing using the Args format for exported stories,
// you can control the props for a component for reuse in a test
// https://storybook.js.org/docs/vue/workflows/unit-testing
export const Default = DefaultTemplate.bind({});
export const Resizable = TemplateWithParentDimensions.bind({});

const initialArguments = {
Expand All @@ -59,23 +57,15 @@ const initialArguments = {
xAxis: {
domainKey: 'value',
title: 'Count',
nice: 2,
},
yAxis: {
domainKey: 'name',
title: 'Letter',
},
padding: {
left: 150,
bottom: 100,
right: 150,
top: 100,
},
animationOptions,
isRTL: false,
data: rawData,
};

export const Default = DefaultTemplate.bind({});
Default.args = {
...initialArguments,
dimensions,
Expand Down
5 changes: 4 additions & 1 deletion packages/ez-vue/src/recipes/bar/BarChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
Dimensions,
} from 'eazychart-core/src/types';
import { Prop } from 'vue-property-decorator';
import { ScaleBand, ScaleLinear } from 'eazychart-core/src';
import { getDomainByKeys, ScaleBand, ScaleLinear } from 'eazychart-core/src';
import Chart from '@/components/Chart';
import Axis from '@/components/scales/Axis';
import Legend from '@/components/addons/legend/Legend';
Expand Down Expand Up @@ -155,6 +155,8 @@ export default class BarChart extends mixins(ToggleDatumMixin) {
Tooltip: $scopedSlots.Tooltip,
};

const [, xAxisDomainMaxValue] = getDomainByKeys([xAxis.domainKey], activeData);

return (
<Chart
dimensions={dimensions}
Expand All @@ -172,6 +174,7 @@ export default class BarChart extends mixins(ToggleDatumMixin) {
domainKey: xAxis.domainKey,
nice: xAxis.nice || 0,
reverse: isRTL,
domain: [0, xAxisDomainMaxValue],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

},
}}
yScaleConfig={{
Expand Down