Skip to content

Commit

Permalink
docs: add example to display the bed per 10^3 people
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastien-Ahkrin authored and targos committed May 7, 2021
1 parent 7ee85e3 commit b33a4c1
Showing 1 changed file with 98 additions and 0 deletions.
98 changes: 98 additions & 0 deletions stories/examples/bed.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
import { Meta } from '@storybook/react';
import { Fragment } from 'react';

import {
Axis,
Plot,
Heading,
Legend,
ScatterSeries,
LineSeries,
} from '../../src';

export default {
title: 'Examples/Bed per 10^3 peoples',
} as Meta;

const data = Array.from(generateNumbers(160))
.sort((a, b) => b.beds - a.beds)
.map((e, i) => ({ ...e, country: i }));

export function Covid19BedCases() {
return (
<Plot
width={900}
height={540}
seriesViewportStyle={{ stroke: 'black' }}
margin={{
bottom: 100,
left: 40,
top: 80,
right: 100,
}}
>
<Heading title="(C) NCC=0.20 (***)" />
<Legend position="top" />

<Axis
id="country"
position="bottom"
labelStyle={{ fontWeight: 'bold' }}
tickStyle={{ fontWeight: 'bold' }}
label="Country"
/>

<Axis
id="beds"
max={12}
position="right"
label={<Fragment>Hospital bed per 10&sup3; people</Fragment>}
/>

<Axis
id="cases"
max={200}
position="left"
label={<Fragment>COVID-19 cases per 10&sup3; people</Fragment>}
/>

<ScatterSeries
markerStyle={{ fill: 'red', stroke: 'red' }}
data={data.map((e) => {
return {
x: e.country,
y: e.cases,
};
})}
xAxis="country"
yAxis="cases"
label="COVID-19 case fatality"
/>

<LineSeries
lineStyle={{ stroke: 'blue' }}
data={data.map((e) => {
return {
x: e.country,
y: e.beds,
};
})}
xAxis="country"
yAxis="beds"
label="Hospital beds"
/>
</Plot>
);
}

function* generateNumbers(elements: number) {
for (let i = 0; i < elements; i++) {
const result = {
country: 0,
beds: Math.random() * 12,
cases: Math.floor(Math.random() * 200),
};

yield result;
}
}

0 comments on commit b33a4c1

Please sign in to comment.