Skip to content

Commit 07f7218

Browse files
committed
Finished Vaccination Tracker app.
1 parent 1a8ba0a commit 07f7218

File tree

2 files changed

+37
-24
lines changed

2 files changed

+37
-24
lines changed

Greece-Vaccination-Tracker/app.js

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,30 +58,43 @@ async function getVaccinationData() {
5858
}
5959
);
6060
const initialData = await response.json();
61-
console.log(initialData);
62-
61+
6362
const ctx = document.getElementById('vaccinations-chart').getContext('2d');
6463
const data = await calculateTotalVaccinations(initialData);
6564
const data2 = await calculateTotalVaccinationsDose1(initialData);
6665

6766
await animate(data, data2, 'Total Vaccinations', 'Total Vaccinations Dose 1')
68-
// todo group vaccinations by day and add x and y property on the data passed to the animatee function
69-
// todo of the vaccination-progressive-line.js module
7067
const myChart = new Chart(ctx, config);
7168
}
7269

7370
async function calculateTotalVaccinations(data) {
7471
const vaccinations = [];
7572

76-
data.forEach(element => {
77-
vaccinations.push(element.totalvaccinations);
78-
});
73+
for(let i=0;i<data.length/74;i++) {
74+
let currentData = data.slice(i*74, (i+1)*74);
75+
let currentSum = 0;
76+
currentData.forEach(item => {
77+
currentSum += item.totalvaccinations;
78+
});
79+
vaccinations.push(currentSum);
80+
}
7981

8082
return vaccinations;
8183
}
8284

8385
async function calculateTotalVaccinationsDose1(data) {
86+
const vaccinations = [];
8487

88+
for(let i=0;i<data.length/74;i++) {
89+
let currentData = data.slice(i*74, (i+1)*74);
90+
let currentSum = 0;
91+
currentData.forEach(item => {
92+
currentSum += item.totaldose1;
93+
});
94+
vaccinations.push(currentSum);
95+
}
96+
97+
return vaccinations;
8598
}
8699

87100
function main() {

Greece-Vaccination-Tracker/vaccination-progressive-line.js

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,10 @@
33
let config = {}
44

55
function animate(data, data2, label, label2) {
6-
data = [];
7-
data2 = [];
8-
let prev = 100;
9-
let prev2 = 80;
10-
for (let i = 0; i < 1000; i++) {
11-
prev += 5 - Math.random() * 10;
12-
data.push({x: i, y: prev});
13-
prev2 += 5 - Math.random() * 10;
14-
data2.push({x: i, y: prev2});
15-
}
6+
for (let i = 0; i < data.length; i++) {
7+
data[i] = {x:i, y: data[i]};
8+
data2[i] = {x:i, y: data2[i]};
9+
}
1610

1711
const totalDuration = 10000;
1812
const delayBetweenPoints = totalDuration / data.length;
@@ -45,21 +39,21 @@ function animate(data, data2, label, label2) {
4539
}
4640
}
4741
};
48-
42+
4943
config = {
5044
type: 'line',
5145
data: {
5246
datasets: [{
53-
label: 'Dataset 1',
47+
label: label,
5448
borderColor: '#2e82cc',
55-
borderWidth: 2,
49+
borderWidth: 3,
5650
radius: 0,
5751
data: data,
5852
},
5953
{
60-
label: 'Dataset 2',
54+
label: label2,
6155
borderColor: '#e8fbfe',
62-
borderWidth: 2,
56+
borderWidth: 3,
6357
radius: 0,
6458
data: data2,
6559
}]
@@ -76,8 +70,14 @@ function animate(data, data2, label, label2) {
7670
},
7771
scales: {
7872
x: {
79-
type: 'linear'
80-
}
73+
type: 'linear',
74+
},
75+
xAxes: {
76+
title: {
77+
display: true,
78+
text: 'Days since vaccination started',
79+
}
80+
}
8181
}
8282
}
8383
};

0 commit comments

Comments
 (0)