starting FreeBedsChartView
This commit is contained in:
86
docs/FreeBedsChartView.js
Normal file
86
docs/FreeBedsChartView.js
Normal file
@@ -0,0 +1,86 @@
|
||||
class FreeBedsChartView {
|
||||
|
||||
#canvas;
|
||||
#chart;
|
||||
|
||||
constructor(canvas) {
|
||||
this.#canvas = canvas;
|
||||
}
|
||||
|
||||
displayChart({ data, title }) {
|
||||
if (this.#chart != null) {
|
||||
this.#chart.destroy();
|
||||
}
|
||||
this.#chart = new Chart(
|
||||
this.#canvas,
|
||||
{
|
||||
type: 'line',
|
||||
data: this.#getData(data),
|
||||
options: this.#getOptions(title)
|
||||
});
|
||||
}
|
||||
|
||||
#getData(data) {
|
||||
return {
|
||||
datasets: [
|
||||
{
|
||||
label: 'Anteil freier Betten',
|
||||
data: data,
|
||||
parsing: {
|
||||
yAxisKey: 'free_beds_divided_by_all_beds'
|
||||
},
|
||||
backgroundColor: 'rgba(0, 255, 0, 1)'
|
||||
}
|
||||
]
|
||||
};
|
||||
}
|
||||
|
||||
#getOptions(title) {
|
||||
return {
|
||||
plugins: {
|
||||
title: {
|
||||
display: true,
|
||||
text: title
|
||||
},
|
||||
tooltip: {
|
||||
callbacks: {
|
||||
label: function (context) {
|
||||
let label = context.dataset.label || '';
|
||||
|
||||
if (label) {
|
||||
label += ': ';
|
||||
}
|
||||
if (context.parsed.y !== null) {
|
||||
label += context.parsed.y.toFixed(1) + "%";
|
||||
}
|
||||
return label;
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
responsive: true,
|
||||
scales: {
|
||||
x: {
|
||||
type: 'time',
|
||||
time: {
|
||||
unit: 'month'
|
||||
}
|
||||
},
|
||||
y: {
|
||||
// min: 0,
|
||||
// max: 100,
|
||||
title: {
|
||||
display: true,
|
||||
text: "Anteil freier Betten"
|
||||
},
|
||||
ticks: {
|
||||
callback: value => value + "%"
|
||||
}
|
||||
}
|
||||
},
|
||||
parsing: {
|
||||
xAxisKey: 'date'
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -29,7 +29,7 @@ class IntensiveCareCapacitiesChartView {
|
||||
parsing: {
|
||||
yAxisKey: 'betten_belegt'
|
||||
},
|
||||
backgroundColor: 'rgba(255, 0, 0, 1)',
|
||||
backgroundColor: 'rgba(255, 0, 0, 1)'
|
||||
},
|
||||
{
|
||||
label: 'Freie Betten',
|
||||
@@ -37,7 +37,7 @@ class IntensiveCareCapacitiesChartView {
|
||||
parsing: {
|
||||
yAxisKey: 'betten_frei'
|
||||
},
|
||||
backgroundColor: 'rgba(0, 255, 0, 1)',
|
||||
backgroundColor: 'rgba(0, 255, 0, 1)'
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta content="width=device-width, initial-scale=1.0" name="viewport" />
|
||||
@@ -10,12 +11,49 @@
|
||||
<script src="https://cdn.jsdelivr.net/npm/chartjs-adapter-moment@^1"></script>
|
||||
<script src="./UIUtils.js"></script>
|
||||
<script src="./IntensiveCareCapacitiesChartView.js"></script>
|
||||
<script src="./FreeBedsChartView.js"></script>
|
||||
<script src="./intensivstationen.js"></script>
|
||||
<script>
|
||||
const labels = [
|
||||
'January',
|
||||
'February',
|
||||
'March',
|
||||
'April',
|
||||
'May',
|
||||
'June',
|
||||
];
|
||||
|
||||
const data = {
|
||||
labels: labels,
|
||||
datasets: [{
|
||||
label: 'My First dataset',
|
||||
backgroundColor: 'rgb(255, 99, 132)',
|
||||
borderColor: 'rgb(255, 99, 132)',
|
||||
data: [0, 10, 5, 2, 20, 30, 45],
|
||||
}]
|
||||
};
|
||||
|
||||
const config = {
|
||||
type: 'line',
|
||||
data: data,
|
||||
options: {}
|
||||
};
|
||||
|
||||
document.addEventListener(
|
||||
"DOMContentLoaded",
|
||||
event => {
|
||||
//const myChart = new Chart(
|
||||
// document.getElementById('myChart'),
|
||||
// config
|
||||
//);
|
||||
});
|
||||
</script>
|
||||
<script>
|
||||
document.addEventListener(
|
||||
"DOMContentLoaded",
|
||||
event => {
|
||||
const intensiveCareCapacitiesChartView = new IntensiveCareCapacitiesChartView(document.querySelector(".canvas"));
|
||||
const freeBedsChartView = new FreeBedsChartView(document.getElementById('myChart'));
|
||||
document.querySelector('#kreisSelect').addEventListener(
|
||||
'change',
|
||||
event => {
|
||||
@@ -28,6 +66,14 @@
|
||||
kreisText: selectedOption.text,
|
||||
kreisValue: selectedOption.value
|
||||
});
|
||||
fetch(`data/intensivstationen/intensivstationen-${selectedOption.value}.json`)
|
||||
.then(response => response.json())
|
||||
.then(json => {
|
||||
for (const dataElement of json.data) {
|
||||
dataElement.free_beds_divided_by_all_beds = dataElement.betten_frei / (dataElement.betten_frei + dataElement.betten_belegt) * 100;
|
||||
}
|
||||
freeBedsChartView.displayChart({ data: json.data, title: selectedOption.text });
|
||||
});
|
||||
});
|
||||
displayIntensiveCareCapacitiesChart(
|
||||
{
|
||||
@@ -37,6 +83,14 @@
|
||||
kreisText: 'Alle Landkreise',
|
||||
kreisValue: 'de'
|
||||
});
|
||||
fetch(`data/intensivstationen/intensivstationen-de.json`)
|
||||
.then(response => response.json())
|
||||
.then(json => {
|
||||
for (const dataElement of json.data) {
|
||||
dataElement.free_beds_divided_by_all_beds = dataElement.betten_frei / (dataElement.betten_frei + dataElement.betten_belegt) * 100;
|
||||
}
|
||||
freeBedsChartView.displayChart({ data: json.data, title: 'Alle Landkreise' });
|
||||
});
|
||||
});
|
||||
|
||||
function getSelectedOption(select) {
|
||||
@@ -44,6 +98,7 @@
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<span id="forkongithub"><a href="https://github.com/KnollFrank/HowBadIsMyBatch">Fork me on GitHub</a></span>
|
||||
<h1>DIVI-Intensivregister auf Landkreisebene</h1>
|
||||
@@ -452,5 +507,9 @@
|
||||
<dt>Datenstand:</dt>
|
||||
<dd id="Datenstand">12.03.2022, 12:38 Uhr</dd>
|
||||
</dl>
|
||||
<p>
|
||||
<canvas id="myChart"></canvas>
|
||||
</p>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
Reference in New Issue
Block a user