import type { FC } from 'react'; import { useRef } from 'react'; import { useParentSize } from '@cutting/use-get-parent-size'; import { VictoryChart, VictoryGroup, VictoryLegend, VictoryTooltip, VictoryLine, VictoryScatter, VictoryAxis, } from 'victory'; import dayjs from 'dayjs'; import { ApplicationLayout } from '../../layouts/ApplicationLayout'; import { LoadingOverlay } from '@cutting/component-library'; import { ResponsiveSVG } from '@cutting/svg'; import { AxisColor, Countries, DayData, countryData, CountriesResult } from '../Graphs/types'; import * as Urls from '../../urls'; import { NavLink, useLocation } from 'react-router-dom'; import { assert } from 'assert-ts'; import * as styles from './Graph.css'; export type GraphProps = { result: { data?: CountriesResult }; xAxisLabel: string; yAxisLabel: string; xTickFormat?: (label: string, i: number, a: unknown[]) => string; // eslint-disable-next-line @typescript-eslint/no-explicit-any yTickFormat?: (tick: any, index: number, ticks: any[]) => string | number; heading: string; labels?: ({ datum }: { datum: DayData }) => string; }; export const Graph: FC = ({ result, yAxisLabel, labels, heading, xTickFormat = (label: string, i: number, a: unknown[]) => i % 2 === 0 || i === a.length - 1 ? `${dayjs(label).format('DD/MM')}` : '', yTickFormat = (t) => t, }) => { const location = useLocation(); const legendRef = useRef(null); const chartRef = useRef(null); const largeScreen = typeof window !== 'undefined' && window.screen.availWidth > 500; const { width: legendWdith, height: legendHeight } = useParentSize(legendRef, { debounceDelay: 50 }); const { width: chartWidth, height: chartHeight } = useParentSize(chartRef, { debounceDelay: 50 }); return (
    {[ { url: Urls.Covid19, text: 'Daily increase in deaths (Scotland)', }, { url: Urls.IncreaseInDeaths, text: 'Daily increase in deaths (World)', }, // { // url: Urls.RateOfChange, // text: 'Rate of change', // }, // { url: Urls.Deaths, text: 'Total deaths' }, ].map((u) => { if (location.pathname === u.url) { return
  • {u.text}
  • ; } return (
  • {u.text}
  • ); })}
{ if (location.pathname !== Urls.Covid19) { return true; } return ['SCO'].includes(k); }) .map((k) => ({ name: countryData[k as Countries].longName, symbol: { fill: countryData[k as Countries].color }, }))} />
{typeof result?.data === 'undefined' ? ( ) : ( {/* eslint-disable-next-line @typescript-eslint/no-explicit-any */} {Object.keys(result.data as any).map((k) => { assert(result.data?.[k as Countries], `No country data ${k}`); const country = result.data?.[k as Countries]; return ( } data={country?.data} > (['SCO'].includes(k) ? 7 : 3)} /> ); })} )}
); }; export default Graph;