-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcounty.html
More file actions
58 lines (46 loc) · 1.33 KB
/
county.html
File metadata and controls
58 lines (46 loc) · 1.33 KB
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
<!DOCTYPE html>
<meta charset="utf-8">
<style>
.counties {
fill: none;
}
.states {
fill: none;
stroke: #fff;
stroke-linejoin: round;
}
</style>
<svg width="960" height="600"></svg>
<script src="https://d3js.org/d3.v5.min.js"></script>
<script src="https://d3js.org/d3-scale-chromatic.v1.min.js"></script>
<script src="https://d3js.org/topojson.v2.min.js"></script>
<script>
var svg = d3.select("svg"),
width = +svg.attr("width"),
height = +svg.attr("height");
var county_cases = d3.map();
var path = d3.geoPath();
var color = d3.scaleThreshold()
.domain([0, 1,5, 10, 20, 50, 100, 150])
.range(d3.schemeOranges[9]);
var promises = [
d3.json("https://d3js.org/us-10m.v2.json"),
d3.csv("county_cases.csv", function(d) { county_cases.set(d.id, +d.rate); })
]
Promise.all(promises).then(ready)
function ready([us]) {
svg.append("g")
.attr("class", "counties")
.selectAll("path")
.data(topojson.feature(us, us.objects.counties).features)
.enter().append("path")
.attr("fill", function(d) { return color(d.rate = county_cases.get(d.id)); })
.attr("d", path)
.append("title")
.text(function(d) { return d.rate; });
svg.append("path")
.datum(topojson.mesh(us, us.objects.states, function(a, b) { return a !== b; }))
.attr("class", "states")
.attr("d", path);
}
</script>