-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
1095 lines (887 loc) · 49.4 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
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
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<HTML>
<HEAD>
<TITLE>Yet Another Covid Analysis - COVID Timeline - UIUC CS-498-DV - ccbeyer2 - Summer 2020</TITLE>
<!--// Create Style Sheet for Narrative Visualization Consistency //-->
<style>
/* Set Styles for the Introduction / Model Window */
.modal {
display: none; /* Hidden by default */
position: fixed; /* Stay in place */
z-index: 1; /* Sit on top */
//padding-top: 100px; /* Location of the box */
padding-top: 20%; /* Location of the box */
left: 0;
top: 0;
width: 100%; /* Full width */
height: 100%; /* Full height */
overflow: auto; /* Enable scroll if needed */
background-color: rgb(0,0,0); /* Fallback color */
background-color: rgba(0,0,0,0.4); /* Black w/ opacity */
}
/* Modal Content */
.modal-content {
background-color: #E9E9E8;
margin: auto;
padding: 20px;
border: 3px solid #E84A27;
width: 80%;
}
/* The Close Button */
.close {
color: #aaaaaa;
float: right;
font-size: 28px;
font-weight: bold;
}
.close:hover,
.close:focus {
color: #000;
text-decoration: none;
cursor: pointer;
}
</style>
<style>
/* Style Sheet settings for the navigation buttons */
a.disabled_navigation_button{
display:inline-block;
padding:0.35em 1.2em;
border:0.1em solid #6e7887;
margin:0 0.3em 0.3em 0;
border-radius:0.12em;
box-sizing: border-box;
text-decoration:none;
font-family: "proxima-nova-alt", sans-serif;
font-weight:900;
color:#E9E9E8;
text-align:center;
transition: all 0.2s;
background-color: #E9E9E8;
width: 100%;
}
a.navigation_button{
display:inline-block;
padding:0.35em 1.2em;
border:0.1em solid #6e7887;
margin:0 0.3em 0.3em 0;
border-radius:0.12em;
box-sizing: border-box;
text-decoration:none;
font-family: "proxima-nova-alt", sans-serif;
font-weight:900;
color:#FFFFFF;
text-align:center;
transition: all 0.2s;
background-color: #E84A27;
width: 100%;
}
a.navigation_button:hover{
color:#E84A27;
background-color:#E9E9E8;
}
@media all and (max-width:30em){
a.navigation_button{
display:block;
margin:0.4em auto;
}
}
a.page_title_button{
display:inline-block;
padding:0.35em 1.2em;
border:0.1em solid #6e7887;
margin:0 0.3em 0.3em 0;
border-radius:0.12em;
box-sizing: border-box;
text-decoration:none;
font-family: "proxima-nova-alt", sans-serif;
font-weight:900;
color:#E84A27;
text-align:center;
transition: all 0.2s;
background-color: #E9E9E8;
width: 100%;
}
</style>
<style>
/* Set Style sheet options for the document body */
body {
font-family: "proxima-nova-alt", sans-serif;
font-size: 1.15em;
font-weight: 400;
line-height: 1.6;
color: #E9E9E8;
}
p.page_summary{
font-family: "proxima-nova-alt", sans-serif;
font-size: 1.1em;
font-weight: 1200;
line-height: 1.1;
color: #E9E9E8;
}
/* Set Styles for the Header that override body settings */
td.header{
background-color: #34466B;
}
div.header{
color: white;
background-color: #34466b;
}
td.sides{
color: white;
}
p.illini_orange{
color: #E84A27;
}
bg-white {
background: white; }
.bg-gray-lightest {
background: #F4F4F2; }
.bg-gray-light {
background: #E9E9E8; }
.bg-gray-medium {
background: white; }
.bg-gray-dark {
background: #363d44; }
.bg-orange {
background: #E84A27; }
.bg-blue-dark {
background: #6e7887; }
header {
bgcolor: #002855;
}
/* Set Graph Items */
.line {
fill: none;
stroke: #E84A27;
stroke-width: 5px;
}
.axis path,
.axis line {
fill: none;
stroke: #E9E9E8;
stroke-width: 5px;
shape-rendering: crispEdges;
font-size: 14px;
}
.axis .tick > text {
font-size: 1.1em;
font-weight: 1200;
fill: #E9E9E8;
}
chart_title {
font-family: "proxima-nova-alt", sans-serif;
font-size: 1.25em;
font-weight: 800;
line-height: 1.6;
color: #E84A27;
}
.guideline {
margin-right: 100px;
float: right;
}
div.tooltip {
opacity: 0;
position: absolute;
text-align: left;
width: 250px;
height: 100px;
padding: 2px;
font-family: "proxima-nova-alt", sans-serif;
font-size: .75em;
font-weight: 600;
background: #E9E9E8;
color: #E84A27;
border: 0px;
border-radius: 8px;
pointer-events: none;
}
</style>
<!-- // Load the D3 Library // -->
<script src='https://d3js.org/d3.v5.min.js'></script>
<script src="http://d3js.org/topojson.v1.min.js"></script> <!-- This is D3 support for JSON formatted geographic data files such as found at NASA, etc. -->
<!-- // NOTE: The Javascript sections below would typically be placed in a standalone .js file(s); however, I left them here for easier visibility for the grader // -->
<!-- // Create Global Variables // -->
<script>
//---------------------------------------------------------------
//Code Block : GLOBAL VARS
//Author : Charles Beyer (ccbeyer2)
//Date : 07/29/2020
//Notes : The purpose of this block is to define/store all global variables
// that will be needed across "pages" for narrative visualization
// "Real World" would probably use namespaces and load from files,
// but this is
// not needed for this project and just keeping it basic
//---------------------------------------------------------------
//Development Flags
boolDebug = true; // Set to true while developing / debugging for additional output
//Narrative Visualation Control Flags
var nv_intro_played = false; // As we only want to show the intro once, set boolean to track this
//Define Initial Page Values
var scene_total = 3; // Total Number of "Slides" in Narrative
var start_date = '12/31/2019'; // First date where data is available
var current_country = 'World' // Create the default country for initial plots
//Define State Values
var scene_current = 0; // Keep track of the current page
var current_date = start_date; // This variable will increment through playback
//Define Transition / Animation values
var ani_playback_speed = 1000; // For animations controls the playback speed. (higher = slower playback)
var ani_scene_speed = 2000; // For animations between scenes
var ani_enabled = true; // Controls whether is is playback animation or show all data at once
var ani_direction = 1; // 1 forward / -1 reversed
var ani_skywalker = 'he was supposed to be the chosen one!';
//Declare world map variables
var wm_rotation_speed = 5000 // Transition delay when "spinning" the globe to zoom to the selected country
var wm_selected_zoom = 200 // For selected country, set a zoom factor
//Define Files Required
var file_covid_data = "https://raw.githubusercontent.com/owid/covid-19-data/master/public/data/owid-covid-data.csv?raw=true"; //This file contains the COVID raw data
var file_page_intro = "https://raw.githubusercontent.com/beyerch/CS498DV_Narrative/master/data/nv_page_headers.csv"; //This file contains metadata for each slide/page
var file_annotations = "https://raw.githubusercontent.com/beyerch/CS498DV_Narrative/master/data/nv_page_annotations.csv"; //This file contains annotations by page & date
var file_world_map = "https://raw.githubusercontent.com/beyerch/CS498DV_Narrative/master/data/WorldMap.json"; //World Map Raw Data
var file_country_list = "https://raw.githubusercontent.com/beyerch/CS498DV_Narrative/master/data/CountryList.tsv"; //Country List for Map / COVID Data Lookup
// Load Data Sources
var data_covid; // Data storage area for COVID main data table
var graph_data_covid; // For line chart
var data_page_intro; // Data storage area for Page Header/Introductions
var data_annotations; // Data Annotations
var data_world_map; // World Map
var data_country_list; // Country List
// Declare objects to hold sub-sets from Data Sources
var data_countries; // Create a list of distinct countries (used for selection bar)
var data_continents; // Create a list of continents (used for selection bar)
// Declare svg object
// Create variables for margins, height, and width
var margin = {top: 75, right: 20, bottom: 50, left: 70},
width = 760 - margin.left - margin.right,
height = 550 - margin.top - margin.bottom;
// Add X axis --> it is a date format
var x = d3.scaleTime().range([0, width]);
var y = d3.scaleLinear().range([height, 0]);
// Create a function to draw the line
var deathline = d3.line()
.x(function(d) { return x(d.date); })
.y(function(d) { return y(d.total_deaths); });
// Create a function to draw the line
var infectionline = d3.line()
.x(function(d) { return x(d.date); })
.y(function(d) { return y(d.total_cases); });
// Create a function to draw the line
var stringencyline = d3.line()
.x(function(d) { return x(d.date); })
.y(function(d) { return y(d.stringency_index); });
var formatComma = d3.format(",");
</script>
<!-- // Page / Scene Scripts // -->
<script>
//---------------------------------------------------------------
//Code Block : init_display()
//Author : Charles Beyer (ccbeyer2)
//Date : 07/29/2020
//Notes : The purpose of this block is remove any SVG tags and reset
// visualization to the initial state
function init_display()
{
//Drop any existing SVG elements
//d3.selectAll("svg").remove();
}
//---------------------------------------------------------------
//Code Block : start_scene
//Author : Charles Beyer (ccbeyer2)
//Date : 08/01/2020
//Notes : The purpose of this block is render the appropriate scene
function start_scene(direction=0)
{
//Deubg output as needed
if (boolDebug)
{
console.log(' In start_scene()');
console.log(' Scene Number is : ' + scene_current);
console.log(' Scene Direction is : ' + direction);
console.log(' Introduction Bypass is : ' + nv_intro_played);
}
//Check to see current scene is either first or last and the requested direction would go out of bound, if so, exit
if ( (scene_current ==1 && direction < 0) || (scene_current == scene_total && direction > 0) ) { return; }
//Adjust current scene accordingly
scene_current += direction;
//Since the introduction has been played, disable
if (scene_current != 0) { nv_intro_played = true; }
//Update the Title Appropriately
document.getElementById("btn_page_header").innerHTML = data_page_intro[scene_current].PageName;
//Update the left side summary data
if (scene_current > 0) { document.getElementById("page_overview_text").innerHTML = data_page_intro[scene_current].PageText; }
//Update the "Previous" Navigation Menus
nav_button = document.getElementById("btn_nav_previous")
if (scene_current > 1)
{
//Update Button based on current scene value
nav_button.className = "navigation_button";
nav_button.innerHTML = "Previous: " + data_page_intro[scene_current-1].PageName;
}
else
{
//We are already at the lowest page so disable Previous
nav_button.className = "disabled_navigation_button";
}
//Update the "Next" Navigation Menus
nav_button = document.getElementById("btn_nav_next")
if (scene_current < scene_total)
{
//Update Button based on current scene value
nav_button.className = "navigation_button";
nav_button.innerHTML = "Next: " + data_page_intro[scene_current+1].PageName;
}
else
{
//Remove Text and change color
nav_button.className = "disabled_navigation_button";
}
console.log(' Scene Number is : ' + scene_current);
//If we are on the introduction scene, but the flag is set, move to scene 1
if (scene_current == 0 && nv_intro_played == true) { scene_current = 1 }
console.log(' Scene Number is : ' + scene_current);
//Perform switch based on page number
switch (scene_current)
{
case 0:
show_intro();
break;
case 1:
create_line_graph();
break;
case 2:
create_line_graph();
break;
case 3:
create_line_graph();
break;
default:
console.log('Something went wrong as an unexpected scene number was encountered!');
}
}
//---------------------------------------------------------------
//Code Block : update_chart_data
//Author : Charles Beyer (ccbeyer2)
//Date : 08/02/2020
//Notes : The purpose of this block is update line chart data w/ filter
// for the currently selected Country/Location
function create_line_graph()
{
if (boolDebug) { console.log('In create_line_graph'); }
//Circle cleanup
Array.prototype.slice.call(document.getElementsByTagName('circle')).forEach(
function(item) {
item.remove();
// or item.parentNode.removeChild(item); for older browsers (Edge-)
});
// Create the Sorted Country List
data_countries = d3.map(data_covid, function(d){return d.location;}).keys().sort(function(a, b) {return d3.ascending(a, b);});
if (boolDebug) { console.log(' data_countries dataset has : ' + data_countries.length + ' entries'); }
// add the options to the button
d3.select("#sel_country")
.selectAll('myOptions')
.data(data_countries)
.enter()
.append('option')
.text(function (d) { return d; }) // text showed in the menu
.attr("value", function (d) { return d; }) // corresponding value returned by the button
// Set the currently select option to match the default country
document.getElementById('sel_country').value=current_country;
// Add event listener to allow change to Selected Country
d3.select("#sel_country").on("change", function(d) {
if (boolDebug) { console.log("In sel_country onChange") }
// recover the option that has been chosen
var selectedOption = d3.select(this).property("value")
// run the updateChart function with this selected option
update(selectedOption)
})
if (boolDebug) { console.log(' Country Select List has : ' + document.getElementById("sel_country").options.length + ' entries'); }
//Get a reference to the SVG tag
var svg = d3.select("svg")
.attr("width", width + margin.left + margin.right)
.attr("height", height + margin.top + margin.bottom)
.append("g")
.attr("id","g_graph")
.attr("transform",
"translate(" + margin.left + "," + margin.top + ")");
// filter data to the current country
graph_data_covid = data_covid.filter(function(record) { return record.location == current_country; });
graph_data_covid.forEach(function(d) {
d.date = new Date(d.date); // d3.timeParse("%Y/%m/%d")(d.date);
d.total_deaths = +d.total_deaths;
d.total_cases = +d.total_cases;
d.stringency_index = +d.stringency_index
//console.log('Date is ' + d.date + ', Total Deaths are : ' + d.total_deaths);
});
// Scale the range of the data
x.domain(d3.extent(graph_data_covid, function(d) { return d.date; }));
// Determine if the path already exists, if not create
if (document.getElementById('chart_line') == null)
{
if (boolDebug) { console.log (' Object chart_line not found, creating') }
svg.append("path")
.data([graph_data_covid])
.attr("class", "line")
.attr("id","chart_line")
}
// Three function that change the tooltip when user hover / move / leave a cell
var mouseover = function(d) {
console.log ('In Tooltip Mouseover');
d3.select(this).transition()
.duration('50')
.attr('opacity', '.85');
Tooltip.transition()
.duration(50)
.style("opacity", 1);
}
// Create the appropriate line
switch (scene_current)
{
case 1:
// Set the appropriate Scaling
y.domain([0, d3.max(graph_data_covid, function(d) { return d.total_cases; })]);
// Add the line for infections
d3.select("#chart_line")
.data([graph_data_covid])
.attr("class", "line")
.attr("id","chart_line")
.transition()
.duration(ani_scene_speed)
.attr("d", infectionline);
break;
case 2:
// Set the appropriate Scaling
y.domain([0, d3.max(graph_data_covid, function(d) { return d.total_deaths; })]);
// Add the line path for Deaths
d3.select("#chart_line")
.data([graph_data_covid])
.attr("class", "line")
.attr("id","chart_line")
.transition()
.duration(ani_scene_speed)
.attr("d", deathline);
break;
case 3:
// Set the appropriate Scaling
y.domain([0, d3.max(graph_data_covid, function(d) { return d.stringency_index; })]);
// Add the line path for Deaths
d3.select("#chart_line")
.data([graph_data_covid])
.attr("class", "line")
.attr("id","chart_line")
.transition()
.duration(ani_scene_speed)
.attr("d", stringencyline);
break;
default:
console.log(' Unexpected Scene value in D3 Line Chart Creation. Scene Value was ' + scene_current);
}
// Determine if the path already exists, if not create
if (document.getElementById('chart_title') == null)
{
if (boolDebug) { console.log (' Object chart_title not found, creating') }
svg.append("text")
.attr("id", "chart_title");
}
// Add Title
d3.select("#chart_title")
.attr("id", "chart_title")
.attr("x", (width / 2))
.attr("y", 0 - (margin.top / 2))
.attr("font-family", "proxima-nova-alt, sans-serif")
.attr("fill", "#E84A27")
.attr("font-weight","800")
.style("text-decoration", "underline")
.style("text-anchor","middle")
.text(data_page_intro[scene_current].PageTitle + " vs Date Graph");
// Determine if the path already exists, if not create
if (document.getElementById('axis_x') == null)
{
if (boolDebug) { console.log (' Object chart x axis not found, creating') }
svg.append("g")
.attr("class", "axis")
.attr("id", "axis_x");
}
// Add the x Axis
d3.select("#axis_x")
.attr("class", "axis")
.attr("id", "axis_x")
.attr("transform", "translate(0," + height + ")")
.transition()
.duration(ani_scene_speed)
.call(d3.axisBottom(x));
// Determine if the path already exists, if not create
if (document.getElementById('axis_y') == null)
{
if (boolDebug) { console.log (' Object chart y axis not found, creating') }
svg.append("g")
.attr("class", "axis")
.attr("id", "axis_y");
}
// Add the y Axis
d3.select("#axis_y")
.attr("class", "axis")
.attr("id", "axis_y")
.transition()
.duration(ani_scene_speed)
.call(d3.axisLeft(y));
//console.log(graph_data_covid.length);
//Get Tooltip DIV
var div = d3.select("#div_tooltip");
//Insert Circles
svg.selectAll("circle")
.data(graph_data_covid)
.enter()
.append("circle")
.style("fill", "#E84A27")
.style("fill-opacity","0%")
.attr("r", 3)
.attr("cx", function(d){return x(d.date);})
.attr("cy", function(d)
{
switch (scene_current)
{
case 1:
return y(d.total_cases);
case 2:
return y(d.total_deaths);
case 3:
return y(d.stringency_index);
}
}
)
.on("mouseover", function(d)
{
div.style("opacity", .9);
div.html(d.location + "<HR>" + "Total Cases : " + formatComma(d.total_cases) + "<BR>" + "Total Deaths: " + formatComma(d.total_deaths) + "<BR>" + "Government Response Level: " + d.stringency_index)
.style("left", (d3.event.pageX) + "px")
.style("top", (d3.event.pageY - 28) + "px");
}
)
.on("mouseout", function(d)
{
div.style("opacity", 0);
}
);
}
// A function that update the chart
function update(selectedGroup) {
Array.prototype.slice.call(document.getElementsByTagName('circle')).forEach(
function(item) {
item.remove();
// or item.parentNode.removeChild(item); for older browsers (Edge-)
});
// Log that we are in the graph update function
if (boolDebug) { console.log("In the sel_country onChange update function, value is : [" + selectedGroup + "]") }
// Update the current country
current_country = selectedGroup;
// Create new data with the selection?
var dataFilter = data_covid.filter(function(record) { return record.location == current_country; });
dataFilter.forEach(function(d) {
d.date = new Date(d.date); // d3.timeParse("%Y/%m/%d")(d.date);
d.total_deaths = +d.total_deaths;
d.total_cases = +d.total_cases;
d.stringency_index = +d.stringency_index;
console.log('Name is : ' + d.location + ', Date is ' + d.date + ', Total Deaths are : ' + d.total_deaths);
});
//Re-Scale the range of the x axis
x.domain(d3.extent(dataFilter, function(d) { return d.date; }));
// Create the appropriate line
switch (scene_current)
{
case 1:
// Set the appropriate Scaling
y.domain([0, d3.max(dataFilter, function(d) { return d.total_cases; })]);
var line = d3.select(".line")
.data([dataFilter])
.transition()
.duration(ani_playback_speed)
.attr("d", infectionline);
break;
case 2:
// Set the appropriate Scaling
y.domain([0, d3.max(dataFilter, function(d) { return d.total_deaths; })]);
// Add the line path for Deaths
var line = d3.select(".line")
.data([dataFilter])
.transition()
.duration(ani_playback_speed)
.attr("d", deathline);
break;
case 3:
// Set the appropriate Scaling
y.domain([0, d3.max(dataFilter, function(d) { return d.stringency_index; })]);
// Add the line path for Deaths
var line = d3.select(".line")
.data([dataFilter])
.transition()
.duration(ani_playback_speed)
.attr("d", stringencyline);
break;
default:
console.log(' Unexpected Scene value in D3 Line Chart Creation. Scene Value was ' + scene_current);
}
// Add the y Axis
var axis_y =
d3.select("#axis_y") //svg.append("g")
.attr("class", "axis")
.attr("id", "axis_y")
.transition()
.duration(ani_playback_speed)
.call(d3.axisLeft(y));
// Add the x Axis
var axis_x =
d3.select("#axis_x")
.attr("class", "axis")
.attr("id", "axis_x")
.attr("transform", "translate(0," + height + ")")
.transition()
.duration(ani_playback_speed)
.call(d3.axisBottom(x));
//Get Tooltip DIV
var div = d3.select("#div_tooltip");
//Insert Circles
var svg = d3.select("#g_graph")
.selectAll("circle")
.data(dataFilter)
.enter()
.append("circle")
.style("fill","#E84A27")
.style("fill-opacity","0%")
.attr("r", 3)
.attr("cx", function(d){return x(d.date);})
.attr("cy", function(d)
{
switch (scene_current)
{
case 1:
return y(d.total_cases);
case 2:
return y(d.total_deaths);
case 3:
return y(d.stringency_index);
}
}
)
.on("mouseover", function(d)
{
div.style("opacity", .9);
div.html(d.location + "<HR>" + "Total Cases : " + formatComma(d.total_cases) + "<BR>" + "Total Deaths: " + formatComma(d.total_deaths) + "<BR>" + "Government Response Level: " + d.stringency_index)
.style("left", (d3.event.pageX) + "px")
.style("top", (d3.event.pageY - 28) + "px");
}
)
.on("mouseout", function(d)
{
div.style("opacity", 0);
}
);
}
//---------------------------------------------------------------
//Code Block : show_world_map
//Author : Charles Beyer (ccbeyer2)
//Date : 08/02/2020
//Notes : The purpose of this block is render the world map via D3
function show_world_map()
{
// TO DO - Implement this if I can get to it. Day Job Work sucks and no time right now
}
//---------------------------------------------------------------
//Code Block : show_intro
//Author : Charles Beyer (ccbeyer2)
//Date : 08/01/2020
//Notes : The purpose of this block is render the appropriate scene
function show_intro()
{
//Deubg output as needed
if (boolDebug)
{
console.log(' In show_intro()');
console.log(' Page Name is : ' + data_page_intro[scene_current].PageName);
console.log(' Page Title is : ' + data_page_intro[scene_current].PageTitle);
console.log(' Page Text is : ' + data_page_intro[scene_current].PageText);
}
//Create SVG object in the main body
var modal = document.getElementById("div_introduction")
var span = document.getElementById("modal-span")
//Add the data read from D3 to the paragraph
document.getElementById("modal-p").innerHTML = data_page_intro[scene_current].PageText;
//Make the dialog visible
modal.style.display = "block";
//Create event handler to hide dialog
span.onclick = function() { modal.style.display = "none"; start_scene(1); window.onclick = null; }
//Create event handler to hide dialog outside of modal
window.onclick = function(event) { if (event.target == modal) { modal.style.display = "none"; }; start_scene(1); window.onclick = null;}
}
</script>
<!-- // Data Processing Scripts // -->
<script>
// Load the data files
async function data_load()
{
data_covid = await d3.csv(file_covid_data);
data_page_intro = await d3.csv(file_page_intro);
data_annotations = await d3.csv(file_annotations);
data_world_map = await d3.json(file_world_map);
data_country_list = await d3.tsv(file_country_list);
if (boolDebug)
{
//Debug mode, write out row counts to confirm data is loaded
console.log('data_covid dataset contains [' + data_covid.length + '] rows of data');
console.log('data_page_intro dataset contains [' + data_page_intro.length + '] rows of data');
console.log('data_annotations dataset contains [' + data_annotations.length + '] rows of data');
console.log('data_world_map dataset contains [' + Object.keys(data_world_map).length + '] data keys');
console.log('data_country_list dataset contains [' + data_country_list.length + '] rows of data');
}
//Validate that the data loaded
if (data_covid.length < 1 || data_page_intro.length < 1 || data_annotations.length < 1 || Object.keys(data_world_map).length < 1 || data_country_list.length < 1 )
{
//Something went wrong loading data, so display a warning
window.alert('There was a data loading failure, please try refreshing the page. If this issue persists, please contact the administrator or try again later');
return;
}
//Trigger Data Post Processing
data_post_processing();
//Initialize the presentation page
init_display();
//Prep / Start scene
start_scene();
}
</script>
<!-- // Data Load Prep Operations // -->
<script>
function data_post_processing()
{
// Prep the lists
if (boolDebug)
{
console.log(' In data_post_processing ');
console.log(' data_covid dataset contains [' + data_covid.length + '] rows of data');
console.log(' data_page_intro dataset contains [' + data_page_intro.length + '] rows of data');
console.log(' data_annotations dataset contains [' + data_annotations.length + '] rows of data');
console.log(' data_world_map dataset contains [' + Object.keys(data_world_map).length + '] data keys');
console.log(' data_country_list dataset contains [' + data_country_list.length + '] rows of data');
}
// Create the Sorted Country List
data_countries = d3.map(data_covid, function(d){return d.location;}).keys().sort(function(a, b) {return d3.ascending(a, b);});
console.log(data_countries);
// Create the Sorted Continent List
data_continents = d3.map(data_covid, function(d){return d.continent;}).keys().sort(function(a, b) {return d3.ascending(a, b);});
console.log(data_continents);
}
</script>
</HEAD>
<BODY onload='data_load()' bgcolor="#34466b" >
<!--//-------------------------------------------- Create a Table structure to create a Header, Footer, Left, Right and Center areas. -----------------------------------------------
While people frown on TABLE for modern page layout, this is a simple layout and it works //-->
<TABLE id="tblMainStruct" width="100%" height="100%" bgcolor="#6e7887" cellspacing="0" cellpadding="0">
<TR height="10%" id="header" cellspacing="0">
<!--// -------------------------------------------------------Create the header area //------------------------------------------------------------------------------------>
<TD colspan="3" width="100%" bgcolor="#34466b">
<!-- // Print a warning in the event the browser does not support Javascript or it is disabled // -->
<DIV style="header" id="div_header">
<noscript><H1>WARNING: This page requires Javascript to work properly. Please enable Javascript for this page in your Browser!</H1></noscript>
<CENTER><H1>COVID-19 - A World at Risk</H1><I>Summer 2020 CS498 Data Visualization (ccbeyer2)</I> </CENTER>
</DIV>
</TD>
</TR>
<!-- // Navigation & Page Header Row // -->
<TR height="2%">
<!--// ----------------------------------------------------- Create the left "nav" area ---------------------------------------------------------------------------- //-->
<TD width="20%" id="doc_leftcolumn_nav" valign="top" class="header">
<a href="#" class="navigation_button" id="btn_nav_previous" onClick="start_scene(-1); return false;">Previous</a>
</TD>
<!--// ------------------------------------------------------ Create the center area -------------------------------------------------------------------------------- //-->
<TD width="60%" id="doc_centercolumn" valign="top" class="header">
<a href="#" class="page_title_button" id="btn_page_header" href="#" onClick="return false;">Introduction</a>
</TD>
<!--// ------------------------------------------------------ Create the right area ----------------------------------------------------------------------------- ----//-->
<TD width="20%" id="doc_rightcolumn_nav" valign="top" class="header">
<a href="#" class="navigation_button" id="btn_nav_next" onClick="start_scene(1); return false;">Next</a>
</TD>
</TR>
<!-- // Main Body Row // -->
<TR height="1%">
<TD width="20%" class="header"></td>
<TD width="60%" class="header">
View data for: <select id="sel_country"></select> <HR>
</TD>
<td width="20%" class="header"></td>
</tr>
<TR height="68%">
<!--// ----------------------------------------------------- Create the left "nav" area ---------------------------------------------------------------------------- //-->
<TD width="20%" id="doc_leftcolumn" valign="top" class="header" valign="middle">
<p id="page_overview_text" class="page_summary"></p>
</TD>
<!--// ------------------------------------------------------ Create the center area -------------------------------------------------------------------------------- //-->
<TD colspan="2" width="80%" id="doc_centercolumn" class="header" valign="top">
<!--// -------------- Content Specific to the Introduction ----------------- // -->