-
Notifications
You must be signed in to change notification settings - Fork 1
/
script.js
154 lines (133 loc) · 4.28 KB
/
script.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
/* If you're feeling fancy you can add interactivity
to your site with Javascript */
// prints "hi" in the browser's dev tools console
console.log("hi");
window.onscroll = function() {myFunction()};
// Get the navbar
var navbar = document.getElementById("nav_bar1");
// Get the offset position of the navbar
var sticky = navbar.offsetTop;
// Add the sticky class to the navbar when you reach its scroll position. Remove "sticky" when you leave the scroll position
function myFunction() {
if (window.pageYOffset >= sticky) {
navbar.classList.add("sticky")
} else {
navbar.classList.remove("sticky");
}
}
Highcharts.getJSON(
"https://raw.githubusercontent.com/NectDz/coronacation/master/UScounty.json",
function(data) {
/**
* Data parsed from http://www.bls.gov/lau/#tables
*
* 1. Go to http://www.bls.gov/lau/laucntycur14.txt (or similar, updated
* datasets)
* 2. In the Chrome Developer tools console, run this code:
* copy(JSON.stringify(document.body.innerHTML.split('\n').filter(function (s) { return s.indexOf('<PUT DATE HERE IN FORMAT e.g. Feb-14>') !== -1; }).map(function (row) { row = row.split('|'); return { code: 'us-' + row[3].trim().slice(-2).toLowerCase() + '-' + row[2].trim(), name: row[3].trim(), value: parseFloat(row[8]) }; })))
* 3. The data is now on your clipboard, paste it below
* 4. Verify that the length of the data is reasonable, about 3300
* counties.
*/
var countiesMap = Highcharts.geojson(
Highcharts.maps["countries/us/us-all-all"]
),
// Extract the line paths from the GeoJSON
lines = Highcharts.geojson(
Highcharts.maps["countries/us/us-all-all"],
"mapline"
),
// Filter out the state borders and separator lines, we want these
// in separate series
borderLines = Highcharts.grep(lines, function(l) {
return l.properties["hc-group"] === "__border_lines__";
}),
separatorLines = Highcharts.grep(lines, function(l) {
return l.properties["hc-group"] === "__separator_lines__";
});
// Add state acronym for tooltip
Highcharts.each(countiesMap, function(mapPoint) {
mapPoint.name =
mapPoint.name + ", " + mapPoint.properties["hc-key"].substr(3, 2);
});
document.getElementById("container").innerHTML = "Rendering map...";
// Create the map
setTimeout(function() {
// Otherwise innerHTML doesn't update
Highcharts.mapChart("container", {
chart: {
borderWidth: 0,
marginRight: 20 // for the legend
// width:100%;
},
title: {
text: "Safest Travel Sites in the USA 2020"
},
legend: {
layout: "vertical",
align: "right",
floating: true,
backgroundColor:
// theme
(Highcharts.defaultOptions &&
Highcharts.defaultOptions.legend &&
Highcharts.defaultOptions.legend.backgroundColor) ||
"rgba(255, 255, 255, 0.85)"
},
mapNavigation: {
enabled: true
},
colorAxis: {
min: 0,
max: 0.3,
tickInterval: 0.1,
stops: [[0, "#228B22"], [0.65, "#FFFF00"], [1, "#8B0000"]],
labels: {
format: "{value} risk"
}
},
plotOptions: {
mapline: {
showInLegend: false,
enableMouseTracking: false
}
},
series: [
{
mapData: countiesMap,
data: data,
joinBy: ["hc-key", "code"],
name: "Risk Level",
tooltip: {
valueSuffix: "%"
},
borderWidth: 0,
states: {
hover: {
color: "#a4edba"
}
},
shadow: false
},
{
type: "mapline",
name: "State borders",
data: borderLines,
color: "white",
shadow: false
},
{
type: "mapline",
name: "Separator",
data: separatorLines,
color: "gray",
shadow: false
}
]
});
}, 0);
// function mousePressed() {
// return false;
// }
}
);