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

0% Statements 0/25
0% Branches 0/22
0% Functions 0/6
0% Lines 0/17

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 regression from 'regression';
    import { Countries } from '../Graphs';
    import dayjs from 'dayjs';

    export const RateOfChange: FC = () => {
      const result = useCountryCovidData({ startDate: '2020-01-01' });

      const dates: string[] = result?.data?.GBR?.data.map((x) => dayjs(x.x).format('DD/MM')) || [];

      if (result.data) {
        for (const c of Object.keys(result.data)) {
          const country = result.data?.[c as Countries];

          country.data.shift();

          country.data = regression
            .logarithmic([
              ...country.data.map((d) => {
                return [d.index, d.deltaDeaths] as [number, number];
              }),
            ])
            // eslint-disable-next-line @typescript-eslint/no-explicit-any
            .points.map(([x, y], i) => ({ x: x - 1, y: i <= 0 ? 0 : y })) as any;
        }
      }

      return (
        <Graph
          heading="Rate of change of reported deaths"
          xAxisLabel="Days since first reported death"
          yAxisLabel="Daily increase in deaths"
          result={result}
          xTickFormat={(i) => {
            return dates[Number(i)];
          }}
          // eslint-disable-next-line @typescript-eslint/no-explicit-any
          yTickFormat={() => ''}
        />
      );
    };