-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathworld_dashboard.html
1936 lines (1753 loc) · 65.1 KB
/
world_dashboard.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
<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" />
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Expires" content="0" />
<link rel="icon" href="./static/img/favicon.ico">
<title>COVID-19 World CrRW Status Trend</title>
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" crossorigin="anonymous">
<script src="https://kit.fontawesome.com/cb45cc91b0.js" crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.css" />
<style>
html, body {
overflow: hidden;
font-size: 12px;
}
p {
margin-bottom: .5rem;
}
.box-header-nav {
padding: 0 0 0 15px;
}
/* a start screen for IE and hiding init */
#start-screen {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: 9999;
background: white;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
#ss-msg {
width: 100%;
padding: 10px 0;
text-align: center;
}
.wrapper {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
overflow-y: auto;
overflow-x: hidden;
}
.d3-tip {
line-height: 1;
padding: 6px;
background: rgba(0, 0, 0, 0.7);
color: #fff;
border-radius: 4px;
font-size: 12px;
}
/* for the calendar chart */
.fig-crrw-calendar {
width: 100%;
height: 95px;
}
.fig-crrw-calendar .crrw-day-label {
display: inline-block;
width: 80px;
margin: 0 5px 1px 0 ;
font-size: 10px;
}
.fig-crrw-calendar .crrw-day-chart {
width: calc(100% - 80px);
height: 95px;
}
/* for the 1-d calendar chart */
.fig-crrw-1dcal {
height: 12px;
width: 100%;
padding: 0 0 0 5px;
}
.fig-crrw-1dcal:hover {
background: whitesmoke;
}
.fig-crrw-1dcal .crrw-day-label {
display: inline-block;
width: 80px;
height: 12px;
margin: 0 5px 1px 0 ;
overflow: hidden;
white-space: nowrap;
font-size: 10px;
line-height: 12px;
}
.fig-crrw-1dcal .crrw-day {
display: inline-block;
width: 6px;
height: 6px;
margin: 0 1px 1px 0 ;
}
/* for the trend chart */
.fig-crrw-trend {
width: 100%;
height: 165px;
margin: 0 0 3px 0;
background: white;
}
.crrw-trend-info {
display: inline-block;
width: 80px;
padding: 0 0 0 5px;
}
.crrw-trend-bar {
display: block;
width: 100%;
padding: 2px 0;
}
.crrw-trend-label {
display: inline-block;
width: 100%;
}
.crrw-trend-label:hover {
cursor: grab;
cursor: -moz-grab;
cursor: -webkit-grab;
background: whitesmoke;
}
.crrw-trend-label:active {
cursor: grabbing;
cursor: -moz-grabbing;
cursor: -webkit-grabbing;
background: whitesmoke;
}
.crrw-trend-chart {
width: 100%;
min-width: 600px;
height: 150px;
}
.crrw-day-R {
background: red;
}
.crrw-day-G {
background: green;
}
.crrw-day-Y {
background: gold;
}
.crrw-day-badge {
padding: 1px 5px;
border-radius: 5px;
}
#header {
background: whitesmoke;
}
#header a {
color: #555555;
}
.modal-dialog {
max-width: 700px !important;
}
.attr-color-legend {
display: inline-block;
width: 50px;
height: 16px;
}
.region-detail-box {
width: 100%;
max-height: 150px;
border-top: 1px dotted #eeeeee;
padding: 5px;
}
.region-detail-item {
display: inline-block;
margin: 0 10px 0 0;
}
.region-detail-name {
background: #ececec;
padding: 0 3px;
border-bottom: 1px solid #ececec;
}
.region-detail-value {
font-weight: bold;
margin-left: -3px;
padding: 0 3px;
border-bottom: 1px solid #ececec;
}
</style>
</head>
<body>
<div id="start-screen">
<h1>
<i class="fa fa-globe-americas"></i>
COVID-19 World CrRW Status Trend
</h1>
<div id="ss-msg">Loading data and initializing plots ...</div>
</div>
<div class="container-fluid wrapper">
<div id="header" class="row mb-3">
<div class="col">
<div class="mt-2 mb-2">
<i class="fa fa-globe-americas"></i> COVID-19 World CrRW Status Trend |
<a target="_blank" href="./"><i class="fa fa-home"></i> Home</a> |
<a href="javascript:void(0);"
onclick="jarvis.modal('About CrRW and how to use this website',$('#about-text').html());">
<i class="fa fa-question-circle"></i>
About
</a> |
<a href="https://github.com/OHNLP/covid19tracking" target="_blank">
<i class="fa fa-github"></i>
Source Code
</a>
</div>
</div>
</div>
<div class="row">
<div class="col d-flex flex-row">
<div id="fig_crrw_worldmap_vpp" class="box" style="width: 100%;">
<h5>
<i class="fa fa-globe-americas"></i>
World Map of CrRW Status for <span id="fig_crrw_worldmap_last_update"> </span>
</h5>
<div class="d-flex flex-row justify-content-start">
<div class="btn-group">
<button id="fig_crrw_worldmap_select_colorscale"
class="btn btn-light btn-sm dropdown-toggle"
type="button" data-toggle="dropdown" aria-haspopup="true"
aria-expanded="false">
Color: {{ attr_colorscales[current.attr].name }}
</button>
<div class="dropdown-menu">
<a class="dropdown-item"
href="javascript:void(0);"
v-for="attr_colorscale, attr in attr_colorscales"
v-on:click="update_color(attr)">
<span class="attr-color-legend"
v-bind:style="get_attr_colorscale_legend(attr_colorscale)">
</span>
{{ attr_colorscale.name }}
{{ get_attr_colorscale_value_legend(attr_colorscale) }}
</a>
</div>
</div>
<div class="ml-3 pt-1" style="width: 200px">
<span class="attr-color-legend-large d-flex justify-content-between"
v-bind:style="get_attr_colorscale_legend(attr_colorscales[current.attr])">
<span class="text-sm ml-1">{{ get_attr_colorscale_min_value_legend(attr_colorscales[current.attr]) }}</span>
<span class="text-sm mr-1 text-white">{{ get_attr_colorscale_max_value_legend(attr_colorscales[current.attr]) }}</span>
</span>
</div>
</div>
<div id="fig_crrw_worldmap" style="width: 100%; height: 100%;"></div>
<div class="region-detail-box" v-if="country.country == null"></div>
<div class="region-detail-box" v-else>
<p>For {{ date }}, {{ country.data.name }}, (Population: {{ fmt_comma(country.data.pop) }}). </p>
<div class="region-detail-item" >
<span class="region-detail-name">Cr7d100k:</span>
<span class="region-detail-value">{{ get_detail().crp }} cases per 100k capita</span>
</div>
<div class="region-detail-item" >
<span class="region-detail-name">RW_Cr7d100k:</span>
<span class="region-detail-value">{{ get_detail().crt }} </span>
</div>
<div class="region-detail-item" >
<span class="region-detail-name">New cases:</span>
<span class="region-detail-value">{{ fmt_comma(get_detail().dnc) }} </span>
</div>
<div class="region-detail-item" >
<span class="region-detail-name">Total cases:</span>
<span class="region-detail-value">{{ fmt_comma(get_detail().ncc) }} </span>
</div>
<div class="region-detail-item" >
<span class="region-detail-name">Vaccination Administered:</span>
<span class="region-detail-value">
{{ fmt_ind_val('vaps', get_detail().vap) }}
({{ fmt_ind_val('vacs', get_detail().vac) }} doses)
<a style="color:#777777;" target="_blank" href="https://ourworldindata.org/covid-vaccinations" title="The latest vaccination data come from the Our World in Data COVID vaccination data">
<i class="far fa-question-circle"></i>
</a>
</span>
</div>
<div class="region-detail-item" >
<span class="region-detail-name">Fully Vaccinated:</span>
<span class="region-detail-value">
{{ fmt_ind_val('fvps', get_detail().fvp) }}
({{ fmt_ind_val('fvcs', get_detail().fvc) }} people)
<a style="color:#777777;" target="_blank" href="https://ourworldindata.org/covid-vaccinations" title="The latest vaccination data come from the Our World in Data COVID vaccination data">
<i class="far fa-question-circle"></i>
</a>
</span>
</div>
<div class="region-detail-item" >
<span class="region-detail-name">Case Doubling Time:</span>
<span class="region-detail-value">{{ (get_detail().cdt).toFixed(1) }} days</span>
</div>
<div class="region-detail-item" >
<span class="region-detail-name">Total death:</span>
<span class="region-detail-value">{{ fmt_comma(get_detail().dth) }} </span>
</div>
<div class="region-detail-item" >
<span class="region-detail-name">Death rate:</span>
<span class="region-detail-value">{{ (get_detail().dtr*100).toFixed(2) }} %</span>
</div>
<div class="region-detail-item" >
<span class="region-detail-name">Total Cases / Population:</span>
<span class="region-detail-value">{{ (get_detail().tcp*100).toFixed(4) }} %</span>
</div>
</div>
</div>
</div>
</div>
<div id="toast" class="toast" style="position: absolute; top: 10px; right: 10px;">
<div class="toast-header">
<svg class="bd-placeholder-img rounded mr-2" width="15" height="15" xmlns="http://www.w3.org/2000/svg" preserveAspectRatio="xMidYMid slice" focusable="false" role="img"><rect id="toast_rect" width="100%" height="100%" fill="#007aff"></rect></svg>
<strong class="mr-auto">Bootstrap</strong>
<small> </small>
<button type="button" class="ml-2 mb-1 close" data-dismiss="toast" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div id="toast_body" class="toast-body">
</div>
</div>
<!-- Modal -->
<div class="modal fade" id="modal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="modal-title">Modal title</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div id="modal-body" class="modal-body">
</div>
</div>
</div>
</div>
<div id="about-text" style="display: none;">
<style>
.rcf-em1 {
font-weight: bold;
background-color: whitesmoke;
border-radius: 5px;
padding: 0 3px;
}
</style>
<h5>CrRW: Cr7d100k and RW_Cr7d100k</h5>
<p>We propose to use <b>CrRW</b> to measure the trends in COVID-19 or other infectious diseases, which includes two indicators: </p>
<p>1. <b>Cr7d100k</b>: 7-day smoothed average daily case rate per 100k capita;</p>
<p>2. <b>RW_Cr7d100k</b>: the ratio of this week’s Cr7d100k comparing to the week before.</p>
<p>The data for calculating CrRW are from USAFacts and COVIDTracking.</p>
<p>By using these two indicators in combination, we can depict the current status of the epidemic as well as recent trends with following thresholds:</p>
<p>1. The <b class="badge badge-success">GREEN</b> status: There are two cases. First, if <span class="rcf-em1">Cr7d100k <= 10</span> for the past seven days, it would be safe. Second, if <span class="rcf-em1">Cr7d100k < 15 and RW_Cr7d100k < 1</span> for the past seven days, it would be relative safe; </p>
<p>2. The <b class="badge badge-danger">RED</b> status: There are two cases. First, if <span class="rcf-em1">Cr7d100k > 30</span> for the past seven days, the pandemic is extremely serious. Second, if <span class="rcf-em1">Cr7d100k > 15 and RW_Cr7d100k > 1.1</span> and for the past seven days, the current pandemic situation is bad or the trend is bad;</p>
<p>3. The <b class="badge badge-warning">ORANGE</b> status: Everything else is orange status as we cannot say much – it can go either way.</p>
<hr>
<h5>Data Sources</h5>
<p>We get the latest COVID-19 data from the following data sources. <br>
Due to differences in data update frequency, sometimes we have to use the data of closest dates to update the dashboard if the latest data is not available.</p>
<p>
<a href="https://github.com/CSSEGISandData/COVID-19"><b>John Hopkins Coronavirus Resource Center</b></a>:
The global and U.S. state-level cases and deaths data.
</p>
<p>
<a href="https://covidtracking.com/"><b>COVID Tracking</b></a>:
The state-level cases, deaths, and tests data.
</p>
<p>
<a href="https://covidactnow.org/"><b>COVID Act Now</b></a>:
The state-level and county-level cases, deaths, and vaccination data.
</p>
<p>
<a href="https://covid.cdc.gov/covid-data-tracker/#vaccinations"><b>CDC Vaccination Tracker</b></a>:
The latest state-level vaccination data.
</p>
<p>
<a href="https://covid.cdc.gov/covid-data-tracker/#pandemic-vulnerability-index"><b>NIH NIEHS COVID-19 Data Repository</b></a>:
The county-level and state-level PVI* data.
</p>
<p>
<a href="https://covid.cdc.gov/covid-data-tracker/#pandemic-vulnerability-index"><b>USA Facts</b></a>:
The county-level cases and deaths data.
</p>
<p>
<a href="https://ourworldindata.org/covid-vaccinations"><b>Our World in Data</b></a>:
The global vaccination data.
</p>
<p>* The Pandemic Vulnerability Index (PVI) is an indicator which integrates baseline data on relevant community vulnerabilities with dynamic data on local infection rates and interventions <a target="_blank" href="https://www.ncbi.nlm.nih.gov/pmc/articles/PMC7430608/">PMID: 32817964</a>. The data of PVI model are from <a target="_blank" href="https://covid.cdc.gov/covid-data-tracker/#pandemic-vulnerability-index">CDC COVID Data Tracker</a>.</p>
<hr>
</div>
<!-- modal of trend lines -->
<div id="vw_modal_line" class="modal" tabindex="-1">
<div class="modal-dialog" style="max-width: 80% !important;">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" style="margin-right: 10px;">
<i class="fa fa-line-chart"></i>
CrRW Status Trend
</h5>
<div class="form-inline">
<button type="button" class="btn btn-light btn-sm mr-2 "
onclick="jarvis.reset_fig_crrw_trends();">
<i class="fa fa-undo"></i>
Reset
</button>
</div>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<div id="fig_crrw_trends" style="">
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</div>
<script>
var isIE = /*@cc_on!@*/false || !!document.documentMode;
if (isIE) {
document.getElementById('ss-msg').innerHTML = 'The visualization used in this website require advanced web technologies, which are <b>NOT</b> supported by Internet Explorer.<br>Try using Google Chrome, Apple Safari, Mozilla Firefox or other modern browsers to access:<br><span style="font-size:1.2em;">' + location.href + '</span>';
}
</script>
<!-- JavaScript packages -->
<script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js"></script>
<script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
<script src="https://d3js.org/d3.v5.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/echarts.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]"></script>
<script>
var fig_crrw_worldmap = {
plot_id: 'fig_crrw_worldmap',
vpp: null,
vpp_id: '#fig_crrw_worldmap_vpp',
data: null,
data_file: 'WORLD-history.json',
colorscale: {
cdts: {
name: 'Case Doubling Time',
abbr: 'cdts',
min: 0,
mid: 50,
max: 100,
schema: [
[0, 'rgba(255, 0, 0, 1)'],
[0.5, 'rgba(255, 255, 0, 1)'],
[1, 'rgba(144, 238, 144, 1)']
]
},
crcs: {
name: 'CrRW Status',
abbr: 'crcs',
min: 0,
mid: 1,
max: 2,
schema: [
[0, 'green'],
[0.5, 'gold'],
[1, 'red']
]
},
tcps: {
name: 'Total Cases / Population',
abbr: 'tcps',
min: 0,
mid: 0.1,
max: 0.2,
schema: [
[0, 'rgba(254, 240, 206, 1)'],
[0.5, 'rgba(253, 164, 93, 1)'],
[1, 'rgba(255, 30, 2, 1)']
]
},
vaps: {
name: 'Vaccination Administered %',
abbr: 'vaps',
min: 0,
mid: 0.6,
max: 1.2,
schema: [
[0, 'rgba(255, 255, 255, 1)'],
[0.5, 'rgba(117, 218, 157, 1)'],
[1, 'rgba(1, 117, 31, 1)']
]
},
fvps: {
name: 'Fully Vaccinated Percentage',
abbr: 'fvps',
min: 0,
mid: 0.4,
max: 0.8,
schema: [
[0, 'rgba(255, 255, 255, 1)'],
[0.5, 'rgba(141, 199, 252, 1)'],
[1, 'rgba(0, 76, 145, 1)']
]
}
},
fmt_comma: d3.format(","),
plot_config: {
responsive: true,
// displayModeBar: false,
scrollZoom: false,
},
current: {
date: null,
attr: 'crcs'
},
load: function() {
$.get(
'./covid_data/v2/' + this.data_file,
{ver: Math.random()},
function(data) {
fig_crrw_worldmap.init(data);
}, 'json'
);
},
init: function() {
// init the vpp part
this.vpp = new Vue({
el: this.vpp_id,
data: {
attr_colorscales: this.colorscale,
current: this.current,
date: null,
dates: [],
country: {
country: null,
data: {}
}
},
methods: {
get_attr_colorscale_legend: function(cs) {
var style = '';
if (cs.abbr == 'crcs') {
style = "background: linear-gradient( to right, ";
style += cs.schema[0][1] + ", ";
style += cs.schema[0][1] + " 33%, ";
style += cs.schema[1][1] + " 33%, ";
style += cs.schema[1][1] + " 66%, ";
style += cs.schema[2][1] + " 66% ";
style += ")";
} else {
style = "background: linear-gradient(90deg";
for (var i = 0; i < cs.schema.length; i++) {
var schema_item = cs.schema[i];
style += ', ' + schema_item[1] + ' ' + (schema_item[0] * 100) + '%'
}
style += ');'
}
return style;
},
get_attr_colorscale_value_legend: function(cs) {
if (['tcps', 'fvps', 'vaps'].indexOf(cs.abbr)>=0) {
return '('+
this.get_attr_colorscale_min_value_legend(cs) +
' - ' +
this.get_attr_colorscale_max_value_legend(cs) +
')';
} else if (['crcs'].indexOf(cs.abbr)>=0) {
return '(Green, Yellow, Red)';
} else {
return '('+cs.min+' - '+cs.max+')';
}
},
get_attr_colorscale_min_value_legend: function(cs) {
if (['tcps', 'fvps', 'vaps'].indexOf(cs.abbr)>=0) {
return (cs.min*100).toFixed(1) +'%';
} else if (['crcs'].indexOf(cs.abbr)>=0) {
return 'Green';
} else {
return cs.min;
}
},
get_attr_colorscale_max_value_legend: function(cs) {
if (['tcps', 'fvps', 'vaps'].indexOf(cs.abbr)>=0) {
return (cs.max*100).toFixed(1) +'%';
} else if (['crcs'].indexOf(cs.abbr)>=0) {
return 'Red';
} else {
return cs.max;
}
},
update_color: function(attr) {
this.current.attr = attr;
fig_crrw_worldmap.update(fig_crrw_worldmap.data);
},
get_detail: function() {
var date_idx = this.dates.indexOf(this.date);
return {
country: this.country.data.country,
name: this.country.data.name,
state: this.country.data.state,
pop: this.country.data.pop,
cdt: this.country.data.cdts[date_idx],
crp: this.country.data.crps[date_idx],
crt: this.country.data.crts[date_idx],
ncc: this.country.data.nccs[date_idx],
dnc: this.country.data.dncs[date_idx],
dth: this.country.data.dths[date_idx],
dtr: this.country.data.dtrs[date_idx],
crc: this.country.data.crcs[date_idx],
tcp: this.country.data.nccs[date_idx] / this.country.data.pop,
fvc: this.country.data.fvcs[date_idx],
fvp: this.country.data.fvps[date_idx],
vac: this.country.data.vacs[date_idx],
vap: this.country.data.vaps[date_idx],
}
},
fmt_comma: function(v) {
return fig_crrw_worldmap.fmt_comma(v);
},
fmt_ind_val: function(ind, val) {
return jarvis.ind2txt(ind).fmt(val);
},
fmt_val: function(ind, val) {
return jarvis.val2txt(ind, val);
}
}
});
},
update: function(data) {
this.data = data;
this.current.date = data.date;
// update the vpp
this.vpp.date = data.date;
this.vpp.dates = data.dates;
this._create_plot_data();
this._create_plot_layout();
Plotly.purge(this.plot_id);
Plotly.newPlot(
this.plot_id,
this.plot_data,
this.plot_layout,
this.plot_config
);
// update the last update
$('#' + this.plot_id + '_last_update').html(data.date);
// re-bind click event
this._bind_click_event();
// re-bind hover event
this._bind_hover_event();
},
update_by_date: function(date) {
this.current.date = date;
// update hte vpp
this.vpp.date = date;
// create the data on this date
var mydata = this._create_mydata();
var update_plot_data = [{
locations: this.unpack(mydata, 'country'),
text: this.unpack(mydata, 'txt'),
z: this.unpack(mydata, 'val'),
}];
// update the figure
Plotly.animate(
this.plot_id,
{
data: update_plot_data,
traces: [0],
layout: {},
},
{
transition: {
duration: 100,
easing: "cubic-in-out",
},
frame: {
duration: 100,
},
}
);
// update hte last update time
$('#' + this.plot_id + '_last_update').html(this.current.date);
},
_bind_click_event: function() {
// bind click events
this.plot_elm = document.getElementById(this.plot_id);
this.plot_elm.on('plotly_click', function(data) {
var country = data.points[0].location;
jarvis.show_country(country);
fig_crrw_worldmap.show_detail(country)
});
},
_bind_hover_event: function() {
// bind hover events
this.plot_elm = document.getElementById(this.plot_id);
this.plot_elm.on('plotly_hover', function(data) {
var country = data.points[0].location;
});
},
show_detail: function(country) {
this.vpp.country.country = country;
this.vpp.country.data = this.data.world_data[country];
// this.vpp.$forceUpdate();
},
_create_mydata: function() {
var date = this.current.date;
var date_idx = this.data.dates.indexOf(date);
var rows = this.data.world_data;
var mydata = [];
for (var country in rows) {
if (rows.hasOwnProperty(country)) {
var obj = rows[country];
var country_name = obj.name;
var cdt = obj.cdts[date_idx];
var dnc = obj.dncs[date_idx];
var ncc = obj.nccs[date_idx];
var crp = obj.crps[date_idx];
var crt = obj.crts[date_idx];
var dth = obj.dths[date_idx];
var dtr = obj.dtrs[date_idx];
var crc = obj.crcs[date_idx];
var crc_v = {R:2, Y:1, G:0}[crc];
var tcp = ncc / obj.pop;
// decide show which value as default
var val = null;
if (this.current.attr == 'crcs') {
val = crc_v;
} else if (this.current.attr == 'tcps') {
val = tcp;
} else {
val = obj[this.current.attr][date_idx];
}
var txt = this._get_hover_text(obj, date, date_idx, this.current.attr, val);
var r = {
country: country,
val: val,
txt: txt
};
mydata.push(r);
}
}
this._mydata = mydata;
return mydata;
},
_get_hover_text: function(obj, date, date_idx, attr, val) {
return date + ', ' +
obj.name + '<br>' +
jarvis.ind2txt(attr).name + ': ' +
jarvis.ind2txt(attr).fmt(val);
},
_create_plot_data: function() {
var mydata = this._create_mydata();
this.plot_data = [];
this.plot_data.push({
name: '',
type: 'choropleth',
locationmode: 'world',
locations: this.unpack(mydata, 'country'),
text: this.unpack(mydata, 'txt'),
z: this.unpack(mydata, 'val'),
showlegend: false,
showscale: false,
hovertemplate: '%{text}',
zmin: this.colorscale[this.current.attr].min,
zmax: this.colorscale[this.current.attr].max,
colorscale: this.colorscale[this.current.attr].schema,
hoverlabel: {
font: {
size: 12
},
align: 'left'
}
});
},
_create_plot_layout: function() {
this.plot_layout = {
margin: { t: 0 , b: 0, l: 0, r: 0},
geo: {
scope: 'world',
resolution: 50,
showframe: false,
showlakes: false
},
width: this.get_width(),
height: this.get_height()
};
},
unpack: function(rows, key) {
return rows.map(function(row) {
return row[key];
});
},
get_width: function() {
// var w = $('#' + this.plot_id).css('width');
// w = parseFloat(w.substring(0, w.length-2));
var w = $('#' + this.plot_id).width();
// var ww = $(window).width();
// if (ww<1000) {
// // which means it is mobile
// w = ww;
// }
console.log('* ' + this.plot_id + ' width: ' + w);
if (w < 100) {
// ask help !!!
// 40 is the padding of the container
w = jarvis.guess_width(this.plot_id) - 40;
if (w == 0) {
w = this.default_width;
}
}
return w;
},
get_height: function() {
// var h = $('#' + this.plot_id).css('height');
// h = parseFloat(h.substring(0, h.length-2));
var h = $('#' + this.plot_id).height();
console.log('* ' + this.plot_id + ' height: ' + h);
if (h < 200) {
var width = this.get_width();
return width * 0.5;
} else {
return h;
}
},
};
// bind this to the global plots object
if (typeof(plots) == 'undefined') {
} else {
plots[fig_crrw_worldmap.plot_id] = fig_crrw_worldmap;
}
var figmker_crrw_trend = {
version: '1.2.0',
crp_threshold_1: 15,
crp_threshold_2: 30,
crp_threshold_3: 10,
colorscale: [
'green',
'gold',
'red'
],
make_fig: function(plot_id, data, state, fips, prependTo_id) {
if ($('#' + plot_id).length>0) {
// have already there
// $( "#" + plot_id ).effect( 'pulsate', {}, 200, null );
// move to the first
var parent_id = $( "#" + plot_id ).parent().attr('id');
$( "#" + plot_id ).prependTo('#'+parent_id);
return;
}
if (typeof(prependTo_id) == 'undefined') {
prependTo_id = '#fig_crrw_trends';
}
var fig = {
plot_id: plot_id,
color_range: figmker_crrw_trend.colorscale,
state: state,
fips: fips,
data: data,
crp_threshold_1: figmker_crrw_trend.crp_threshold_1,
crp_threshold_2: figmker_crrw_trend.crp_threshold_2,
crp_threshold_3: figmker_crrw_trend.crp_threshold_3
};
var is_cnty = false;
var datatmp = null;
if (typeof(fips)=='undefined') {
is_cnty = false;
datatmp = data.state_data[state];
} else if (fips == 'mchrr') {
is_cnty = false;
datatmp = data.mchrr_data[state];
} else if (fips == 'world') {
// the state is country code
is_cnty = false;
datatmp = data.world_data[state];
} else {
is_cnty = true;
if (data.county_data.hasOwnProperty(fips)) {
datatmp = data.county_data[fips];
}
}
if (datatmp == null) {
return null;
}
fig.is_cnty = is_cnty;
// create the DOM obj for this figure
var cal_lbl = is_cnty?
datatmp.name + ', ' + datatmp.state :
datatmp.name;
$(prependTo_id).prepend(
'<div id="'+fig.plot_id+'" class="fig-crrw-trend d-flex justify-content-start align-items-start align-items-stretch">'+
'<div class="crrw-trend-info">'+
'<div class="crrw-trend-bar"><a href="javascript:void(0);" title="Remove this chart" onclick="jarvis.remove_trend(\''+fig.plot_id+'\')"><i class="fa fa-times"></i></a></div>'+
'<div class="crrw-trend-label">'+cal_lbl+'</div>'+
'</div>'+
'<div id="'+fig.plot_id+'_chart" class="crrw-trend-chart"></div>' +
'</div>'
);
fig.cal_data = [];
var base_zero = 50;
fig.data_crps = datatmp.crps.map(function(v, i) {