-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcovid.js
1556 lines (1460 loc) · 72.7 KB
/
covid.js
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
/**
* @copyright: Louis de Charsonville
*
*/
$('#loading_screen').show();
const main = document.getElementById('main'),
mainStyle = main.currentStyle || window.getComputedStyle(main),
mainWidth = main.offsetWidth,
mainSideMargin = parseFloat(mainStyle.marginLeft) + parseFloat(mainStyle.marginRight),
mainSidePadding = parseFloat(mainStyle.paddingLeft) + parseFloat(mainStyle.paddingRight),
graphWidth = mainWidth - mainSidePadding,
graphHeight = Math.max(400, screen.height * 0.4);
const root = document.documentElement,
rootStyle = window.getComputedStyle(root);
const stylesheet = window.document.styleSheets[2];
// Dark Mode
const cssVariables = ['--background-color','--color-text','--text-muted']; // for dark mode
let cssMapping = {};
for (const v of cssVariables) {
cssMapping[ v + '-light'] = rootStyle.getPropertyValue(v + '-light');
cssMapping[ v + '-dark'] = rootStyle.getPropertyValue(v + '-dark');
}
// Colors
const colors_countries = ["#1abb9b","#3497da","#9a59b5","#f0c30f","#e57e22","#e64c3c","#7f8b8c","#CC6666", "#9999CC", "#66CC99"];
const colors = ['#FFC107','#ff073a','#2ecb71'];
// Data
let _data = {
"cases": [],
"cases_raw": [],
"cases_selected": [],
"testing": [],
"population": [],
"mobility": [],
"hospitalization": [],
};
// Initiate variables
let pivot_columns = ['Province/State','Country/Region','Lat','Long'],
// cases_categories = ['Confirmed','Deaths'],
cases_categories = ['Confirmed','Deaths','Recovered'],
rates_categories = ['Deaths rate'],
new_cases_categories = ['New Confirmed cases','New Deaths cases'],
testing_yaxis = ['Cumulative total','Cumulative total per thousand','Daily change in cumulative total','Daily change in cumulative total per thousand'],
testing_countries = [],
countries = [],
list_dates = [],
mobilityDates = [],
mobilityRegions = [],
mobilityTypes = [];
// Continental Aggregates
const EU_countries = ['Austria', 'Belgium','Bulgaria', 'Croatia', 'Cyprus',
'Czechia', 'Denmark', 'Estonia','Finland', 'France',
'Germany', 'Greece', 'Hungary', 'Ireland', 'Italy', 'Latvia',
'Lithuania', 'Luxembourg', 'Malta', 'Netherlands', 'Poland',
'Portugal', 'Romania','Slovakia', 'Slovenia', 'Spain', 'Sweden'],
Asia_countries = ["Afghanistan","Azerbaijan","Bangladesh","Bhutan","Brunei",
"Cambodia","Cameroon","China","East Timor","India","Indonesia",
"Japan","Kazakhstan","Korea, South","Kuwait","Kyrgyzstan",
"Malaysia","Maldives","Mongolia","Nepal","Oman","Pakistan",
"Philippines","Singapore","Sri Lanka","Taiwan*","Thailand",
"Uzbekistan","Vietnam"],
Africa_countries = ["Algeria","Angola","Benin","Burkina Faso","Cabo Verde",
"Cape Verde","Central African Republic","Chad",
"Congo (Brazzaville)","Congo (Kinshasa)","Cote d'Ivoire",
"Djibouti","Egypt","Equatorial Guinea","Eritrea","Gabon",
"Gambia, The","Ghana","Guinea","Kenya","Liberia","Madagascar",
"Mauritania","Mauritius","Morocco","Namibia","Niger","Nigeria",
"Rwanda","Senegal","Seychelles","Somalia","South Africa",
"Tanzania","Togo","Tunisia","Uganda","Zambia","Zimbabwe"],
Carribean_countries = ["Antigua and Barbuda","Bahamas, The","Barbados",
"Cuba","Dominican Republic","Haiti","Saint Lucia",
"Saint Vincent and the Grenadines","Trinidad and Tobago"],
Central_America_countries = ["Costa Rica","Ecuador","El Salvador",
"Guatemala","Honduras","Jamaica","Nicaragua",
"Panama","Belize"],
Europe_countries = ["Albania","Andorra","Armenia","Austria","Belarus",
"Belgium","Bosnia and Herzegovina","Bulgaria","Croatia",
"Cyprus","Czechia","Denmark","Estonia","Eswatini","Ethiopia",
"Finland","France","Georgia","Germany","Greece","Holy See",
"Hungary","Iceland","Ireland","Italy","Kosovo","Latvia",
"Liechtenstein","Lithuania","Luxembourg","Malta","Martinique",
"Moldova","Monaco","Montenegro","Netherlands","North Macedonia",
"Norway","Poland","Portugal","Romania","Russia","San Marino",
"Serbia","Slovakia","Slovenia","Spain","Sudan","Sweden","Switzerland",
"Ukraine","United Kingdom"],
Middle_East_countries = ["Bahrain","Iran","Iraq","Israel","Jordan","Lebanon",
"Qatar","Saudi Arabia","Turkey","United Arab Emirates",
"Yemen","Syria"],
North_America_countries = ["Canada", "Mexico", "US"],
Oceania_countries = ['Australia','Fiji','New Zealand','Papua New Guinea'],
South_America_countries = ["Argentina","Bolivia","Brazil","Chile","Colombia",
"Guyana","Paraguay","Peru","Suriname","Uruguay","Venezuela"];
// Mapping between testing and JHU data
const testing_equivalence_country = {
"Czech Republic": "Czechia",
"United States":"US",
"South Korea": "Korea, South"
};
const map_testing_country = function(country) {
if (Object.keys(testing_equivalence_country).indexOf(country) > -1) {
return testing_equivalence_country[country];
} else {
return country;
}
};
// ========================================================================== //
// NAVIGATION
// ----------
// Default navigation
let navigation = {
"page": "by_country",
"darkMode": window.matchMedia("(prefers-color-scheme: dark)").matches,
"country": "World",
"elements": [
{
"Country/Region": "France",
"category": "Confirmed",
"offset": 0
},
{
"Country/Region": "Italy",
"category": "Confirmed",
"offset": 0
},
{
"Country/Region": "Spain",
"category": "Confirmed",
"offset": 0
}
],
"logScale": false,
"logScale2": false,
"lines": true,
"lines2": true,
"percPopulation": false,
"percPopulation2": false,
"startDate": null,
"endDate": null,
"maCompare": 1,
"ft_countries": ["Korea, South","China","France","Italy","Spain","Japan","US","United Kingdom"],
"logScale3": true,
"hideLegend": false,
"ft_category": "Deaths",
"ft_threshold": 100,
"ft_thresholdCategory": "Deaths",
"ft_ma": 1,
"testing_yVar": "Cumulative total",
"testing_countries": false,
"mobility_elements":[
{
"region": "Paris",
"transportation_type": "walking"
},
{
"region": "Paris",
"transportation_type": "driving"
},
{
"region": "Paris",
"transportation_type": "transit"
}],
"lines4": true,
"hideLegendMobility": false,
"hideNav": true,
"hospitalizationVariables": ["Hospitalizations for suspicion of COVID-19"],
"hideLegendHospitalization": false,
"lines5": true,
"maHospitalization": 1,
"custom_settings": [
["Font size axis tick text",".tick text","font-size","12px"],
["Font size axis label", ".axisLabel text", "font-size", "16px"]
]
};
function loadPage(button, target) {
$('.sidebar_show.active').each(function() {
$(this).removeClass('active');
});
button.addClass('active');
$('.content').hide();
$(target).show();
updateNavigation({"page":target.slice(1)});
}
function updateNavigation(j) {
Object.keys(j).forEach(function(e,i) {
if (Object.keys(navigation).indexOf(e) > -1) {
navigation[e] = j[e];
}
});
localStorage.setItem("navigation",JSON.stringify(navigation));
document.location.hash = navigation.hideNav ? "" : JSON.stringify(navigation);
}
// Simple analytics
function action(event) {
try {
sa_event(event);
}
catch(error) {
console.log(`Error in action. Action: ${event} | Error: ${error}`);
}
}
// Navigation - load
if (document.location.hash.length > 0) {
updateNavigation(JSON.parse(decodeURIComponent(document.location.hash.substring(1))));
} else {
if (localStorage.getItem('navigation')) {
updateNavigation(JSON.parse(localStorage.getItem('navigation')));
}
}
loadPage($(`#button_${navigation.page}`),'#' + navigation.page);
toggleDarkMode(navigation.darkMode);
$('#logScaleSwitch').prop('checked', navigation.logScale);
$('#barSwitch').prop('checked', !navigation.lines);
$('#percPopulation').prop('checked', navigation.percPopulation);
//Compare
$('#logScaleSwitch2').prop('checked', navigation.logScale2);
$('#barSwitch2').prop('checked', !navigation.lines2);
$('#percPopulation2').prop('checked', navigation.percPopulation2);
$('#movingAverageCompareRange').prop('value', navigation.maCompare);
$('#movingAverageCompareValue').html(navigation.maCompare);
// FT
$('#logScaleSwitch3').prop('checked', navigation.logScale3);
$('#hideLegend').prop('checked', navigation.hideLegend);
$('#thresholdRange').prop('value', navigation.ft_threshold);
// for ranges, we need to update both the range (position of the cursor) and the span value
$('#thresholdValue').html(navigation.ft_threshold);
$('#movingAverageFTRange').prop('value', navigation.ft_ma);
$('#movingAverageFTValue').html(navigation.ft_ma);
// Mobility
$('#barSwitch4').prop('checked', !navigation.lines4);
$('#hideLegendMobility').prop('checked', navigation.hideLegendMobility);
// Hospitalization
$('#barSwitch5').prop('checked', !navigation.lines5);
$('#hideLegendHospitalization').prop('checked', navigation.hideLegendHospitalization);
$('#movingAverageHospitalizationRange').prop('value', navigation.maHospitalization);
$('#movingAverageHospitalizationValue').html(navigation.maHospitalization);
// ========================================================================== //
// DARK MODE
// ---------
function toggleDarkMode(darkMode) {
let darkModeSwitch = $('#darkmodeSwitch');
if (darkMode) {
cssVariables.forEach(function(it) {root.style.setProperty(it,cssMapping[it+'-dark']);});
darkModeSwitch.addClass('darkmode badge-primary');
darkModeSwitch.removeClass('badge-secondary');
darkModeSwitch.text('ON');
updateNavigation({"darkMode":true});
} else {
cssVariables.forEach(function(it) {root.style.setProperty(it,cssMapping[it + '-light']);});
darkModeSwitch.removeClass('darkmode badge-secondary');
darkModeSwitch.addClass('badge-secondary');
darkModeSwitch.text('OFF');
updateNavigation({"darkMode":false});
}
}
// ========================================================================== //
// (DATA) FUNCTIONS
// -----------------
// In this section, all the functions used to download and process data.
function zip() {
// This function mimics zip function in Python
var args = [].slice.call(arguments);
var shortest = args.length==0 ? [] : args.reduce(function(a,b){
return a.length<b.length ? a : b;
});
return shortest.map(function(_,i){
return args.map(function(array){return array[i];});
});
}
function ma_json(array, yVars, period=1) {
// Compute the moving average on yVars with period 'period' where array
// is a JSON array
let ma = [];
for (let i = array.length; i >= 0 + period; i--) {
let e = $.extend(true, {}, array[i - 1]);
for (const yVar of yVars) {
e[yVar] = array.slice(i-period,i).reduce((t,n) => t + n[yVar],0)/period;
}
ma.push(e);
}
return ma.reverse();
}
function parseData(wide_data, pivot_columns, category) {
let long_data = [],
columns = Object.keys(wide_data[0]),
wide_columns = columns.filter(x => !pivot_columns.includes(x));
for (const element of wide_data) {
for (const col of wide_columns) {
let long_element = {};
long_element['field_id'] = col;
long_element['field_value'] = +element[col];
for (const col of pivot_columns) {
long_element[col] = element[col];
}
long_element['date'] = d3.timeParse("%m/%d/%y")(long_element['field_id']);
long_element['category'] = category;
long_element['key'] = category + long_element['Country/Region'] + long_element['field_id'];
long_element['key_world'] = category + long_element['field_id'];
long_data.push(long_element);
}
}
list_dates = d3.set(long_data.map(d => d['date'])).values().map(d => d3.timeFormat("%d-%b-%y")(new Date(d)));
navigation.startDate = navigation.startDate || list_dates[0];
navigation.endDate = list_dates.slice(-1)[0];
return long_data.sort(function(a,b) {return a.date - b.date;});
}
function parseMobilityData(wide_data, pivot_columns) {
let long_data = [],
columns = Object.keys(wide_data[0]),
wide_columns = columns.filter(x => !pivot_columns.includes(x));
for (const element of wide_data) {
for (const col of wide_columns) {
let long_element = {};
long_element['field_id'] = col;
long_element['field_value'] = +element[col];
for (const col of pivot_columns) {
long_element[col] = element[col];
}
long_element['date'] = new Date (d3.timeParse("%Y-%m-%d")(long_element['field_id']));
long_element['key'] = `${long_element['region']} - ${long_element['transportation_type']}`;
long_data.push(long_element);
}
}
mobilityDates = Grapher.unique(long_data.map(d => d['field_id']));
mobilityRegions = Grapher.unique(long_data.map(d => d['region']));
mobilityTypes = Grapher.unique(long_data.map(d => d['transportation_type']));
return long_data;
}
function parseTestingData(data) {
let confirmed_cases = d3.nest().key(d => d.key).map(_data.cases
.filter(d => d['category'] === 'Confirmed'));
for (const el of data) {
el['Country/Region'] = map_testing_country(el['Entity'].split(' - ')[0]);
el['units'] = el['Entity'].split(' - ')[1];
el['key'] = el['Entity'];
el['date'] = d3.timeParse("%Y-%m-%d")(el['Date']);
let cases = confirmed_cases.get(`Confirmed${el['Country/Region']}${d3.timeFormat('%-m/%-d/%y')(el.date)}`);
if (cases !== undefined) {
el['Cumulative cases per test'] = el['Cumulative total'] > 0 ? cases[0]['field_value'] / el['Cumulative total'] : null;
} else {
el['Cumulative cases per test'] = null;
}
}
testing_countries = d3.set(data.map(d => d.key)).values();
navigation.testing_countries = navigation.testing_countries || testing_countries.slice(1, 4);
testing_yaxis.push('Cumulative cases per test');
return data;
}
function addRates(data) {
let rates_categories = cases_categories.filter(d => d !== 'Confirmed');
let rates = d3.nest()
.key(d => d['Country/Region']+d['field_id'])
.rollup(function(d) {
let _ = [],
confirmed = d.filter(e => e['category'] === 'Confirmed')[0]['field_value'];
for (const category of rates_categories) {
let out = $.extend(true, {}, d[0]),
nb = d.filter(e => e['category'] === category )[0]['field_value'],
rate = confirmed === 0 ? 0 : nb / confirmed;
out['category'] = `${category} rate`;
out['field_value'] = rate;
out['key'] = out['category'] + out['Country/Region'] + out['field_id'];
out['field_value_pop'] = NaN;
_.push(out);
}
return _;
})
.entries(data)
.map(g => g.value).flat();
let new_and_growth_cases = d3.nest()
.key( d => d['Country/Region'] + d.category)
.rollup(function(a) {
let new_case = $.extend(true, [], a),
growth_rate = $.extend(true, [], a);
for (const [i, e] of a.entries()) {
if (i > 0) {
new_case[i]['field_value'] = a[i]['field_value']-a[i-1]['field_value'];
new_case[i]['previous_date'] = a[i-1]['field_id'];
growth_rate[i]['field_value'] = a[i-1]['field_value'] > 0 ? a[i]['field_value']/a[i-1]['field_value']-1 : null;
} else {
new_case[i]['field_value'] = null;
growth_rate[i]['field_value'] = null;
}
new_case[i]['category'] = `New ${e['category']} cases`;
new_case[i]['key'] = e['category'] + e['Country/Region'] + e['field_id'];
new_case[i]['field_value_pop'] = new_case[i]['field_value'] / e['Population'];
growth_rate[i]['category'] = `${e['category']} growth rate`;
growth_rate[i]['key'] = e['category'] + e['Country/Region'] + e['field_id'];
growth_rate[i]['field_value_pop'] = growth_rate[i]['field_value'] / e['Population'];
}
return [...new_case, ...growth_rate];
})
.entries(_data.cases)
.map(g => g.value).flat();
return [...data, ...rates, ...new_and_growth_cases];
}
function groupBy(array, key, colSum = [], colCount = [], colFirst = []){
// This function mimics a groupby with sum as the agg function.
// It uses D3.js
// @ Arguments:
// - array: array to group by
// - key: key to group by
// - colSum: array of columns to agg by sum
// - colCount: array of columns to agg by count
// - colFirst: array of columns to keep first
return d3.nest()
.key(function(d) { return d[key];})
.rollup(function(d) {
var out = {};
colSum.forEach(function(k) {
out[k] = d3.sum(d, v => v[k]);
});
colCount.forEach(function(k) {
out[k] = d.filter(v => v[k] != null).length;
});
colFirst.forEach(function(k) {
out[k] = d[0][k];
});
return out;
})
.entries(array)
.map(function (group) {
var out = {};
out[key] = group.key;
[...colSum,...colCount,...colFirst].forEach(function(k) {
out[k] = group.value[k];
});
return out;
});
}
function computeAggregate(name_aggregate, fltr = false,
data = _data.cases,
colSum = ['field_value','Population'],
colFirst = ['field_id','date', 'category']) {
return d3.nest()
.key(d => d.category + d.field_id)
.rollup(function(d) {
let out = {};
colSum.forEach(function(k) {
out[k] = d3.sum(d, v => v[k]);
});
colFirst.forEach(function(k) {
out[k] = d[0][k];
});
return out;
})
.entries((fltr ? data.filter(fltr) : data))
.map(function(g) {
let out = {};
[...colSum, ...colFirst].forEach(function(k) {
out[k] = g.value[k];
});
out['Country/Region'] = name_aggregate;
out['key'] = out.category + out['Country/Region'] + out['field_id'];
out['field_value_pop'] = out['field_value'] / out['Population'];
return out;
});
}
function get_list_countries(data) {
countries = d3.set(data.map(f => f['Country/Region'])).values().sort();
// Add countries to selector
let chooseCountryHTML = '',
ft_countries_html = '<option selected>Add country</option>';
for (const [index, country] of countries.entries()) {
let selected = country === navigation.country ? 'selected' : '';
chooseCountryHTML += `<option ${selected}>${country}</option>`;
ft_countries_html += navigation.ft_countries.indexOf(country) == -1 ? `<option>${country}</option>` : '';
}
$('#chooseCountry').html(chooseCountryHTML);
$('#chooseCountry').show();
$('#ft_add_country').html(ft_countries_html);
}
function load_summary_data() {
let last_date = _data.cases_raw.map(d => d['date']).slice(-1)[0];
for (const category of cases_categories) {
let data_category = _data.cases_selected.filter(f => f['category'] === category),
last_value = d3.format((navigation.percPopulation ? '%' : ','))(data_category.slice(-1)[0][(navigation.percPopulation ? 'field_value_pop' : 'field_value')]);
$(`#nb_${category.toLowerCase()}`).html(last_value);
// Add this data to DOM
if (category === 'Deaths' || category === 'Recovered') {
let last_value_rate = ` (${d3.format('.2%')(_data.cases_selected.filter(f => f['category'] === category + ' rate').slice(-1)[0]['field_value'])}) `;
$(`#nb_${category.toLowerCase()}_rate`).html(last_value_rate);
}
// sparkline(`#sparkline_${category.toLowerCase()}`, data_category, 'field_id', (navigation.percPopulation ? 'field_value_pop' : 'field_value'), navigation.logScale);
}
$('#lastDataPoint').html(d3.timeFormat("%d-%b-%y")(last_date));
}
function addPopulationData() {
let popData = d3.nest().key(d => d['Country/Region']).map(_data.population);
_data.cases = d3.nest()
.key(d => d['Country/Region'])
.rollup(function(a) {
let popDataEl = popData.get(a[0]['Country/Region']);
if (popDataEl) {
for (const e of a) {
e['Population'] = +popDataEl[0].Population;
e['field_value_pop'] = e['field_value'] / e['Population'];
}
}
return a;
})
.entries(_data.cases)
.map(d => d.value).flat();
}
function computeWorldData() {
return [..._data.cases, ...computeAggregate('World'),
...computeAggregate('European Union', (d => EU_countries.indexOf(d['Country/Region']) > -1)),
...computeAggregate('Europe', (d => Europe_countries.indexOf(d['Country/Region']) > -1)),
...computeAggregate('Asia', (d => Asia_countries.indexOf(d['Country/Region']) > -1)),
...computeAggregate('North America', (d => North_America_countries.indexOf(d['Country/Region']) > -1)),
...computeAggregate('Oceania', (d => Oceania_countries.indexOf(d['Country/Region']) > -1)),
...computeAggregate('Middle East', (d => Middle_East_countries.indexOf(d['Country/Region']) > -1)),
...computeAggregate('Africa', (d => Africa_countries.indexOf(d['Country/Region']) > -1)),
...computeAggregate('Central America', (d => Central_America_countries.indexOf(d['Country/Region']) > -1)),
...computeAggregate('Carribean', (d => Carribean_countries.indexOf(d['Country/Region']) > -1)),
...computeAggregate('South America', (d => South_America_countries.indexOf(d['Country/Region']) > -1))
];
}
function get_dates(data) {
list_dates = d3.set(data.map(d => d['date'])).values();
}
function filterByDate(data, categoryName=false, categoryList=false, dateVariable = "date") {
let a = d3.timeParse('%d-%b-%y')(navigation.startDate),
b = d3.timeParse('%d-%b-%y')(navigation.endDate);
if (categoryName) {
return data.filter(d => d[dateVariable] >= a &&
d[dateVariable] <= b &&
categoryList.indexOf(d[categoryName]) > -1);
} else {
return data.filter(d => d[dateVariable] >= a &&
d[dateVariable] <= b);
}
}
/**
* Prepare data for compare graph:
* 1. Filter data for the right date and countries
* 2. Offset data
* 3. Compute moving average
* 4. Retrieve keys
*/
function getCompareData(inputData) {
let data = [];
function offset_data(data, offset_value) {
// Compute offset and update key
data.forEach(function(it,ind) {
let value = ind + offset_value < data.length ? data[ind + offset_value]['field_value'] : NaN,
value_pop = ind + offset_value < data.length ? data[ind + offset_value]['field_value_pop'] : NaN;
it['field_value'] = value; // update value
it['field_value_pop'] = value_pop;
it.offset = offset_value; // add offset to the element
it.keyCompare = getKey(it);
});
return data;
}
function getKey(e) {
return `${e['Country/Region']} - ${e['category']}` + (e['offset'] > 0 ? ` (offset: ${e['offset']} day${e['offset'] > 1 ? 's' : ''})` : "");
}
navigation.elements.forEach(function(element,index) {
let _ = inputData.filter(d => (d['category'] === element['category'] &&
d['Country/Region'] === element['Country/Region'] &&
d['date'] >= d3.timeParse('%d-%b-%y')(navigation.startDate) &&
d['date'] <= d3.timeParse('%d-%b-%y')(navigation.endDate)));
_ = ma_json(offset_data($.extend(true, [], _), element['offset']),['field_value', 'field_value_pop'], navigation.maCompare);
data = data.concat(_);
});
return data;
}
function ftData(data, yVar='field_value') {
return d3.nest()
.key(d => d['Country/Region'])
.rollup(function(a) {
let na = $.extend(true, [], a).filter(d => d['category'] === navigation.ft_category),
date_threshold = d3.min(a.filter(d => d['category'] === navigation.ft_thresholdCategory &&
d[yVar] >= navigation.ft_threshold)
.map(d => d['date']));
for (let i = na.length; i >= 0 + navigation.ft_ma; i--) {
let e = na[i-1];
e['x'] = Math.round((e['date'] - date_threshold)/(24*3600*1000));
e['y'] = navigation.ft_ma === 1 ? e[yVar] : na.slice(i-navigation.ft_ma,i).reduce((t,n) => t + n[yVar],0)/navigation.ft_ma;
}
return na.reverse().slice(navigation.ft_ma-1).filter(d => d['x'] >= 0);
})
.entries(data.filter(d => (navigation.ft_countries.indexOf(d['Country/Region']) > -1)))
.map( g => g.value).flat();
}
// ========================================================================== //
// FUNCTIONS INTERACTING WITH DOM
// ==============================
function build_ft_countries_select() {
let ft_countries_html = '<option selected>Add country</option>';
for (const [index, country] of countries.entries()) {
ft_countries_html += navigation.ft_countries.indexOf(country) == -1 ? `<option>${country}</option>` : '';
}
$('#ft_add_country').html(ft_countries_html);
}
function build_ft_categories_select() {
let ft_categories_html = '',
ft_categories_threshold_html = '',
categories = d3.set(_data.cases.map(d => d['category'])).values().filter(d => !d.includes('rate'));
for (const category of categories) {
let ft_category_select = navigation.ft_category === category ? 'selected' : '',
ft_category_threshold_select = navigation.ft_thresholdCategory === category ? 'selected' : '';
ft_categories_html += `<option ${ft_category_select}>${category}</option>`;
ft_categories_threshold_html += `<option ${ft_category_threshold_select}>${category}</option>`;
}
$('#ftCategory').html(ft_categories_html);
$('#ftThresholdCategory').html(ft_categories_threshold_html);
};
function build_testing_countries_select() {
let testing_countries_html = '<option selected>Add country</option>';
for (const [index, country] of testing_countries.entries()) {
testing_countries_html+= navigation.testing_countries.indexOf(country) == -1 ? `<option>${country}</option>` : '';
}
$('#testing_add_country').html(testing_countries_html);
}
function build_testing_yaxis() {
let testing_yaxis_html = '';
for (const yaxis of testing_yaxis) {
testing_yaxis_html += navigation.testing_yVar == yaxis ? `<option selected>${yaxis}</option>` : `<option>${yaxis}</option>`;
}
$('#testingYAxis').html(testing_yaxis_html);
}
function build_elements_compare() {
let html = '',
categories = d3.set(_data.cases.map(d => d['category'])).values();
for (const [index, element] of navigation.elements.entries()) {
element.id = (parseInt(Math.random()*1e16)).toString();
html += `<div class="col-xl-4 col-md-6 col-12 mt-2 mb-2"> <div class="card element" style="border-color:${colors_countries[index]}"><svg style="position:absolute;top:0.2rem;right:0.1rem;" class="svg-icon delete-element" onclick=delete_element('${element.id}') viewBox="0 0 20 20" data-toggle="tooltip" data-placement="top" title="delete plot"><path d="M10.185,1.417c-4.741,0-8.583,3.842-8.583,8.583c0,4.74,3.842,8.582,8.583,8.582S18.768,14.74,18.768,10C18.768,5.259,14.926,1.417,10.185,1.417 M10.185,17.68c-4.235,0-7.679-3.445-7.679-7.68c0-4.235,3.444-7.679,7.679-7.679S17.864,5.765,17.864,10C17.864,14.234,14.42,17.68,10.185,17.68 M10.824,10l2.842-2.844c0.178-0.176,0.178-0.46,0-0.637c-0.177-0.178-0.461-0.178-0.637,0l-2.844,2.841L7.341,6.52c-0.176-0.178-0.46-0.178-0.637,0c-0.178,0.176-0.178,0.461,0,0.637L9.546,10l-2.841,2.844c-0.178,0.176-0.178,0.461,0,0.637c0.178,0.178,0.459,0.178,0.637,0l2.844-2.841l2.844,2.841c0.178,0.178,0.459,0.178,0.637,0c0.178-0.176,0.178-0.461,0-0.637L10.824,10z"></path></svg><div class="card-title country_element mb-1"><select onchange="update_element(this,'Country/Region')" class="select-country-element" element_id="${element.id}">`;
for (const country of countries) {
let selected = country === element['Country/Region'] ? 'selected' : '';
html += '<option ' + selected + '>' + country + '</option>';
}
html += '</select></div>';
html += `<div class="category_element mb-1 mt-1"><select onchange="update_element(this,'category')" class="select-category-element" element_id="${element.id}">`;
for (const category of categories) {
let selected = category === element['category'] ? 'selected' : '';
html += '<option ' + selected + '>' + category + '</option>';
}
html += '</select></div><div class="offset_element"><span>Offset:</span><span id="offset_'+ element.id+'" class="offset pr-1 pl-1">' + element['offset'] + '</span><span>days</span> <svg class="svg-icon" element_id="' + element.id + '" viewBox="0 0 20 20" onclick=update_offset(this,1)> <path d="M14.613,10c0,0.23-0.188,0.419-0.419,0.419H10.42v3.774c0,0.23-0.189,0.42-0.42,0.42s-0.419-0.189-0.419-0.42v-3.774H5.806c-0.23,0-0.419-0.189-0.419-0.419s0.189-0.419,0.419-0.419h3.775V5.806c0-0.23,0.189-0.419,0.419-0.419s0.42,0.189,0.42,0.419v3.775h3.774C14.425,9.581,14.613,9.77,14.613,10 M17.969,10c0,4.401-3.567,7.969-7.969,7.969c-4.402,0-7.969-3.567-7.969-7.969c0-4.402,3.567-7.969,7.969-7.969C14.401,2.031,17.969,5.598,17.969,10 M17.13,10c0-3.932-3.198-7.13-7.13-7.13S2.87,6.068,2.87,10c0,3.933,3.198,7.13,7.13,7.13S17.13,13.933,17.13,10"></path></svg><svg class="svg-icon" element_id="' + element.id + '" viewBox="0 0 20 20" onclick=update_offset(this,-1)><path d="M14.776,10c0,0.239-0.195,0.434-0.435,0.434H5.658c-0.239,0-0.434-0.195-0.434-0.434s0.195-0.434,0.434-0.434h8.684C14.581,9.566,14.776,9.762,14.776,10 M18.25,10c0,4.558-3.693,8.25-8.25,8.25c-4.557,0-8.25-3.691-8.25-8.25c0-4.557,3.693-8.25,8.25-8.25C14.557,1.75,18.25,5.443,18.25,10 M17.382,10c0-4.071-3.312-7.381-7.382-7.381C5.929,2.619,2.619,5.93,2.619,10c0,4.07,3.311,7.382,7.381,7.382C14.07,17.383,17.382,14.07,17.382,10"></path></svg></div></div></div>';
}
$('#compare_elements_container').html(html);
}
function build_elements_mobility() {
let html = '';
for (const [index, element] of navigation.mobility_elements.entries()) {
let selectRegion = '',
selectType = '';
for (const region of mobilityRegions) {
let selected = region === element['region'] ? 'selected' : '';
selectRegion += '<option ' + selected + '>' + region + '</option>';
}
for (const type of mobilityTypes) {
let selected = type === element['transportation_type'] ? 'selected' : '';
selectType += '<option ' + selected + '>' + type + '</option>';
}
element.id = (parseInt(Math.random()*1e16)).toString();
html += `
<div class="col-xl-4 col-md-6 col-12 mt-2 mb-2">
<div class="card element" style="border-color:${colors_countries[index]}">
<svg style="position:absolute;top:0.2rem;right:0.1rem;" class="svg-icon delete-element" onclick=delete_mobility_element('${element.id}') viewBox="0 0 20 20" data-toggle="tooltip" data-placement="top" title="delete plot">
<path d="M10.185,1.417c-4.741,0-8.583,3.842-8.583,8.583c0,4.74,3.842,8.582,8.583,8.582S18.768,14.74,18.768,10C18.768,5.259,14.926,1.417,10.185,1.417 M10.185,17.68c-4.235,0-7.679-3.445-7.679-7.68c0-4.235,3.444-7.679,7.679-7.679S17.864,5.765,17.864,10C17.864,14.234,14.42,17.68,10.185,17.68 M10.824,10l2.842-2.844c0.178-0.176,0.178-0.46,0-0.637c-0.177-0.178-0.461-0.178-0.637,0l-2.844,2.841L7.341,6.52c-0.176-0.178-0.46-0.178-0.637,0c-0.178,0.176-0.178,0.461,0,0.637L9.546,10l-2.841,2.844c-0.178,0.176-0.178,0.461,0,0.637c0.178,0.178,0.459,0.178,0.637,0l2.844-2.841l2.844,2.841c0.178,0.178,0.459,0.178,0.637,0c0.178-0.176,0.178-0.461,0-0.637L10.824,10z"></path>
</svg>
<div class="card-title country_element mb-1">
<select onchange="update_mobility_element(this,'region')" class="select-country-element" element_id="${element.id}">
${selectRegion}
</select>
</div>
<div class="category_element mb-1 mt-1">
<select onchange="update_mobility_element(this,'transportation_type')" class="select-category-element" element_id="${element.id}">
${selectType}
</select>
</div>
</div>
</div>`;
}
$('#mobility_elements_container').html(html);
};
function build_ft_countries() {
let html = '';
for (const [i, country] of navigation.ft_countries.entries()) {
html += `
<div class="p-2 ml-1 mr-1 mt-1 mb-1 badge" style="display:inline-block; background-color:${colors_countries[i]};"><span>${country}</span>
<svg class="svg-icon delete-element mb-1" onclick=remove_ft_country(${i}) viewBox="0 0 20 20" data-toggle="tooltip" data-placement="top" title="delete plot"><path d="M10.185,1.417c-4.741,0-8.583,3.842-8.583,8.583c0,4.74,3.842,8.582,8.583,8.582S18.768,14.74,18.768,10C18.768,5.259,14.926,1.417,10.185,1.417 M10.185,17.68c-4.235,0-7.679-3.445-7.679-7.68c0-4.235,3.444-7.679,7.679-7.679S17.864,5.765,17.864,10C17.864,14.234,14.42,17.68,10.185,17.68 M10.824,10l2.842-2.844c0.178-0.176,0.178-0.46,0-0.637c-0.177-0.178-0.461-0.178-0.637,0l-2.844,2.841L7.341,6.52c-0.176-0.178-0.46-0.178-0.637,0c-0.178,0.176-0.178,0.461,0,0.637L9.546,10l-2.841,2.844c-0.178,0.176-0.178,0.461,0,0.637c0.178,0.178,0.459,0.178,0.637,0l2.844-2.841l2.844,2.841c0.178,0.178,0.459,0.178,0.637,0c0.178-0.176,0.178-0.461,0-0.637L10.824,10z"></path></svg></div>`;
}
$('#ft_countries_container').html(html);
update_ft_threshold();
}
function build_testing_countries() {
let html = '';
for (const [i, country] of navigation.testing_countries.entries()) {
html += `
<div class="p-2 ml-1 mr-1 mt-1 mb-1 badge" style="display:inline-block; background-color:${colors_countries[i]};"><span>${country}</span>
<svg class="svg-icon delete-element mb-1" onclick=remove_testing_country(${i}) viewBox="0 0 20 20" data-toggle="tooltip" data-placement="top" title="delete plot"><path d="M10.185,1.417c-4.741,0-8.583,3.842-8.583,8.583c0,4.74,3.842,8.582,8.583,8.582S18.768,14.74,18.768,10C18.768,5.259,14.926,1.417,10.185,1.417 M10.185,17.68c-4.235,0-7.679-3.445-7.679-7.68c0-4.235,3.444-7.679,7.679-7.679S17.864,5.765,17.864,10C17.864,14.234,14.42,17.68,10.185,17.68 M10.824,10l2.842-2.844c0.178-0.176,0.178-0.46,0-0.637c-0.177-0.178-0.461-0.178-0.637,0l-2.844,2.841L7.341,6.52c-0.176-0.178-0.46-0.178-0.637,0c-0.178,0.176-0.178,0.461,0,0.637L9.546,10l-2.841,2.844c-0.178,0.176-0.178,0.461,0,0.637c0.178,0.178,0.459,0.178,0.637,0l2.844-2.841l2.844,2.841c0.178,0.178,0.459,0.178,0.637,0c0.178-0.176,0.178-0.461,0-0.637L10.824,10z"></path></svg></div>`;
}
$('#testing_countries_container').html(html);
}
function update_ft_threshold() {
let max_value = Math.min(d3.max(_data.cases.filter(d => (navigation.ft_countries.indexOf(d['Country/Region']) > -1) &&
(d['category'] === 'Deaths'))
.map(d => d['field_value'])),1000);
$('#thresholdRange').attr('max', max_value.toString());
}
function remove_ft_country(index) {
navigation.ft_countries.splice(index,1);
updateNavigation({"ft_countries": navigation.ft_countries});
build_ft_countries();
build_ft_countries_select();
plots['ft_graph'].draw({"data": ftData(_data.cases),
"categories":navigation.ft_countries});
}
function remove_testing_country(index) {
navigation.testing_countries.splice(index,1);
updateNavigation({"testing_countries": navigation.testing_countries});
build_testing_countries();
build_testing_countries_select();
plots['testing_graph'].draw({"data": filterByDate(_data.testing, 'Entity', navigation.testing_countries),
"categories": navigation.testing_countries});
}
function update_offset(el, value) {
let element_id = $(el).attr('element_id');
navigation.elements.forEach(function(it, ind) {
if (it.id === element_id) {
it.offset = Math.max(0, it.offset + parseInt(value));
$(`#offset_${element_id}`).html(it.offset);
}
});
compareGraph.draw({"data": getCompareData(_data.cases),
"categories": get_list_elements()});
}
function update_element(el, property) {
let element_id = $(el).attr('element_id');
navigation.elements.forEach(function(it, ind) {
if (it.id === element_id) {
it[property] = el.value;
}
});
updateNavigation({"elements": navigation.elements});
plots['compare_graph'].draw({"data":getCompareData(_data.cases),
"categories": get_list_elements()});
}
function update_mobility_element(el, property) {
let element_id = $(el).attr('element_id');
navigation.mobility_elements.forEach(function(it, ind) {
if (it.id === element_id) {
it[property] = el.value;
}
});
updateNavigation({"mobility_elements": navigation.mobility_elements});
plots['mobility_graph'].draw({"data": filterByDate(_data.mobility,'key',
navigation.mobility_elements.map(d => `${d['region']} - ${d['transportation_type']}`)),
"categories": navigation.mobility_elements.map(d => `${d['region']} - ${d['transportation_type']}`)});
}
function get_list_elements() {
function getKey(e) {
return `${e['Country/Region']} - ${e['category']}` + (e['offset'] > 0 ? ` (offset: ${e['offset']} day${e['offset'] > 1 ? 's' : ''})` : "");
}
return navigation.elements.map(d => getKey(d));
}
function add_element() {
let last_el = navigation.elements.length > 0 ? $.extend(true, {}, navigation.elements[navigation.elements.length-1]) : {
"Country/Region": "France",
"category": "Confirmed",
"offset": 0
}; // copy last element
last_el['Country/Region'] = navigation.elements.length > 0 ? countries[Math.min(countries.indexOf(last_el['Country/Region'])+1,countries.length-1)] : 'France';
updateNavigation({"elements": navigation.elements.concat(last_el)});
build_elements_compare();
plots['compare_graph'].draw({"data":getCompareData(_data.cases),
"categories": get_list_elements()});
}
function delete_element(id) {
navigation.elements = navigation.elements.filter(d => d.id != id);
updateNavigation({"elements": navigation.elements});
build_elements_compare();
plots['compare_graph'].draw({"data":getCompareData(_data.cases),
"categories": get_list_elements()});
}
function add_mobility_element() {
let last_el = navigation.mobility_elements.length > 0 ? $.extend(true, {}, navigation.mobility_elements.slice(-1)[0]) : {
"region": "Paris",
"transportation_type": "walking"
}; // copy last element
updateNavigation({"mobility_elements": navigation.mobility_elements.concat(last_el)});
last_el['region'] = navigation.mobility_elements.length > 0 ? mobilityRegions[Math.min(mobilityRegions.indexOf(last_el['region'])+1,mobilityRegions.length-1)] : 'Paris';
build_elements_mobility();
plots['mobility_graph'].draw({"data": filterByDate(_data.mobility,'key',
navigation.mobility_elements.map(d => `${d['region']} - ${d['transportation_type']}`)),
"categories": navigation.mobility_elements.map(d => `${d['region']} - ${d['transportation_type']}`)});
}
function delete_mobility_element(id) {
updateNavigation({"mobility_elements": navigation.mobility_elements.filter(d => d.id != id)});
build_elements_mobility();
plots['mobility_graph'].draw({"data": filterByDate(_data.mobility,'key',
navigation.mobility_elements.map(d => `${d['region']} - ${d['transportation_type']}`)),
"categories": navigation.mobility_elements.map(d => `${d['region']} - ${d['transportation_type']}`)});
}
function addDatestoSelect() {
let html_start_dates = '',
html_end_dates = '';
for (const d of list_dates) {
html_start_dates += '<option ' + (d === navigation.startDate ? 'selected' : '') + '>' + d + '</option>';
html_end_dates += '<option ' + (d === navigation.endDate ? 'selected' : '') + '>' + d + '</option>';
}
$('.select-dates[start]').each((i,e) => $(e).html(html_start_dates));
$('.select-dates[end]').each((i,e) => $(e).html(html_end_dates));
}
function updateDatesPlot(target) {
switch (target) {
case 'country_graph':
plots['country_graph'].draw({"data": filterByDate(_data.cases_selected, 'category', cases_categories)});
plots['country_graph_rates'].draw({"data": filterByDate(_data.cases_selected, 'category', rates_categories)});
plots['country_graph_new_cases'].draw({"data": filterByDate(_data.cases_selected, 'category', new_cases_categories)});
break;
case 'compare_graph':
plots['compare_graph'].draw({"data":getCompareData(_data.cases)});
break;
case 'testing_graph':
plots['testing_graph'].draw({"data": filterByDate(_data.testing, 'Entity', navigation.testing_countries)});
break;
case 'mobility_graph':
plots['mobility_graph'].draw(
{"data": filterByDate(_data.mobility,'key',
navigation.mobility_elements.map(d => `${d['region']} - ${d['transportation_type']}`))
});
break;
case 'hospitalization_graph':
plots['hospitalization_graph'].draw(
{"data": ma_json(filterByDate(_data.hospitalization,
'Category',
navigation.hospitalizationVariables),
["value"],
navigation.maHospitalization
)
}
);
}
}
function download_data(id) {
switch (id) {
case 'country_graph':
countryGraph.downloadData();
break;
case 'country_graph_rates':
plots['country_graph_rates'].downloadData();
break;
case 'country_graph_new_cases':
plots['country_graph_new_cases'].downloadData();
break;
case 'compare_graph':
plots['compare_graph'].downloadData();
break;
case 'ft_graph':
plots['ft_graph'].downloadData();
break;
case 'testing_graph':
plots['testing_graph'].downloadData();
break;
}
}
function buildSelectHospitalizationVariables() {
let hospitalizationVariables = Grapher.unique(_data.hospitalization.map(d => d['Category']));
let html = "";
for (const v of hospitalizationVariables) {
let selected = navigation.hospitalizationVariables.indexOf(v) > -1 ? 'selected' : '';
html += `<option ${selected}>${v}</option>`;
}
$('#hospitalization_variables').html(html);
}
function buildCustomSettings() {
// Settings
let htmlSettings = '';
navigation.custom_settings.forEach(function(it,ind) {
htmlSettings += `
<div class="form-group form-inline">
<label for="${it[0].replace(' ','_')}">${it[0]}</label>
<input id="${it[0].replace(' ','_')}" type="text" class="setting form-control form-control-sm mx-sm-3" target="${it[1]}" css="${it[2]}" value="${it[3]}">
</div>
`;
// activate rule
$(it[1]).css(it[2], it[3]);
// insert rule to DOM
stylesheet.insertRule(`${it[1]} { ${it[2]}: ${it[3]}; }`, stylesheet.cssRules.length);
});
$('#form_settings').html(htmlSettings);
}
// ========================================================================== //
// CHARTS
// ======
class CovidGraph extends Grapher {
constructor(id, options= {}) {
let default_options = {
"x": {
"name": "date",
"tickFormat": d3.timeFormat("%d/%m/%y"),
"scale": "scaleTime",
"nice": false
},
"y": {
"name": 'field_value',
"scale": "scaleLinear",
},
"category": {
"name": "category"
},
"type": "line",
"style": {
"tooltipColor": () => (navigation.darkMode ? '#dadada' : '#181818')
},
};
Grapher.updateDict(default_options, options, true);
super(id,
default_options,
graphWidth,
graphHeight);
}
}
// ========================================================================== //
let plots = {};
plots['country_graph'] = new CovidGraph('country_graph',
{
"y": {
"name": navigation.percPopulation ? 'field_value_pop' : 'field_value',
"scale": navigation.logScale ? "scaleLog" : "scaleLinear",
"tickFormat": Grapher.formatTick(navigation.logScale, navigation.percPopulation)
},
"categories": cases_categories,
"type": navigation.lines ? "line" : "bar",
"advanced": {
"additionalColumnsInData": ['Country/Region','field_value_pop','field_value']
},
"style": {
"colors": colors,
"tooltipColor": () => (navigation.darkMode ? '#dadada' : '#181818')
}
});
plots['country_graph_rates'] = new CovidGraph('country_graph_rates',
{
"y": {
"tickFormat": Grapher.formatTick(false, true)
},
"category": {
"name": "category"
},
"style": {
"colors": colors,
"tooltipColor": () => (navigation.darkMode ? '#dadada' : '#181818')
},
"categories": rates_categories,
"advanced": {
"additionalColumnsInData": ['Country/Region']
}});
plots['country_graph_new_cases'] = new CovidGraph('country_graph_new_cases',
{
"y": {
"tickFormat": Grapher.formatTick(false, false)
},
"style": {