-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathus.html
70 lines (55 loc) · 1.68 KB
/
us.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
<!DOCTYPE html>
<meta charset="utf-8">
<style>
.state {
fill: #ccc;
}
.state-boundary {
fill: none;
stroke: #fff;
}
.state.selected {
fill: orange;
stroke: #000;
}
</style>
<body>
<script src="//d3js.org/d3.v3.min.js"></script>
<script src="//d3js.org/topojson.v1.min.js"></script>
<script>
var width = 960,
height = 600;
var projection = d3.geo.albersUsa()
.scale(1280)
.translate([width / 2, height / 2]);
var path = d3.geo.path()
.projection(projection);
var svg = d3.select("body").append("svg")
.attr("width", width)
.attr("height", height);
var selected = d3.set([
9, 10, 12, 13, 17, 18, 19, 21, 23, 24,
25, 26, 29, 31, 33, 34, 36, 37, 39, 42,
44, 45, 47, 50, 51, 54, 55
]);
d3.json("lib/us.json", function (error, us) {
if (error) throw error;
svg.append("path")
.datum(topojson.feature(us, us.objects.states))
.attr("class", "state")
.attr("d", path);
svg.append("path")
.datum(topojson.mesh(us, us.objects.states, function (a, b) {
return a !== b;
}))
.attr("class", "state-boundary")
.attr("d", path);
svg.append("path")
.datum(topojson.merge(us, us.objects.states.geometries.filter(function (d) {
return selected.has(d.id);
})))
.attr("class", "state selected")
.attr("d", path);
});
d3.select(self.frameElement).style("height", height + "px");
</script>