|
|
@@ -1,8 +1,9 @@
|
|
|
import React from 'react';
|
|
|
import { LineChart, XAxis, YAxis, Line, CartesianGrid } from 'recharts';
|
|
|
|
|
|
-import { Cases, Country } from '../types';
|
|
|
+import { Cases, Country, Data } from '../types';
|
|
|
import { getCases } from '../utils/get-cases';
|
|
|
+import { getExponentialRegression } from '../utils/regression';
|
|
|
|
|
|
type Props = {
|
|
|
country: Country;
|
|
|
@@ -17,15 +18,17 @@ const margin = {
|
|
|
|
|
|
const GraphCases: React.FC<Props> = ({ country }) => {
|
|
|
const cases = React.useMemo<Cases>(() => getCases(country), [country]);
|
|
|
+ const data = React.useMemo<Data>(() => getExponentialRegression(cases), [cases]);
|
|
|
|
|
|
return (
|
|
|
<div>
|
|
|
<h3>Country: {country.toUpperCase()}</h3>
|
|
|
- <LineChart width={640} height={480} data={cases} margin={margin}>
|
|
|
+ <LineChart width={640} height={480} data={data} margin={margin}>
|
|
|
<XAxis dataKey="date" label="Date" />
|
|
|
<YAxis tick />
|
|
|
<CartesianGrid stroke="#f5f5f5" />
|
|
|
<Line type="monotone" dataKey="value" stroke="#000" yAxisId={0} />
|
|
|
+ <Line type="monotone" dataKey="regression" stroke="#06c" yAxisId={0} dot={false} />
|
|
|
</LineChart>
|
|
|
</div>
|
|
|
);
|