-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
472 lines (381 loc) · 17.5 KB
/
index.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
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
<!DOCTYPE html>
<html lang="en">
<head>
<title>COVID-19 USA DATA TRACKER</title>
<meta charset="utf-8">
<script src="https://d3js.org/d3.v4.min.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=0.86, maximum-scale=3.0, minimum-scale=0.86">
<style>
body {
margin: 0;
font: 11px sans-serif;
background-color: #ffffff;
background-image: url('img/COVID19.jpg');
background-repeat: no-repeat;
background-attachment: fixed;
background-size: 100% 100%;
}
.header h1 {
height: 10px;
top: 18px;
left: 10px;
}
/* Style the top navigation bar */
.topnav {
overflow: hidden;
background-color: #5a6ddc;
}
/* Style the topnav links */
.topnav a {
float: left;
display: block;
color: #f2f2f2;
text-align: center;
padding: 5px 12px;
text-decoration: none;
font-size: medium;
}
/* Change color on hover */
.topnav a:hover {
background-color: #ddd;
color: black;
}
.tooltip {
placement: auto;
position: absolute;
display:inline;
overflow:auto;
font-size: 15px;
width: auto;
height: auto;
pointer-events: none;
background-color: antiquewhite;
color: midnightblue;
padding: 0.3px;
}
/* Style the footer */
.footer {
background-color: #f1f1f1;
padding: 10px;
text-align: center;
}
.container{
position: center;
margin: 1px;
width: 100%;
}
</style>
</head>
<body>
<div class="header">
<h1 style="text-align:center;color:floralwhite;font-family:courier;font-size:250%">COVID-19 USA DATA TRACKER</h1>
</div>
<div class="body">
<div class="container">
<div class="topnav">
<a href="index.html"><b>MAP VIEW</b></a>
<a href="US_STATE_CASES_DEATHS.html"><b>STATE DATA</b></a>
<a href="Demographic.html"><b>DEMOGRAPHIC DATA</b></a>
<a href="CASES_DEATHS_TREND.html"><b>TREND DATA</b></a>
</div>
</div>
<p style="background-color:aliceblue;font-family:Helvetica Neue;font-size:130%" align="justify"><b style="color: purple;font-size: 18px">U.S. State Map Of COVID-19 Cases:</b><br>This map shows COVID-19 cases reported by U.S. states as of 07/15/2020. <b>Latest surge of COVID-19 cases increased the cumulative count in Texas , Arizona , Florida and Illinois as reflected on the map.</b> Hover over the maps to see the following details – a) number of cumulative cases, b) number of cumulative cases per 100k population, c) number of cumulative deaths and d) number of cumulative deaths per 100k population reported in each jurisdiction. Linear legend scale on the top-right side.</p>
<div id="my_dataviz" style="background-color:#f8f0e1;color:#202c42;padding:10px;border: 5px outset #08080e" >
</div>
<p style="background-color:aliceblue;font-family:Helvetica Neue;font-size:130%" align="justify"><b style="color: purple;font-size: 18px">U.S. County Map Of COVID-19 Cases:</b><br>This map shows COVID-19 cases reported by U.S. counties as of 07/15/2020. <b>High percentage of COVID-19 cases noticed in counties like Los Angeles(California), Maricopa(Arizona), Kings(New York), Queens(New York), Harris(Texas), Cook(Illinois) and Miami-Dade(Florida).</b><br> Hover over the maps to see the total number of cumulative cases in each county till the above-mentioned date. Legend scale on the top-right side shows the linear variation of total COVID-19 cases reported in U.S. states.</p>
<div id="my_dataviz1" style="background-color:#f8f0e1;color:#202c42;padding:10px;border: 5px outset #08080e" >
</div>
<br>
<footer>
<p style="background-color:aliceblue;font-family:Helvetica Neue;font-size:130%" align="justify">
<b>Reference:</b> For more information about COVID-19 disease please visit <a href="https://www.cdc.gov/coronavirus/2019-nCoV/index.html">https://www.cdc.gov/coronavirus/2019-nCoV/index.html</a>
<br>
<b>Data Courtesy:</b><a href="https://www.cdc.gov/"> https://www.cdc.gov/</a>
<br>
<b>Image Courtesy:</b><a href="https://phil.cdc.gov/Details.aspx?pid=23311"> https://phil.cdc.gov/Details.aspx?pid=23311</a>
<br>
<b>Viz creator:</b> Soumava Dey<br></p>
</footer>
</div>
<script type="text/javascript">
////////////////////////////////////// Beginning of USA Map code ///////////////////////////////////////////////////////
// Width and height of map
var width = 1000;
var height = 475;
// Set color level
var lowColor = '#7eee73'
var highColor = '#cb010f'
// D3 Projection for scaling the map in order to fit screen
var projection = d3.geoAlbersUsa()
.translate([width / 1.9, height / 2.1])
.scale([990]);
// Define path generator
var path = d3.geoPath()
.projection(projection);
//Create SVG element and append map to the SVG
var svg = d3.select("#my_dataviz")
.append("svg")
.attr("width", width)
.attr("height", height);
// Load in my states data
d3.csv("data/US_STATE.csv", function(data) {
var dataArray = [];
for (var d = 0; d < data.length; d++) {
dataArray.push(parseFloat(data[d].Total_Cases))
}
var minVal = d3.min(dataArray)
var maxVal = d3.max(dataArray)
var data_range = d3.scaleLinear().domain([minVal,maxVal]).range([lowColor,highColor])
var tooltip = d3.select("#my_dataviz").append("div")
.attr("class", "tooltip")
.style("opacity", 0);
// Load GeoJSON data and merge with states data source: https://eric.clst.org/assets/wiki/uploads/Stuff/gz_2010_us_040_00_500k.json
d3.json("json/us-states.json", function(json) {
// Loop through each state data value in the .csv file
for (var i = 0; i < data.length; i++) {
// Grab State Name
var dataState = data[i].state;
// Grab data value
var dataValue = data[i].value;
// Grab Deaths per 100k
var dataValue1 = data[i].Death_100k;
// Grab Total no. of Cases
var dataValue2 = data[i].Total_Cases;
// Grab Cases per 100000
var dataValue3 = data[i].RatePer100000;
// Find the corresponding state inside the GeoJSON
for (var j = 0; j < json.features.length; j++) {
var jsonState = json.features[j].properties.NAME;
if (dataState == jsonState) {
// Copy the data value into the JSON
json.features[j].properties.value = dataValue;
json.features[j].properties.death_100k = dataValue1;
json.features[j].properties.total_cases = dataValue2;
json.features[j].properties.cases_100k = dataValue3;
break;
}
}
}
// Bind the data to the SVG and create one path per GeoJSON feature
svg.selectAll("path")
.data(json.features)
.enter()
.append("path")
.attr("d", path)
.style("stroke", "#03243d")
.style("stroke-width", "1")
.style("fill", function(d) { return data_range(d.properties.total_cases) })
.on("mouseover", function(d) {
// Set html elements for the tooltip text
var html = "<span><b> State : </b><b>" + d.properties.NAME + "</b></span><br/>" +
"<span style='color:indianred'><b> Total Cases: </b>" + d.properties.total_cases + "</span></br>" +
"<span style='color:darkred'><b> Cases per 100k: </b>" + d.properties.cases_100k + "</span></br>" +
"<span style='color:red'><b> Total Deaths: </b>" + d.properties.value + "</span></br>" +
"<span style='color:palevioletred'><b> Deaths per 100k: </b>" + d.properties.death_100k + "</span></br>"
;
tooltip.html(html)
.style("left", (d3.event.pageX + 15) + "px")
.style("top", (d3.event.pageY - 28) + "px")
.transition()
.duration(200) // ms
.style("opacity", .9) // started as 0!
})
// fade out tooltip on mouse out
.on("mouseout", function(d) {
tooltip.transition()
.duration(500)
.style("opacity", 0);
});
// Text annotation for hover instruction
svg.append("text")
.attr("x",775)
.attr("y",350)
.attr("font-family","sans-serif")
.attr("font-size",10)
.style("fill", "red")
.style("text-decoration", "underline")
.text("Hover over the individual state map for details")
// add a legend
var l_w = 140, l_h = 500;
var key = d3.select("#my_dataviz")
.append("svg")
.attr("width", l_w)
.attr("height", l_h)
.attr("class", "legend");
var legend = key.append("defs")
.append("svg:linearGradient")
.attr("id", "gradient")
.attr("x1", "100%")
.attr("y1", "0%")
.attr("x2", "100%")
.attr("y2", "100%")
.attr("spreadMethod", "pad");
legend.append("stop")
.attr("offset", "0%")
.attr("stop-color", highColor)
.attr("stop-opacity", 1);
legend.append("stop")
.attr("offset", "100%")
.attr("stop-color", lowColor)
.attr("stop-opacity", 1);
key.append("rect")
.attr("width", l_w - 100)
.attr("height", l_h/2)
.style("fill", "url(#gradient)")
.attr("transform", "translate(49,0)");
key.append("text")
.attr("x",l_w - 140)
.attr("y",275)
.attr("font-family","sans-serif")
.attr("font-size",10)
.style("fill", "black")
.text("Total no. of Cases By State")
var y = d3.scaleLinear()
.range([l_h/2, 0])
.domain([0, maxVal]);
var yAxis = d3.axisRight(y);
key.append("g")
.attr("class", "y axis")
.attr("transform", "translate(90,0)")
.call(yAxis)
});
});
///////////////////////////////////////End of USA State Map code//////////////////////////////////////////////////////
////////////////////////////////////// Beginning of USA County Map code ///////////////////////////////////////////////////////
//Width and height of map
var width_county = 1000;
var height_county = 475;
//Set color range
var lowColor = '#d3f3cf'
var highColor = '#cb010f'
// D3 Projection for the U.S. county map
var projection_county = d3.geoAlbersUsa()
.translate([width_county / 1.9, height_county / 2.1])
.scale([990]);
// Define path generator
var path_county = d3.geoPath() // path generator that will convert GeoJSON to SVG paths
.projection(projection); // tell path generator to use albersUsa projection
//Create SVG element and append map to the SVG
var svg_county = d3.select("#my_dataviz1")
.append("svg")
.attr("width", width_county)
.attr("height", height_county);
// Load in my county data
d3.csv("data/US_COUNTY.csv", function(data) {
var dataArray = [];
for (var d = 0; d < data.length; d++) {
dataArray.push(parseFloat(data[d].Total_Cases))
}
var minVal = d3.min(dataArray)
//var midVal = (d3.max(dataArray) - d3.min(dataArray)) / 2
var maxVal = d3.max(dataArray)
var data_range = d3.scaleLinear().domain([minVal,maxVal]).range([lowColor,highColor])
var tooltip = d3.select("#my_dataviz1").append("div")
.attr("class", "tooltip")
.style("opacity", 0);
// Load GeoJSON data and merge with states data source : https://eric.clst.org/assets/wiki/uploads/Stuff/gz_2010_us_050_00_500k.json
d3.json("json/us-counties.json", function(json1) {
// Loop through each state data value in the .csv file
for (var i = 0; i < data.length; i++) {
// Grab County Name
var dataCounty = data[i].county;
// Grab StateID
var dataStateID = data[i].stateid;
// Grab data value
var dataValue_county = data[i].Total_Cases;
// Find the corresponding state inside the GeoJSON
for (var j = 0; j < json1.features.length; j++) {
var jsonCounty = json1.features[j].properties.NAME;
var jsonStateID = json1.features[j].properties.STATE;
if (dataCounty == jsonCounty && dataStateID == jsonStateID) {
// Copy the data value into the JSON
json1.features[j].properties.total_cases1 = dataValue_county;
// Stop looking through the JSON
break;
}
}
}
// Bind the data to the SVG and create one path per GeoJSON feature
svg_county.selectAll("path")
.data(json1.features)
.enter()
.append("path")
.attr("d", path)
.style("stroke", "#03243d")
.style("stroke-width", "1")
.style("fill", function(d) { return data_range(d.properties.total_cases1) })
.on("mouseover", function(d) {
var html = "<span><b> County : </b><b>" + d.properties.NAME + "</b></span><br/>" +
"<span style='color:indianred'><b> Total Cases: </b>" + d.properties.total_cases1 + "</span></br>"
;
tooltip.html(html)
.style("left", (d3.event.pageX + 15) + "px")
.style("top", (d3.event.pageY - 28) + "px")
.transition()
.duration(200) // ms
.style("opacity", .9) // started as 0!
})
// fade out tooltip on mouse out
.on("mouseout", function(d) {
tooltip.transition()
.duration(500)
.style("opacity", 0);
});
// Text annotation for hover instruction
svg_county.append("text")
.attr("x",765)
.attr("y",350)
.attr("font-family","sans-serif")
.attr("font-size",10)
.style("fill", "red")
.style("text-decoration", "underline")
.text("Hover over the individual county map for details")
// add a legend
var l_w = 140, l_h = 500;
var key = d3.select("#my_dataviz1")
.append("svg")
.attr("width", l_w)
.attr("height", l_h)
.attr("class", "legend");
var legend = key.append("defs")
.append("svg:linearGradient")
.attr("id", "gradient")
.attr("x1", "100%")
.attr("y1", "0%")
.attr("x2", "100%")
.attr("y2", "100%")
.attr("spreadMethod", "pad");
legend.append("stop")
.attr("offset", "0%")
.attr("stop-color", highColor)
.attr("stop-opacity", 1);
legend.append("stop")
.attr("offset", "100%")
.attr("stop-color", lowColor)
.attr("stop-opacity", 1);
key.append("rect")
.attr("width", l_w - 100)
.attr("height", l_h/2)
.style("fill", "url(#gradient)")
.attr("transform", "translate(49,0)");
key.append("text")
.attr("x",l_w - 140)
.attr("y",275)
.attr("font-family","sans-serif")
.attr("font-size",10)
.style("fill", "black")
.text("Total no. of Cases By County")
var y = d3.scaleLinear()
.range([l_h/2, 0])
.domain([0, maxVal]);
var yAxis = d3.axisRight(y);
key.append("g")
.attr("class", "y axis")
.attr("transform", "translate(90,0)")
.call(yAxis)
});
});
////////////////////////////////////// End of USA County Map code ///////////////////////////////////////////////////////
</script>
</body>
</html>