-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathus-alt.html
269 lines (254 loc) · 10.9 KB
/
us-alt.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
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
<!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 in the United States</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/AltCovidData.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 by State in the United States
</a>
</div>
<div id="footerResponsive" class="navbar-collapse">
<ul class="navbar-nav">
<li class="nav-item active">
<a class="nav-link" href="#">Confirmed Cases <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="us-deaths.html">Deaths</a>
</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>Confirmed Cases By State</b><br/><span style="font-size:small;">Data <a href="https://coronadatascraper.com/timeseries-jhu.csv">pulled live</a> as of <span id="last_date"></span>.<br/>Click on a state name below to see state-level data.</span><p></p>
<div class="container-fluid" id="state_container">
<i>Loading...</i>
</div>
</div>
<div class="col-md-9 flex-grow-1;" style="background: #fff;">
<b>Confirmed 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 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(state_name) {
if (state_name != undefined) {
let active = d3.select("#legend-" + state_name.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://coronadatascraper.com/timeseries-jhu.csv").then(function(data) {
let numformat = d3.format(",");
let long_names = {
'AK': 'Alaska',
'AL': 'Alabama',
'AR': 'Arkansas',
'AS': 'American Samoa',
'AZ': 'Arizona',
'CA': 'California',
'CO': 'Colorado',
'CT': 'Connecticut',
'DC': 'Washington, DC',
'DE': 'Delaware',
'FL': 'Florida',
'GA': 'Georgia',
'GU': 'Guam',
'HI': 'Hawaii',
'IA': 'Iowa',
'ID': 'Idaho',
'IL': 'Illinois',
'IN': 'Indiana',
'KS': 'Kansas',
'KY': 'Kentucky',
'LA': 'Louisiana',
'MA': 'Massachusetts',
'MD': 'Maryland',
'ME': 'Maine',
'MI': 'Michigan',
'MN': 'Minnesota',
'MO': 'Missouri',
'MP': 'Northern Marianas',
'MS': 'Mississippi',
'MT': 'Montana',
'NC': 'North Carolina',
'ND': 'North Dakota',
'NE': 'Nebraska',
'NH': 'New Hampshire',
'NJ': 'New Jersey',
'NM': 'New Mexico',
'NV': 'Nevada',
'NY': 'New York',
'OH': 'Ohio',
'OK': 'Oklahoma',
'OR': 'Oregon',
'PA': 'Pennsylvania',
'PR': 'Puerto Rico',
'RI': 'Rhode Island',
'SC': 'South Carolina',
'SD': 'South Dakota',
'TN': 'Tennessee',
'TX': 'Texas',
'UT': 'Utah',
'VA': 'Virginia',
'VI': 'Virgin Islands',
'VT': 'Vermont',
'WA': 'Washington',
'WI': 'Wisconsin',
'WV': 'West Virginia',
'WY': 'Wyoming'
}
let us_state_data = data.filter(record => (record['country'] === 'USA') && (record['state'].length > 0) && (record['county'].length == 0) && (record['city'].length == 0));
us_state_data = us_state_data.map(record => {
if (long_names[record['state']] != undefined) {
record['Province/State'] = long_names[record['state']];
record['state'] = long_names[record['state']];
}
else {
record['Province/State'] = record['state'];
}
return record;
}
)
;
let covid_data = new CovidData(us_state_data, "");
covid_time_chart = new TimeChart(covid_data, "Nationwide");
// 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 state data table.
let state_data_div = d3.select("#state_container");
let _html = "<table>";
_html += "<tr onclick=\'legend_select(); covid_time_chart.toggle_total();\'><th style='padding-right: 15px;'>Nationwide</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:15; width: 15px;'><circle style='fill: #888888' cx='8' cy='6' r='5'></circle></svg></th></tr>";
let state_names = Object.keys(covid_data.regions).sort();
for (i=0; i<state_names.length; i++) {
_html += "<tr onclick='legend_select(\""+state_names[i]+"\"); covid_time_chart.select(\""+state_names[i]+"\");'><td style='font-size: small; padding-right: 15px;'>"+state_names[i]+"</td><td style='font-size: small;'>"+numformat(covid_data.regions[state_names[i]][covid_data.date_strings.length-1])+"</td><td><svg class='legend off' id='legend-"+state_names[i].replace(/ /g, '-')+"' style='vertical-align: middle; height:15; width: 15px;'><circle style='fill: #888888' cx='8' cy='6' r='3'></circle></svg></td></tr>";
}
_html += "</table>";
state_data_div.html(_html);
});
</script>
</body>
</html>