Skip to content

Commit

Permalink
Add under control chart
Browse files Browse the repository at this point in the history
  • Loading branch information
rickkln committed Jul 5, 2020
1 parent d05a01c commit d6d6edb
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 0 deletions.
79 changes: 79 additions & 0 deletions src/components/status/underControlChart.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import React from 'react';
import {
VictoryChart, VictoryLegend, VictoryAxis, VictoryLabel, VictoryArea,
} from 'victory';
import { PeriodSummary } from '../../utilities/types/data';
import Theme from '../shared/general/chartTheme';

const UnderControlChart = ({ data }: { data: PeriodSummary[] }) => (
<VictoryChart
theme={Theme}
height={240}
width={600}
minDomain={{ y: 0 }}
>
<VictoryLegend
x={95}
y={15}
orientation="horizontal"
gutter={25}
data={[
{ name: '% Flattening/Losing', symbol: { fill: 'lightcoral' } },
{ name: '% None/Small/Crushing/Winning/Won', symbol: { fill: 'lightgreen' } },
]}
/>
<VictoryAxis fixLabelOverlap />
<VictoryAxis dependentAxis />
<VictoryLabel
text="Pandemic Status (corona.rickkln.com)"
x={400}
y={64}
style={{
fontSize: 6,
fontFamily: `"SFMono-Regular", Consolas, "Roboto Mono", "Droid Sans Mono",
"Liberation Mono", Menlo, Courier, monospace`,
}}
/>
<VictoryLabel
text="Source: JHU CSSE"
x={400}
y={72}
style={{
fontSize: 6,
fontFamily: `"SFMono-Regular", Consolas, "Roboto Mono", "Droid Sans Mono",
"Liberation Mono", Menlo, Courier, monospace`,
}}
/>
<VictoryArea
data={data}
interpolation="monotoneX"
style={{
data: {
fill: 'lightcoral',
fillOpacity: 0.5,
stroke: 'lightcoral',
strokeWidth: 0,
},
}}
x="endDate"
y={() => 100}
y0="underControl"
/>
<VictoryArea
data={data}
interpolation="monotoneX"
style={{
data: {
fill: 'lightgreen',
fillOpacity: 0.5,
stroke: 'lightgreen',
strokeWidth: 2,
},
}}
x="endDate"
y="underControl"
/>
</VictoryChart>
);

export default UnderControlChart;
9 changes: 9 additions & 0 deletions src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { sumPeriodData, calculateGlobalSummary } from '../utilities/calcGlobal';
import OutbreakStatus from '../utilities/types/OutbreakStatus';
import CountryQuery from '../utilities/query';
import PandemicFreeChart from '../components/status/pandemicFreeChart';
import UnderControlChart from '../components/status/underControlChart';

const IndexPage = () => {
const { loading, error, data } = useQuery<Countries>(CountryQuery);
Expand Down Expand Up @@ -104,6 +105,14 @@ const IndexPage = () => {
textAlign: 'center',
marginTop: '1.2rem',
}}
>
<h3 style={{ marginBottom: 0 }}>How many places have the pandemic under control?</h3>
<UnderControlChart data={globalSummaryData} />
</div>
<div
style={{
textAlign: 'center',
}}
>
<h3 style={{ marginBottom: 0 }}>How much of the world is pandemic free?</h3>
<PandemicFreeChart data={globalSummaryData} />
Expand Down
10 changes: 10 additions & 0 deletions src/utilities/calcGlobal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export const calculateGlobalSummary = (
winning: 0,
won: 0,
pandemicFree: 0,
underControl: 0,
}),
);
const periodSummaries = countries.reduce(
Expand Down Expand Up @@ -75,6 +76,15 @@ export const calculateGlobalSummary = (
) {
newGlobalPeriods[periodIndex].pandemicFree += ((1 / 186) * 100);
}
if (
country.periods[periodIndex].status === OutbreakStatus.None
|| country.periods[periodIndex].status === OutbreakStatus.Small
|| country.periods[periodIndex].status === OutbreakStatus.Crushing
|| country.periods[periodIndex].status === OutbreakStatus.Winning
|| country.periods[periodIndex].status === OutbreakStatus.Won
) {
newGlobalPeriods[periodIndex].underControl += ((1 / 186) * 100);
}
return newGlobalPeriods;
},
globalPeriods,
Expand Down
1 change: 1 addition & 0 deletions src/utilities/types/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,5 @@ export interface PeriodSummary {
winning: number
won: number
pandemicFree: number
underControl: number
}

0 comments on commit d6d6edb

Please sign in to comment.