-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
81 lines (59 loc) · 1.85 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
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
</head>
<body>
<script>
function parseCSV(csv){
lines = csv.split("\n")
header = lines[0]
hdr = header.split(",")
n = lines.map(function(d) {
result = {}
d.split(",").forEach( (val,i) => result[hdr[i]] = val)
return result
})
return n
}
start = new Date().getTime()
$.ajax({ url: 'https://raw.githubusercontent.com/nytimes/covid-19-data/master/us-counties.csv', success: function(data) {
// Parse CSV
data = parseCSV(data)
// Fetch for the state of california
res = data.filter(function(d){
return (d["state"].localeCompare("California") == 0)
})
// Which counties are we interested in for now:
topical = ["San Mateo", "San Francisco", "Santa Clara"]
points = {}
res.forEach( d => {
county = d["county"]
if ( topical.includes(county)) {
if ( !(county in points)){
points[county] = {}
points[county]["x"] = []
points[county]["y"] = []
points[county]["name"] = county
points[county]["type"] = "scatter"
}
entry = points[county]
entry["x"].push(d["date"])
entry["y"].push(d["cases"])
}
}
)
series = Object.keys(points).map( function(d) {
return points[d]}
)
Plotly.newPlot("graph", series)
time = new Date().getTime() - start
outp= document.getElementById("time")
outp.innerHTML = "Page took " + time + "ms to render"
} });
</script>
<div id="graph" style="width:800px;height:500px;"></div>
<div id="time"></div>
<div id="">Find source code here: <a href="https://github.com/langly/corona">here</a></div>
</body>
</html>