This repository has been archived by the owner on Nov 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(COR-1705): Infection Radar graph (#4844)
* feat(COR-1705): Added the redirects and first parts of the graph * feat(COR-1705): Second graph implemented * feat(COR-1705): Finalized the graph settings * feat(COR-1705): PR comment resolution * feat(COR-1705): PR contingency work * feat(COR-1705): Corrected import for infection-radar-per-age-group * feat(COR-1705): Fixed key mutations issues * feat(COR-1705): Lokalize key issue fix * feat(COR-1705): PR comment resolution * feat(COR-1705): Added timeline series for the Infection Radar graph * feat(COR-1705): key-mutations updated * feat(COR-1705): Added Lokalize keys * feat(COR-1705): Deleted batch of keys that don't show up in CMS * feat(COR-1705): Screenreader key update
- Loading branch information
1 parent
48d1fc2
commit 089307c
Showing
15 changed files
with
348 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
packages/app/schema/nl/infectionradar_symptoms_trend_per_age_group_weekly.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-07/schema#", | ||
"title": "nl_infectionradar_symptoms_trend_per_age_group_weekly", | ||
"type": "object", | ||
"properties": { | ||
"values": { | ||
"type": "array", | ||
"items": { | ||
"$ref": "#/definitions/value" | ||
} | ||
}, | ||
"last_value": { | ||
"$ref": "#/definitions/value" | ||
} | ||
}, | ||
"required": ["values", "last_value"], | ||
"additionalProperties": false, | ||
"definitions": { | ||
"value": { | ||
"title": "nl_infectionradar_symptoms_trend_per_age_group_weekly_value", | ||
"type": "object", | ||
"properties": { | ||
"date_of_insertion_unix": { | ||
"type": "integer" | ||
}, | ||
"date_of_report_unix": { | ||
"type": "integer" | ||
}, | ||
"date_start_unix": { | ||
"type": "integer" | ||
}, | ||
"date_end_unix": { | ||
"type": "integer" | ||
}, | ||
"percentage_0_24": { | ||
"type": "number" | ||
}, | ||
"percentage_25_39": { | ||
"type": "number" | ||
}, | ||
"percentage_40_49": { | ||
"type": "number" | ||
}, | ||
"percentage_50_59": { | ||
"type": "number" | ||
}, | ||
"percentage_60_69": { | ||
"type": "number" | ||
}, | ||
"percentage_70_plus": { | ||
"type": "number" | ||
}, | ||
"percentage_average": { | ||
"type": "number" | ||
} | ||
}, | ||
"required": [ | ||
"date_of_insertion_unix", | ||
"date_of_report_unix", | ||
"date_start_unix", | ||
"date_end_unix", | ||
"percentage_0_24", | ||
"percentage_25_39", | ||
"percentage_40_49", | ||
"percentage_50_59", | ||
"percentage_60_69", | ||
"percentage_70_plus", | ||
"percentage_average" | ||
], | ||
"additionalProperties": false | ||
} | ||
} | ||
} |
97 changes: 97 additions & 0 deletions
97
packages/app/src/domain/infection_radar/infection-radar-per-age-group.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
import { NlInfectionradarSymptomsTrendPerAgeGroupWeeklyValue, TimeframeOption } from '@corona-dashboard/common'; | ||
import { Spacer } from '~/components/base'; | ||
import { ErrorBoundary } from '~/components/error-boundary'; | ||
import { InteractiveLegend, SelectOption } from '~/components/interactive-legend'; | ||
import { TimeSeriesChart } from '~/components/time-series-chart'; | ||
import { TimelineEventConfig } from '~/components/time-series-chart/components/timeline'; | ||
import { TooltipSeriesList } from '~/components/time-series-chart/components/tooltip/tooltip-series-list'; | ||
import { LineSeriesDefinition } from '~/components/time-series-chart/logic'; | ||
import { useIntl } from '~/intl'; | ||
import { SiteText } from '~/locale'; | ||
import { space } from '~/style/theme'; | ||
import { getBoundaryDateStartUnix } from '~/utils/get-boundary-date-start-unix'; | ||
import { replaceVariablesInText } from '~/utils/replace-variables-in-text'; | ||
import { AccessibilityDefinition } from '~/utils/use-accessibility-annotations'; | ||
import { useBreakpoints } from '~/utils/use-breakpoints'; | ||
import { useList } from '~/utils/use-list'; | ||
import { BASE_SERIES_CONFIG } from './series-config'; | ||
|
||
interface InfectionRadarSymptomsPerAgeGroup { | ||
/** | ||
* The mandatory AccessibilityDefinition provides a reference to annotate the | ||
* graph with a label and description. | ||
*/ | ||
accessibility: AccessibilityDefinition; | ||
values: NlInfectionradarSymptomsTrendPerAgeGroupWeeklyValue[]; | ||
timeframe: TimeframeOption; | ||
timelineEvents?: TimelineEventConfig[]; | ||
text: SiteText['pages']['infection_radar_page']['nl']; | ||
} | ||
|
||
export function InfectionRadarSymptomsPerAgeGroup({ values, timeframe, accessibility, timelineEvents, text }: InfectionRadarSymptomsPerAgeGroup) { | ||
const { commonTexts } = useIntl(); | ||
const { list, toggle, clear } = useList<string>(); | ||
const breakpoints = useBreakpoints(true); | ||
|
||
const underReportedDateStart = getBoundaryDateStartUnix(values, 7); | ||
|
||
/* Enrich config with dynamic data / locale */ | ||
const seriesConfig: LineSeriesDefinition<NlInfectionradarSymptomsTrendPerAgeGroupWeeklyValue>[] = BASE_SERIES_CONFIG.map((baseAgeGroup) => { | ||
const label = baseAgeGroup.metricProperty in text.infected_per_age_group.legend ? text.infected_per_age_group.legend[baseAgeGroup.metricProperty] : baseAgeGroup.metricProperty; | ||
|
||
const ariaLabel = replaceVariablesInText(commonTexts.aria_labels.age_old, { | ||
age: label, | ||
}); | ||
|
||
return { | ||
...baseAgeGroup, | ||
hideInLegend: true, | ||
type: 'line', | ||
shape: 'style' in baseAgeGroup ? baseAgeGroup.style : 'line', | ||
label, | ||
ariaLabel, | ||
legendAriaLabel: ariaLabel, | ||
}; | ||
}); | ||
|
||
/** | ||
* Chart: | ||
* - when nothing selected: all items | ||
* - otherwise: selected items + always enabled items | ||
*/ | ||
const chartConfig = seriesConfig.filter((item) => list.includes(item.metricProperty) || list.length === 0); | ||
|
||
const interactiveLegendOptions: SelectOption[] = seriesConfig; | ||
|
||
/* Conditionally let tooltip span over multiple columns */ | ||
const hasTwoColumns = list.length === 0 || list.length > 4; | ||
|
||
return ( | ||
<ErrorBoundary> | ||
<InteractiveLegend helpText={text.infected_per_age_group.legend_help_text} selectOptions={interactiveLegendOptions} selection={list} onToggleItem={toggle} onReset={clear} /> | ||
<Spacer marginBottom={space[2]} /> | ||
<TimeSeriesChart | ||
forceLegend | ||
accessibility={accessibility} | ||
values={values} | ||
timeframe={timeframe} | ||
seriesConfig={chartConfig} | ||
minHeight={breakpoints.md ? 300 : 250} | ||
formatTooltip={(data) => <TooltipSeriesList data={data} hasTwoColumns={hasTwoColumns} />} | ||
dataOptions={{ | ||
isPercentage: true, | ||
valueAnnotation: text.infected_per_age_group.value_annotation, | ||
timespanAnnotations: [ | ||
{ | ||
start: underReportedDateStart, | ||
end: Infinity, | ||
label: text.infected_per_age_group.line_chart_legend_inaccurate_label, | ||
shortLabel: text.infected_per_age_group.tooltip_labels.inaccurate, | ||
}, | ||
], | ||
timelineEvents, | ||
}} | ||
/> | ||
</ErrorBoundary> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { colors } from '@corona-dashboard/common'; | ||
|
||
export const BASE_SERIES_CONFIG = [ | ||
{ | ||
metricProperty: 'percentage_0_24', | ||
color: colors.magenta1, | ||
}, | ||
{ | ||
metricProperty: 'percentage_25_39', | ||
color: colors.green3, | ||
}, | ||
{ | ||
metricProperty: 'percentage_40_49', | ||
color: colors.yellow3, | ||
}, | ||
{ | ||
metricProperty: 'percentage_50_59', | ||
color: colors.blue6, | ||
}, | ||
{ | ||
metricProperty: 'percentage_60_69', | ||
color: colors.orange1, | ||
}, | ||
{ | ||
metricProperty: 'percentage_70_plus', | ||
color: colors.magenta5, | ||
}, | ||
{ | ||
metricProperty: 'percentage_average', | ||
color: colors.gray5, | ||
style: 'dashed', | ||
}, | ||
] as const; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.