-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
151 lines (146 loc) · 3.91 KB
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
console.log("hi");
var covid_data;
var values;
var states = [
"Andaman Nicobar",
"Andhra Pradesh",
"Arunachal Pradesh",
"Assam",
"Bihar",
"Chandigarh",
"Chattisgarh",
"Dadra and Nagar Haveli",
"Delhi",
"Goa",
"Gujarat",
"Haryana",
"Himachal Pradesh",
"Jammu and Kashmir",
"Jharkhand",
"Karnataka",
"Kerala",
"Ladakh",
"Lakshadweep Islands",
"Madhya Pradesh",
"Maharashtra",
"Manipur",
"Meghalaya",
"Mizoram",
"Nagaland",
"Odisha",
"Pondicherry",
"Punjab",
"Rajasthan",
"Sikkim",
"Tamil Nadu",
"Telangana",
"Tripura",
"Uttar Pradesh",
"Uttarakhand",
"West Bengal",
];
async function get_data() {
const response = await fetch(
"https://data.covid19india.org/v4/min/data.min.json"
);
console.log(response);
covid_data = await response.json();
console.log(covid_data);
return covid_data;
}
var a = get_data();
a.then((data) => start(data));
function start(keyData) {
values = Object.keys(keyData);
for (var i = 0; i < states.length; i++)
document.getElementById(
"place"
).innerHTML += `<option value=${values[i]}>${states[i]}</option>`;
}
var showBtn = document.getElementById("show");
var covid_figures = [];
showBtn.addEventListener("click", () => {
c.clearRect(0, 0, can.width, can.height);
// console.log(document.getElementById('place').value);
var key = document.getElementById("place").value;
covid_figures[0] = covid_data[key].total.tested;
covid_figures[1] = covid_data[key].total.confirmed;
covid_figures[2] = covid_data[key].total.recovered;
covid_figures[3] = covid_data[key].total.vaccinated1;
covid_figures[4] = covid_data[key].total.vaccinated2;
covid_figures[5] = covid_data[key].total.deceased;
// console.log(covid_figures);
calculation();
});
// var tested_ratio;
// var confirmed_ratio;
// var recovered_ratio;
// var vaccinated1_ratio;
// var vaccinated2_ratio;
// var deceased_ratio;
var ratio = [];
function calculation() {
var max = 0;
for (var i = 0; i <= 5; i++) {
if (covid_figures[i] > max) {
max = covid_figures[i];
}
}
// tested_ratio=covid_figures[0]/sum;
// confirmed_ratio=covid_figures[1]/sum;
// recovered_ratio=covid_figures[2]/sum;
// vaccinated1_ratio=covid_figures[3]/sum;
// vaccinated2_ratio=covid_figures[4]/sum;
// deceased_ratio=covid_figures[5]/sum;
ratio[0] = covid_figures[0] / max;
ratio[1] = covid_figures[1] / max;
ratio[2] = covid_figures[2] / max;
ratio[3] = covid_figures[3] / max;
ratio[4] = covid_figures[4] / max;
ratio[5] = covid_figures[5] / max;
document.getElementById(
"Tested"
).innerHTML = `TESTED:<br>${covid_figures[0]}`;
document.getElementById(
"Confirmed"
).innerHTML = `CONFIRMED:<br>${covid_figures[1]}`;
document.getElementById(
"Recovered"
).innerHTML = `RECOVERED:<br>${covid_figures[2]}`;
document.getElementById(
"Vaccinated1"
).innerHTML = `VACCINATED 1:<br>${covid_figures[3]}`;
document.getElementById(
"Vaccinated2"
).innerHTML = `VACCINATED 2:<br>${covid_figures[4]}`;
document.getElementById(
"Deceased"
).innerHTML = `DECEASED:<br>${covid_figures[5]}`;
draw();
}
var animation_ratio = 0;
var colors = ["blue", "orange", "green", "pink", "purple", "red"];
var can = document.getElementById("canvas");
// can.width=window.innerWidth;
// can.height=window.innerHeight-400;
// console.log(can.width,can.height);
c = can.getContext("2d");
function draw() {
if (animation_ratio < 100) {
id = requestAnimationFrame(draw);
++animation_ratio;
} else {
animation_ratio = 0;
}
var rel = can.width / 11;
for (i = 0; i < 6; i++) {
c.fillStyle = colors[i];
c.fillRect(
rel * 2 * i,
can.height,
rel,
-(can.height * ratio[i]) * (animation_ratio / 100)
);
// console.log(colors[i]);
}
}