# All files / src/components/IncreseFromPreviousDay IncreseFromPreviousDay.tsx

0% Statements 0/24
0% Branches 0/14
0% Functions 0/3
0% Lines 0/19

Press n or j to go to the next uncovered block, b, p or k for the previous block.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44

     import type { FC } from 'react';
    import { useCountryCovidData } from 'src/components/Graphs/useCountryCovidData';
    import Graph from 'src/components/Graphs/Graph';
    import dayjs from 'dayjs';
    import { Countries, countryData, CountryResult } from '../Graphs/types';
    import { assert } from 'assert-ts';

    export const IncreseFromPreviousDay: FC = () => {
      const result = useCountryCovidData();

      if (result.data) {
        for (const c of Object.keys(result.data)) {
          const country: CountryResult = result.data?.[c as Countries];
          assert(!!country, `no country found for ${c}`);
          country.data = country.data.map((d) => {
            const delta = (d.deltaDeaths / countryData[c as Countries].population) * 100000;

            if (isNaN(delta)) {
              console.log({ d, c, country, delta });
            }

            return {
              ...d,
              y: delta <= 0 ? 0 : delta,
            };
          });
        }
      }

      return (
        <Graph
          heading="Daily Increase in deaths"
          xAxisLabel="Days since first reported death"
          yAxisLabel="Increase in deaths from previous day (per 100,000 people)"
          result={result}
          labels={({ datum }) => {
            return `${dayjs(datum?.x).format('DD/MM/YY')}\n total deaths = ${datum.deaths}\n daily increase = ${
              datum.deltaDeaths
            }`;
          }}
        />
      );
    };