-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCASES_DEATHS_TREND.html
533 lines (445 loc) · 19.7 KB
/
CASES_DEATHS_TREND.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
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
<!DOCTYPE html>
<html lang="en">
<head>
<title>CSS Website Layout</title>
<meta charset="utf-8">
<script src="https://d3js.org/d3.v4.min.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
* {
box-sizing: border-box;
}
/* AXES */
/* ticks */
.axis line{
stroke: #1313a0;
stroke-width: 0.5;
shape-rendering: crispEdges;
}
/* axis contour */
.axis path {
stroke: #0a0a7d;
stroke-width: 0.7;
shape-rendering: crispEdges;
}
/* axis text */
.axis text {
fill: #2b2929;
font-family: Georgia;
font-size: 120%;
}
/* LINE CHART */
.line {
fill: none;
stroke-width: 1px;
stroke: #d2d2d2;
}
.ghost-line {
fill: none;
stroke: #0f2092;
opacity: 0;
stroke-width: 10px;
}
.serie_label {
fill: #d2d2d2;
font-family: Georgia;
font-size: 100%;
}
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%;
}
.axis text {
font: 10px sans-serif;
}
</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>
<div class="row">
<p style="background-color:aliceblue;font-family:Helvetica Neue;font-size:130%" align="justify"><b style="color: purple;font-size: 18px">Daily New Cases and Deaths Trend in USA:</b><br> The following chart shows the number of new COVID-19 cases reported each day in the U.S. since mid-March when the outbreak was officially declared in the United States. <b>Click buttons to switch between the trend of daily new case counts, daily new death counts and 7-day average data.The 7-Day moving average of new cases (current day + 6 preceding days / 7) was calculated to smooth expected variations in daily counts.</b> Additionally, hover over the bars to see the number of new cases by day and check the annotation to explore the recent exponential surge started from mid-June due to aggressive reopening strategy carried out by a few U.S. jurisdictions.<br></p>
<div id="my_dataviz" style="background-color:#f8f0e1;color:#202c42;padding:10px;border: 5px outset #08080e">
<div><button onclick="update('Cases')">Cases</button>
<button onclick="update('Average_7Day_Cases')">Average_7Day</button>
<button onclick="update('Deaths')">Deaths</button>
</div>
</div>
<p style="background-color:aliceblue;font-family:Helvetica Neue;font-size:130%" align="justify"><b style="color: purple;font-size: 18px">COVID-19 Cases Trend By State:</b><br>The following line chart exhibits the COVID-19 cases trend reported in different U.S. states as of 07/15/2020. <br>Going by the trend line, it is observed that the COVID-19 cases reached peak stage in New York, New Jersey and Illinois. Moreover based on the following chart, there is a steep surge observed in Texas, California and Florida state. Arizona and Georgia also reported recent surge in COVID-19 cases. <b>Hover over the individual line to get an interactive clear view.</b><br></p>
<div id="my_dataviz1" style="background-color:#f8f0e1;color:rgba(53,69,229,0.09);padding:10px;border: 5px outset #021d28"></div>
<br>
<footer>
<p style="background-color:#ffffff;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>
////////////////////////////////////// Beginning of USA Daily New Cases Trend code //////////////////////////////
// set the dimensions and margins of the graph
var margin_daily = {top: 40, right: 20, bottom: 70, left: 40},
width_daily = 1200 - margin_daily.left - margin_daily.right,
height_daily = 400 - margin_daily.top - margin_daily.bottom;
// append the svg object to the body of the page
var svg_daily = d3.select("#my_dataviz")
.append("svg")
.attr("width", width_daily + margin_daily.left + margin_daily.right)
.attr("height", height_daily + margin_daily.top + margin_daily.bottom)
.append("g")
.attr("transform",
"translate(" + margin_daily.left + "," + margin_daily.top + ")");
// Initialize the X axis
var x = d3.scaleBand()
.range([ 0, width_daily ])
.padding(0.3);
var xAxis = svg_daily.append("g")
.attr("transform", "translate(0," + height_daily + ")")
// Initialize the Y axis
var y = d3.scaleLinear()
.range([ height_daily, 0]);
var yAxis = svg_daily.append("g")
.attr("class", "myYaxis")
var tooltip = d3.select("#my_dataviz").append("div")
.attr("class", "tooltip")
.style("opacity", 0);
// A function that create / update the plot for a given variable:
function update(selectedVar) {
// Parse the Data
d3.csv("data/US_Daily_New_Case.csv", function(data) {
// X axis
x.domain(data.map(function(d) { return d.Date; }))
xAxis.transition().duration(1000).call(d3.axisBottom(x))
.selectAll("text")
.attr("transform", "translate(-15,10)rotate(-90)")
.style("text-anchor", "end");
// Add Y axis
y.domain([0, d3.max(data, function(d) { return +d[selectedVar] }) ]);
yAxis.transition().duration(1000).call(d3.axisLeft(y));
// variable u: map data to existing bars
var u = svg_daily.selectAll("rect")
.data(data)
.on("mouseover", function(d) {
var html = "<span><b> Date : </b>" + d.Date+ "</span><br/>" +
"<b style='color: darkred'> Daily Cases: <b/>" + d.Cases + "</span></br>" +
"<span style='color:palevioletred'><b> Avg 7 day cases: </b>" + d.Average_7Day_Cases + "</span></br>" +
"<span style='color:red'><b> Daily Deaths: </b>" + d.Deaths + "</span></br>"
tooltip.html(html)
.style("left", (d3.event.pageX + 25) + "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);
})
// update bars
u
.enter()
.append("rect")
.merge(u)
.transition()
.duration(1000)
.attr("x", function(d) { return x(d.Date); })
.attr("y", function(d) { return y(d[selectedVar]); })
.attr("width", x.bandwidth())
.attr("height", function(d) { return height_daily - y(d[selectedVar]); })
.attr("fill", "#69b3a2")
// circle for annotation
svg_daily.append("circle")
.attr("cx", 990)
.attr("cy", 150)
.attr("r", 140)
.style("stroke", function (d) {if (selectedVar == 'Cases') {return "red";}
else if (selectedVar == 'Average_7Day_Cases') {return "mediumvioletred";}
else return "green"; })
.style("stroke-width",4)
.style("stroke-dasharray", ("3, 3"))
.style("fill","none");
//line for annotation
svg_daily.append("line")
.attr("x1", 700)
.attr("y1", 80)
.attr("x2", 850)
.attr("y2", 130)
.attr("stroke-width", 2)
//.attr("stroke", "red")
.style("stroke", function (d) {if (selectedVar == 'Cases') {return "red";}
else if (selectedVar == 'Average_7Day_Cases') {return "mediumvioletred";}
else return "green"; })
.attr("marker-end", "url(#triangle)");
//remove previous state of annotation
svg_daily.selectAll(".annotation").remove();
// text for annotation
svg_daily.append("text")
.attr("class","annotation")
.attr("x",485)
.attr("y",75)
.attr("font-family","sans-serif")
.attr("font-size",12)
//.style("fill", "green")
.style("fill", function (d) {if (selectedVar == 'Cases') {return "red";}
else if (selectedVar == 'Average_7Day_Cases') {return "mediumvioletred";}
else return "green"; })
.style("text-decoration", "underline")
.text(function (d) { if (selectedVar == 'Cases')
{
words = "COVID-19 cases surge in U.S. since mid-June";
}
else if (selectedVar == 'Average_7Day_Cases')
{
words = "Average 7-day cases surge in U.S. since mid-June";
}
else
{
words = "COVID-19 Mortality rate improved since mid-June";
}
return words;
});
})
}
update('Cases') // Initiliaze the bars
////////////////////////////////////// End of USA Daily New Cases Trend code //////////////////////////////
////////////////////////////////////// Beginning of Total no. of Cases Trend by State code //////////////////////////////
// Set width, height and margin
var width = 760;
var height = 300;
var margin = 30;
// appending SVG first
var svg = d3.select("#my_dataviz1").append("svg")
.attr("viewBox", "-"
+ 60 + " -"
+ 60 + " "
+ (width + margin * 5) + " "
+ (height + margin * 5));
//set color
var color = d3.scaleOrdinal(d3.schemeCategory20);
// time conversion using parse function
var timeConv = d3.timeParse("%d-%b-%Y");
// load the USA state data of total no. of cases by date
d3.csv("data/covid_confirmed_usafacts.csv", function(data) {
var slices = data.columns.slice(1).map(function(id) {
return {
id: id,
values: data.map(function(d){
return {
date: timeConv(d.date),
measurement: +d[id]
};
})
};
});
// scaletime
var xScale = d3.scaleTime().range([0,width]);
var yScale = d3.scaleLinear().rangeRound([height, 0]);
xScale.domain(d3.extent(data, function(d){
return timeConv(d.date)}));
yScale.domain([(0), d3.max(slices, function(c) {
return d3.max(c.values, function(d) {
return d.measurement + 4; });
})
]);
// Y axis
var yaxis = d3.axisLeft()
.ticks((slices[0].values).length - 156)
.scale(yScale);
// X axis
var xaxis = d3.axisBottom()
.ticks(d3.timeDay.every(60)) // Time scale in every 60 days
.tickFormat(d3.timeFormat('%b %d'))
.scale(xScale);
var line = d3.line()
.x(function(d) { return xScale(d.date); })
.y(function(d) { return yScale(d.measurement); });
svg.append("g")
.attr("class", "axis")
.attr("transform", "translate(0," + height + ")")
.call(xaxis);
// text label for Y axis
svg.append("g")
.attr("class", "axis")
.call(yaxis)
.append("text")
.attr("transform", "rotate(-90)")
.attr("dy", ".75em")
.attr("y", -55)
.attr("x",0 - (height / 2))
.style("text-anchor", "middle")
.text("Total Cases");
// text label for the x axis
svg.append("text")
.attr("transform",
"translate(" + (width/2) + " ," +
(height + margin + 20) + ")")
.style("text-anchor", "middle")
.text("Date");
// draw circle for annotation
svg.append("circle")
.attr("cx", 720)
.attr("cy", 100)
.attr("r", 60)
.style("stroke", "red")
.style("stroke-width",3)
.style("stroke-dasharray", ("3, 3"))
.style("fill","none");
//line for annotation
svg.append("line")
.attr("x1", 300)
.attr("y1", 30)
.attr("x2", 660)
.attr("y2", 100)
.attr("stroke-width", 1)
.attr("stroke", "red")
.attr("marker-end", "url(#triangle)");
// text for annotation
svg.append("text")
.attr("x",200)
.attr("y",25)
.attr("font-family","sans-serif")
.attr("font-size",9)
.style("fill", "red")
.style("text-decoration", "underline")
.text("COVID-19 cases surge in TX,CA and FL since mid-June");
var lines = svg.selectAll("lines")
.data(slices)
.enter()
.append("g");
// Lines draw
lines.append("path")
.attr("class", "line")
.attr("d", function(d) { return line(d.values); })
.attr("stroke", function(d) { return color(d.id); });
// label each line with state name
lines.append("text")
.attr("class","serie_label")
.datum(function(d) {
return {
id: d.id,
value: d.values[d.values.length - 1]}; })
.attr("transform", function(d) {
return "translate(" + (xScale(d.value.date) + 10)
+ "," + (yScale(d.value.measurement) + 5 )+ ")"; })
.attr("x", 10)
.text(function(d) { return d.id; })
.style("fill", function(d) { return color(d.id); })
const ghost_lines = lines.append("path")
.attr("class", "ghost-line")
.attr("d", function(d) { return line(d.values); })
.attr("stroke", function(d) { return color(d.id); });
// mouseover ghost line events
lines.selectAll(".ghost-line")
.on('mouseover', function() {
const selection = d3.select(this).raise();
selection
.transition()
.delay("100").duration("10")
//.style("stroke","#ed3700")
.style("stroke", function(d) { return color(d.id); })
.style("opacity","1")
.style("stroke-width","3")
// add the legend action
const legend = d3.select(this.parentNode)
.select(".serie_label");
legend
.transition()
.delay("100")
.duration("10")
//.style("fill","#2b2929");
.style("fill", function(d) { return color(d.id); })
})
.on('mouseout', function() {
const selection = d3.select(this)
selection
.transition()
.delay("100")
.duration("10")
.style("stroke","#d2d2d2")
.style("opacity","0")
.style("stroke-width","3");
// add the legend action
const legend = d3.select(this.parentNode)
.select(".serie_label");
legend
.transition()
.delay("100")
.duration("10")
//.style("fill","#d2d2d2");
.style("fill", function(d) { return color(d.id); })
})
});
</script>
</div>
</body>
</html>