refactoring
This commit is contained in:
@@ -36,14 +36,11 @@
|
|||||||
kreisText: selectedOption.text,
|
kreisText: selectedOption.text,
|
||||||
kreisValue: selectedOption.value
|
kreisValue: selectedOption.value
|
||||||
});
|
});
|
||||||
// FK-TODO: extract method
|
displayFreeBedsChart(
|
||||||
fetch(`data/intensivstationen/intensivstationen-${selectedOption.value}.json`)
|
{
|
||||||
.then(response => response.json())
|
freeBedsChartView: freeBedsChartView,
|
||||||
.then(json => {
|
kreisText: selectedOption.text,
|
||||||
for (const dataElement of json.data) {
|
kreisValue: selectedOption.value
|
||||||
dataElement.free_beds_divided_by_all_beds_in_percent = dataElement.betten_frei / (dataElement.betten_frei + dataElement.betten_belegt) * 100;
|
|
||||||
}
|
|
||||||
freeBedsChartView.displayChart({ data: json.data, title: selectedOption.text });
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -9,3 +9,24 @@ function displayIntensiveCareCapacitiesChart(
|
|||||||
intensiveCareCapacitiesChartView.displayChart({ data: json.data, title: kreisText });
|
intensiveCareCapacitiesChartView.displayChart({ data: json.data, title: kreisText });
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function displayFreeBedsChart({ freeBedsChartView, kreisText, kreisValue }) {
|
||||||
|
fetch(`data/intensivstationen/intensivstationen-${kreisValue}.json`)
|
||||||
|
.then(response => response.json())
|
||||||
|
.then(json =>
|
||||||
|
freeBedsChartView.displayChart(
|
||||||
|
{
|
||||||
|
data: get_free_beds_divided_by_all_beds_in_percent(json.data),
|
||||||
|
title: kreisText
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
function get_free_beds_divided_by_all_beds_in_percent(data) {
|
||||||
|
return data.map(({ date, betten_frei, betten_belegt }) =>
|
||||||
|
(
|
||||||
|
{
|
||||||
|
"date": date,
|
||||||
|
"free_beds_divided_by_all_beds_in_percent": betten_frei / (betten_frei + betten_belegt) * 100
|
||||||
|
}
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user