mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2025-01-10 02:07:26 +03:00
Ensured bar charts start at 0
This commit is contained in:
parent
64c1b56973
commit
5d5a2be498
2 changed files with 23 additions and 2 deletions
|
@ -33,9 +33,18 @@ export function GraphCard({ title, isBarChart, stats }) {
|
||||||
});
|
});
|
||||||
const renderGraph = () => {
|
const renderGraph = () => {
|
||||||
const Component = isBarChart ? HorizontalBar : Doughnut;
|
const Component = isBarChart ? HorizontalBar : Doughnut;
|
||||||
const legend = isBarChart ? { display: false } : { position: 'right' };
|
const options = {
|
||||||
|
legend: isBarChart ? { display: false } : { position: 'right' },
|
||||||
|
scales: isBarChart ? {
|
||||||
|
xAxes: [
|
||||||
|
{
|
||||||
|
ticks: { beginAtZero: true },
|
||||||
|
},
|
||||||
|
],
|
||||||
|
} : null,
|
||||||
|
};
|
||||||
|
|
||||||
return <Component data={generateGraphData(stats)} options={{ legend }} />;
|
return <Component data={generateGraphData(stats)} options={options} />;
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
|
@ -26,6 +26,7 @@ describe('<GraphCard />', () => {
|
||||||
expect(horizontal).toHaveLength(0);
|
expect(horizontal).toHaveLength(0);
|
||||||
|
|
||||||
const { labels, datasets: [{ title, data, backgroundColor, borderColor }] } = doughnut.prop('data');
|
const { labels, datasets: [{ title, data, backgroundColor, borderColor }] } = doughnut.prop('data');
|
||||||
|
const { legend, scales } = doughnut.prop('options');
|
||||||
|
|
||||||
expect(title).toEqual('The chart');
|
expect(title).toEqual('The chart');
|
||||||
expect(labels).toEqual(keys(stats));
|
expect(labels).toEqual(keys(stats));
|
||||||
|
@ -40,6 +41,8 @@ describe('<GraphCard />', () => {
|
||||||
'#4D5360',
|
'#4D5360',
|
||||||
]);
|
]);
|
||||||
expect(borderColor).toEqual('white');
|
expect(borderColor).toEqual('white');
|
||||||
|
expect(legend).toEqual({ position: 'right' });
|
||||||
|
expect(scales).toBeNull();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('renders HorizontalBar when is not a bar chart', () => {
|
it('renders HorizontalBar when is not a bar chart', () => {
|
||||||
|
@ -51,8 +54,17 @@ describe('<GraphCard />', () => {
|
||||||
expect(horizontal).toHaveLength(1);
|
expect(horizontal).toHaveLength(1);
|
||||||
|
|
||||||
const { datasets: [{ backgroundColor, borderColor }] } = horizontal.prop('data');
|
const { datasets: [{ backgroundColor, borderColor }] } = horizontal.prop('data');
|
||||||
|
const { legend, scales } = horizontal.prop('options');
|
||||||
|
|
||||||
expect(backgroundColor).toEqual('rgba(70, 150, 229, 0.4)');
|
expect(backgroundColor).toEqual('rgba(70, 150, 229, 0.4)');
|
||||||
expect(borderColor).toEqual('rgba(70, 150, 229, 1)');
|
expect(borderColor).toEqual('rgba(70, 150, 229, 1)');
|
||||||
|
expect(legend).toEqual({ display: false });
|
||||||
|
expect(scales).toEqual({
|
||||||
|
xAxes: [
|
||||||
|
{
|
||||||
|
ticks: { beginAtZero: true },
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue