-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathworld-deaths.html
251 lines (232 loc) · 11.9 KB
/
world-deaths.html
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
241
242
243
244
245
246
247
248
249
250
251
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<style>
.on {
visibility: visible;
}
.off {
visibility: hidden;
}
.d3-tip {
line-height: 1;
padding: 6px;
background: rgba(0, 0, 0, 0.8);
color: #fff;
border-radius: 4px;
font-size: 12px;
}
/* Creates a small triangle extender for the tooltip */
.d3-tip:after {
box-sizing: border-box;
display: inline;
font-size: 10px;
width: 100%;
line-height: 1;
color: rgba(0, 0, 0, 0.8);
content: "\25BC";
position: absolute;
text-align: center;
}
/* Style northward tooltips specifically */
.d3-tip.n:after {
margin: -2px 0 0 0;
top: 100%;
left: 0;
}
</style>
<title>COVID-19 Around the World</title>
<link rel="stylesheet" href="css/bootstrap.min.css" crossorigin="anonymous"/>
<script src="js/jquery-3.4.1.min.js" crossorigin="anonymous"></script>
<script src="js/bootstrap.bundle.min.js" crossorigin="anonymous"></script>
<script src="js/d3.min.js" crossorigin="anonymous"></script>
<script src="js/d3-tip.js" crossorigin="anonymous"></script>
<script src="js/CovidDataCountry.js" crossorigin="anonymous"></script>
<script src="js/TimeChart.js" crossorigin="anonymous"></script>
<script src="js/ResizeObserver.js" crossorigin="anonymous"></script>
<script src="js/regression.js" crossorigin="anonymous"></script>
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-32250702-3"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-32250702-3');
</script>
</head>
<body style="">
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<div class="container-fluid" style="padding:0;">
<div class="navbar-header">
<a class="navbar-brand" href="#">
COVID-19 Growth Charts
</a>
</div>
<div id="footerResponsive" class="navbar-collapse">
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link" href="index.html">About</a>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Worldwide
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
<a class="nav-link" href="world.html">Confirmed Cases <span class="sr-only">(current)</span></a>
<a class="nav-link" href="world-deaths.html">Deaths</a>
</div>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
United States
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
<a class="nav-link" href="us.html">Confirmed Cases <span class="sr-only">(current)</span></a>
<a class="nav-link" href="us-deaths.html">Deaths</a>
</div>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
North Carolina
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
<a class="nav-link" href="nc.html">Confirmed Cases <span class="sr-only">(current)</span></a>
<a class="nav-link" href="nc-deaths.html">Deaths</a>
</div>
</li>
</ul>
</div>
<ul class="nav navbar-nav navbar-right">
<li><a href="http://vaclab.unc.edu/"><img style="width: 192px;" src="vaclab_logo.svg"></a></li>
</ul>
</div>
</nav>
<div class="container-fluid">
<div class="row">
<div class="col-md-3" style="background: #fff;">
<b>Deaths By Country</b><br/><span style="font-size:small;">Data <a href="https://github.com/CSSEGISandData/COVID-19/blob/master/csse_covid_19_data/csse_covid_19_time_series/time_series_covid19_deaths_global.csv">pulled live</a> as of <span id="last_date"></span>. Be sure to read <a href="index.html">the fine print about limitations</a>.<br/>Click on a country name below to see country-level data.</span><p></p>
<div class="container-fluid" id="country_container">
<i>Loading...</i>
</div>
</div>
<div class="col-md-9 flex-grow-1;" style="background: #fff;">
<b>Deaths Cases Over Time</b>
<br/>
<button type="button" id='linearbtn' class="btn btn-primary btn-sm" onclick="{
$('#linearbtn').addClass('btn-primary');
$('#linearbtn').removeClass('btn-secondary');
$('#logbtn').addClass('btn-secondary');
$('#logbtn').removeClass('btn-primary');
covid_time_chart.use_log_scale(false);
}">Linear Scale</button>
<button type="button" id='logbtn' class="btn btn-secondary btn-sm" onclick="{
$('#linearbtn').addClass('btn-secondary');
$('#linearbtn').removeClass('btn-primary');
$('#logbtn').addClass('btn-primary');
$('#logbtn').removeClass('btn-secondary');
covid_time_chart.use_log_scale(true);
}">Log Scale</button>
<div style="float: right;">
<button type="button" id='todaymodelbtn' class="btn btn-primary btn-sm" onclick="{
$('#oldmodelbtn').addClass('btn-secondary');
$('#oldmodelbtn').removeClass('btn-primary');
$('#todaymodelbtn').addClass('btn-primary');
$('#todaymodelbtn').removeClass('btn-secondary');
covid_time_chart.use_old_model(false);
}">Latest Model</button>
<button type="button" id='oldmodelbtn' class="btn btn-secondary btn-sm" onclick="{
$('#oldmodelbtn').addClass('btn-primary');
$('#oldmodelbtn').removeClass('btn-secondary');
$('#todaymodelbtn').addClass('btn-secondary');
$('#todaymodelbtn').removeClass('btn-primary');
covid_time_chart.use_old_model(true);
}">Model from 3 Days Ago</button>
</div>
<div class="row flex-grow-1" id="time_chart_container"> </div>
<div>* The 'forecast' shown on this page is just a simple extrapolation from the best-fit exponential
model derived from the historical data shown in the visualization. This is obviously a VAST
simplification of the underlying process. Any serious analysis would need to adopt much more rigorous
epidemiological models.
</div>
</div>
</div>
</div>
<div class="row">
<div style="margin-top: 15px; border-top: 1px solid lightgray; text-align: center; font-size: small; width: 100%;" class="col-md-12 flex-grow-1">
<br/><a href="http://vaclab.unc.edu/"><img style="width: 200px;" src="vaclab_logo.svg"></a>
<br/>
This project is available as open source via <a href="https://github.com/VACLab/covid/">the VACLab GitHub repository</a>.
</div>
</div>
<script>
function legend_select(country_name) {
if (country_name != undefined) {
let active = d3.select("#legend-" + country_name.replace(/ /g, '-').replace(/,/g, '-'));
if (active.classed('on')) {
active.classed('off', true);
active.classed('on', false);
}
else {
active.classed('on', true);
active.classed('off', false);
}
}
else {
// This means they clicked the total label.
let active = d3.select("#legend-total");
if (active.classed('on')) {
active.classed('off', true);
active.classed('on', false);
}
else {
active.classed('on', true);
active.classed('off', false);
}
}
}
d3.csv("https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_covid19_deaths_global.csv").then(function(data) {
let numformat = d3.format(",");
country_data = data.filter(record => (record['Province/State'].indexOf(',') == -1));
let country_groups = d3.nest()
.key(d => d['Country/Region'])
.rollup(subregions => {
agg_data_for_country = subregions[0];
// Empty out the province/state data, as well as lat/long data.
agg_data_for_country['Province/State'] = '';
agg_data_for_country['Lat'] = '';
agg_data_for_country['Long'] = '';
// Get all dates. We assume that this means all object properties that start with a number.
let dates = Object.keys(agg_data_for_country).filter(prop => ((prop.charAt(0) >= '0') && (prop.charAt(0) <= '9')) );
// First, convert current agg_data object to numbers.
for (let i=0; i<dates.length; i++) {
agg_data_for_country[dates[i]] = +agg_data_for_country[dates[i]]
}
// Now aggregate any remaining subregions.
for (let r=1; r<subregions.length; r++) {
for (let i=0; i<dates.length; i++) {
agg_data_for_country[dates[i]] += (+subregions[r][dates[i]])
}
}
return agg_data_for_country;
})
.entries(country_data);
let covid_data = new CovidDataCountry(country_groups.map(record => record.value));
covid_time_chart = new TimeChart(covid_data, "Global", "deaths");
// Populate last date
let last_date_span = d3.select("#last_date");
last_date_span.html(covid_data.date_strings[covid_data.date_strings.length-1]);
// Populate country data table.
let country_data_div = d3.select("#country_container");
let _html = "<table>";
_html += "<tr onclick=\'legend_select(); covid_time_chart.toggle_total();\'><th style='padding-right: 15px;'>Global</th><th>"+numformat(covid_data.totals[covid_data.totals.length-1])+"</th><th><svg class='legend on' id='legend-total' style='vertical-align: middle; height:15px; width: 15px;'><circle style='fill: #888888' cx='8' cy='6' r='5'></circle></svg></th></tr>";
let country_names = Object.keys(covid_data.regions).sort();
for (i=0; i<country_names.length; i++) {
_html += "<tr onclick='legend_select(\""+country_names[i]+"\"); covid_time_chart.select(\""+country_names[i]+"\");'><td style='font-size: small; padding-right: 15px;'>"+country_names[i]+"</td><td style='font-size: small;'>"+numformat(covid_data.regions[country_names[i]][covid_data.date_strings.length-1])+"</td><td><svg class='legend off' id='legend-"+country_names[i].replace(/ /g, '-').replace(/,/g, '-')+"' style='vertical-align: middle; height:15px; width: 15px;'><circle style='fill: #888888' cx='8' cy='6' r='3'></circle></svg></td></tr>";
}
_html += "</table>";
country_data_div.html(_html);
});
</script>
</body>
</html>