This repository has been archived by the owner on Jul 9, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
164 lines (152 loc) · 5.69 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
<!DOCTYPE html>
<html>
<head>
<title>ARCHIVED: covid19js</title>
<meta charset="UTF-8">
<meta name="author" content="Robert Fuller">
<meta name="keywords" content="Coronavirus, COVID-19, Javascript">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet"
href="//cdn.jsdelivr.net/gh/highlightjs/[email protected]/build/styles/default.min.css">
<script src="dist/covid19.js"></script>
<script>
var append = function(elid,text){
var el = document.getElementById(elid);
var innerText = el.innerText;
el.innerText = innerText + "\n" + text;
}
var appendSome = function(elid,data,n=3){
var result = data.slice(0,n).map(s=>" "+JSON.stringify(s)).join(",\n");
append(elid,"[\n"+result+",\n ...\n]");
}
var appendJSON = function(el,o){
append(el,JSON.stringify(o,null,2));
}
</script>
</head>
<body>
<h1>UPDATES TO THIS PROJECT ENDED 2020-07-08</h1>
<h1>covid19js</h1>
<p>Latest data <span id="updated"></span></p>
<p>Coronavirus COVID-19 outbreak data with zero dependencies, for web developers.</p>
<p>Data is generated from <a href="https://github.com/CSSEGISandData/COVID-19">2019 Novel Coronavirus COVID-19 (2019-nCoV) Data Repository by Johns Hopkins CSSE</a></p>
<p>Updated often and easy to use.</p>
<a href="https://github.com/fullergalway/covid19js/">View on Github</a>
<h2>Getting Started</h2>
<p>Include this line in the head of your html page:</p>
<pre><code class="html"><script src="https://covid19js.com/dist/covid19.js"></script></code></pre>
<p>Afterwards you can use the covid19 data in your javascript</p>
<pre><code id="ex03" class="javascript">var data = covid19.data();
data.latest().totals();
</code></pre>
<script>
var data = covid19.data();
var result = data.latest().totals();
appendJSON("ex03",result);
</script>
<p>Use covid19.data() to create a new clean copy of the data</p>
<pre><code id="ex01" class="javascript">var data = covid19.data();
</code></pre>
<script>
var data = covid19.data();
appendSome("ex01",data);
</script>
<p>Use latest() to get data for the most recent date</p>
<pre><code id="ex02" class="javascript">data.latest();
</code></pre>
<script>
var data = covid19.data();
var result = data.latest();
appendSome("ex02",result);
</script>
<p>List of dates, continents, countryRegions, locations</p>
<pre><code id="ex10" class="javascript">var data = covid19.data();
</code></pre>
<script>
var data = covid19.data();
append("ex10","data.dates().reverse();")
appendSome("ex10",data.dates().reverse());
append("ex10","data.continents();")
appendSome("ex10",data.continents());
append("ex10","data.countryRegions();")
appendSome("ex10",data.countryRegions());
append("ex10","data.locations();")
appendSome("ex10",data.locations());
</script>
<p>Filter as you would with any javascript array</p>
<pre><code id="ex04" class="javascript">data.latest().filter(x=>x.country_region==="US");
</code></pre>
<script>
var data = covid19.data();
var result = data.latest().filter(x=>x.country_region==="US");
appendSome("ex04",result);
</script>
<pre><code id="ex04a" class="javascript">data.latest().filter(x=>x.country_region==="US").totals();
</code></pre>
<script>
var data = covid19.data();
var result = data.latest().filter(x=>x.country_region==="US").totals();
appendJSON("ex04a",result);
</script>
<p>Filter for leaflet map bounds</p>
<pre><code id="ex04b" class="javascript">var bounds = L.latLngBounds(
L.latLng(6.7499552751, 36.619987291),
L.latLng(18.4802470232, 47.1153931748));
data.filter(x=>bounds.contains(L.latLng(x.lat,x.lng)));
</code></pre>
<script>
var data = covid19.data();
var result = data.filter(x=>x.country_region==="Italy");
appendSome("ex04b",result);
</script>
<p>Group by continent (must filter to a single date first)</p>
<pre><code id="ex09" class="javascript">data.latest().groupByContinent();
</code></pre>
<script>
var data = covid19.data();
var result = data.latest().groupByContinent();
appendSome("ex09",result);
</script>
<p>Group by country (must filter to a single date first)</p>
<pre><code id="ex05" class="javascript">data.latest().groupByCountryRegion();
</code></pre>
<script>
var data = covid19.data();
var result = data.latest().groupByCountryRegion();
appendSome("ex05",result);
</script>
<p>Group by date with or without filtering first</p>
<pre><code id="ex06" class="javascript">data.filter(x=>x.country_region==="US").groupByDate();
</code></pre>
<script>
var data = covid19.data();
var result = data.filter(x=>x.country_region==="US").groupByDate();
appendSome("ex06",result);
</script>
<pre><code id="ex07" class="javascript">data.groupByDate();
</code></pre>
<script>
var data = covid19.data();
var result = data.groupByDate();
appendSome("ex07",result);
</script>
<h2>Promise based refresh to get updated data from server</h2>
<p>Max once per minute, reasonably efficient by fetching change timestamp first.</p>
<pre><code id="ex08" class="javascript">covid19.refresh().then(data=>{
console.log(covid19.last_updated);
console.log(data.latest().groupByLocation())
});
</code></pre>
<script>
covid19.refresh().then((data)=>{
appendJSON("ex08",covid19.last_updated);
appendSome("ex08", data.latest().groupByLocation())
})
</script>
<script>
covid19.refresh().then(()=>document.getElementById("updated").innerText = covid19.last_updated);
</script>
<script src="//cdn.jsdelivr.net/gh/highlightjs/[email protected]/build/highlight.min.js"></script>
<script>hljs.initHighlightingOnLoad();</script>
</body>
</html>