-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: add example to display the bed per 10^3 people
- Loading branch information
1 parent
7ee85e3
commit b33a4c1
Showing
1 changed file
with
98 additions
and
0 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
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³ people</Fragment>} | ||
/> | ||
|
||
<Axis | ||
id="cases" | ||
max={200} | ||
position="left" | ||
label={<Fragment>COVID-19 cases per 10³ 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; | ||
} | ||
} |