-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathvisualization.js
More file actions
240 lines (220 loc) · 5.06 KB
/
visualization.js
File metadata and controls
240 lines (220 loc) · 5.06 KB
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
// COVID-19 Simulation Tool in JavaScript
// Copyright 2020 Savithru Jayasinghe and Dushan Wadduwage
// Licensed under the MIT License (LICENSE.txt)
'use strict';
var date_format = 'YYYY-MM-DD';
var country_data;
var district_data;
//Chart objects
var country_chart;
var district_chart;
var countries_to_plot = ['Sri Lanka', 'United States', 'United Kingdom', 'India',
'Pakistan','China', 'Singapore', 'Japan', 'Brazil', 'Spain', 'Italy',
'Oman','Thailand'];
window.onload = function()
{
loadCountryData();
setupCountryChart();
setupDistrictChart();
}
function loadCountryData()
{
let case_threshold = 100;
country_data = [];
for (let country_name of Object.keys(world_data))
{
let data_array = world_data[country_name];
let processed_data = [];
let start_date = null;
for (let data of data_array)
{
if (data.confirmed >= case_threshold)
{
if (start_date == null)
start_date = moment(data.date, date_format);
let current_date = moment(data.date, date_format);
let t_elapsed = current_date.diff(start_date, 'days');
processed_data.push({x:t_elapsed, y: data.confirmed});
}
}
if (country_name == 'US')
country_name = 'United States';
country_data[country_name] = processed_data;
}
}
function setupCountryChart()
{
let chart_element = document.getElementById('chart_country');
let dataseries_vec = [];
let xmax = 0;
for (let country_name of countries_to_plot)
{
let data_hist = country_data[country_name];
dataseries_vec.push({
name: country_name,
data: data_hist
});
xmax = Math.max(xmax, data_hist[data_hist.length-1].x);
}
var options = {
chart: {
type: 'line',
animations: {
enabled: true,
easing: 'easeinout',
speed: 500,
animateGradually: {
enabled: false,
},
dynamicAnimation: {
enabled: true,
speed: 350
}
}
},
series: dataseries_vec,
xaxis: {
type: 'numeric',
title: {
text: 'No. of days elapsed since 100 cases',
style: {
fontSize: "16px",
color: '#666'
},
offsetY: 10
},
},
yaxis: {
logarithmic: true,
title: {
text: 'No. of cases',
style: {
fontSize: "16px",
color: '#666',
},
},
},
legend: {
offsetY: 15,
position: 'right'
},
grid: {
xaxis: {
lines: {
show: true
}
},
yaxis: {
lines: {
show: true
}
}
},
colors: ['#1f78b4','#a6cee3','#b2df8a','#33a02c','#fb9a99','#e31a1c',
'#fdbf6f','#ff7f00','#cab2d6','#6a3d9a','#b15928','#ffff99',
'#9665c7'],
fill: {
type: 'solid'
},
stroke: {
width: 1.5,
curve: 'smooth',
},
}
country_chart = new ApexCharts(chart_element, options);
country_chart.render();
};
function setupDistrictChart()
{
let chart_element = document.getElementById('chart_district');
let dataseries_vec = [];
// let districts = ['Colombo','Gampaha','Jaffna'];
for (let district_name of Object.keys(SL_district_data))
{
dataseries_vec.push({
name: district_name,
data: SL_district_data[district_name]
});
}
let yaxis_log = document.querySelector('input[name="plot_yaxis_type"]:checked').value == 'logarithmic';
var options = {
chart: {
type: 'line',
animations: {
enabled: true,
easing: 'easeinout',
speed: 500,
animateGradually: {
enabled: false,
},
dynamicAnimation: {
enabled: true,
speed: 350
}
}
},
series: dataseries_vec,
xaxis: {
type: 'datetime',
title: {
text: 'Date',
style: {
fontSize: "16px",
color: '#666'
},
offsetY: 10
},
},
yaxis: {
logarithmic: yaxis_log,
title: {
text: 'No. of cases',
style: {
fontSize: "16px",
color: '#666',
},
},
},
legend: {
offsetY: 15,
position: 'right'
},
grid: {
xaxis: {
lines: {
show: true
}
},
yaxis: {
lines: {
show: true
}
}
},
colors: ['#1f78b4','#a6cee3','#b2df8a','#33a02c','#fb9a99','#e31a1c',
'#fdbf6f','#ff7f00','#cab2d6','#6a3d9a','#b15928','#ffff99',
'#9665c7'],
fill: {
type: 'solid'
},
stroke: {
width: 1.5,
curve: 'smooth',
},
tooltip: {
enabled: true,
shared: false
}
}
district_chart = new ApexCharts(chart_element, options);
district_chart.render();
};
function updateYAxisType()
{
let yaxis_log = document.querySelector('input[name="plot_yaxis_type"]:checked').value == 'logarithmic';
district_chart.updateOptions({
yaxis: {
logarithmic: yaxis_log,
}
});
}