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

0% Statements 0/23
0% Branches 0/16
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
    45
    46

     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, CountriesResult } from '../Graphs/types';
    import { assert } from 'assert-ts';
    import { LoadingOverlay } from '@cutting/component-library';

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

      if (typeof result.data?.SCO === 'undefined') {
        return <LoadingOverlay busy={true} darkMode={true} />;
      }

      const countries = {
        SCO: result.data.SCO,
      };

      for (const c of Object.keys(countries)) {
        const countryCode = c as Countries;
        const country = (countries as CountriesResult)?.[countryCode];
        assert(!!country, `no country found for ${c}`);
        country.data = country.data.map((d) => {
          return {
            ...d,
            y: d.deltaDeaths <= 0 ? 0 : d.deltaDeaths,
          };
        });
      }

      return (
        <Graph
          heading="Daily Increase in Scottish deaths"
          xAxisLabel="Days since first reported death"
          yAxisLabel="Increase in deaths from previous day"
          result={{ data: countries as CountriesResult }}
          labels={({ datum }) => {
            return `${dayjs(datum?.x).format('DD/M  M/YY')}\n total deaths = ${datum.deaths}\n daily increase = ${
              datum.deltaDeaths
            }`;
          }}
        />
      );
    };