-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
83 lines (65 loc) · 1.82 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
<!DOCTYPE html>
<meta charset="utf-8">
<style>
svg {
font: 10px sans-serif;
}
.caption {
font-weight: bold;
}
.key path {
display: none;
}
.key line {
stroke: #000;
shape-rendering: crispEdges;
}
.county-border {
fill: none;
stroke: #000;
stroke-opacity: .3;
}
</style>
<body>
<script src="http://d3js.org/d3.v3.min.js"></script>
<script src="http://d3js.org/topojson.v1.min.js"></script>
<script src="http://d3js.org/colorbrewer.v1.min.js"></script>
<script>
var width = 960,
height = 1100;
var svg = d3.select("body").append("svg")
.attr("width", width)
.attr("height", height);
var color = d3.scale.threshold()
.domain([1, 10, 50, 100, 500, 1000, 2000, 5000])
.range(colorbrewer.Blues[9]);
var path = d3.geo.path()
.projection(null);
d3.json("ca.json", function(error, ca) {
if (error) return console.error(error);
var tracts = topojson.feature(ca, ca.objects.tracts);
// Clip tracts to land.
svg.append("defs").append("clipPath")
.attr("id", "clip-land")
.append("path")
.datum(topojson.feature(ca, ca.objects.counties))
.attr("d", path);
// Group tracts by color for faster rendering.
svg.append("g")
.attr("class", "tract")
.attr("clip-path", "url(#clip-land)")
.selectAll("path")
.data(d3.nest()
.key(function(d) { return color(d.properties.population / d.properties.area * 2.58999e6); })
.entries(tracts.features.filter(function(d) { return d.properties.area; })))
.enter().append("path")
.style("fill", function(d) { return d.key; })
.attr("d", function(d) { return path({type: "FeatureCollection", features: d.values}); });
// Draw county borders.
svg.append("path")
.datum(topojson.mesh(ca, ca.objects.counties, function(a, b) { return a !== b; }))
.attr("class", "county-border")
.attr("d", path)
.interpolate("linear");
});
</script>