This is a gist in progress, forking from http://bl.ocks.org/mbostock/4657115
-
-
Save okdistribute/9675588 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<head> | |
<meta charset="utf-8"> | |
<link type="text/css" rel="stylesheet" href="style.css"/> | |
</head> | |
<body> | |
<script src="http://d3js.org/d3.v3.min.js"></script> | |
<script src="http://d3js.org/queue.v1.min.js"></script> | |
<script src="http://d3js.org/topojson.v1.min.js"></script> | |
<script src="src.js"></script> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var width = 960, | |
height = 500; | |
var path = d3.geo.path(); | |
var svg = d3.select("body").append("svg") | |
.attr("width", width) | |
.attr("height", height); | |
queue() | |
.defer(d3.json, "/d/4090846/us.json") | |
.defer(d3.json, "/d/4090846/us-congress-113.json") | |
.await(ready); | |
function ready(error, us, congress) { | |
svg.append("defs").append("path") | |
.attr("id", "land") | |
.datum(topojson.feature(us, us.objects.land)) | |
.attr("d", path); | |
svg.append("clipPath") | |
.attr("id", "clip-land") | |
.append("use") | |
.attr("xlink:href", "#land"); | |
svg.append("g") | |
.attr("class", "districts") | |
.attr("clip-path", "url(#clip-land)") | |
.selectAll("path") | |
.data(topojson.feature(congress, congress.objects.districts).features) | |
.enter().append("path") | |
.attr("d", path) | |
.append("title") | |
.text(function(d) { return d.id; }); | |
svg.append("path") | |
.attr("class", "district-boundaries") | |
.attr("clip-path", "url(#clip-land)") | |
.datum(topojson.mesh(congress, congress.objects.districts, function(a, b) { return (a.id / 1000 | 0) === (b.id / 1000 | 0); })) | |
.attr("d", path); | |
svg.append("path") | |
.attr("class", "state-boundaries") | |
.datum(topojson.mesh(us, us.objects.states, function(a, b) { return a !== b; })) | |
.attr("d", path); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
path { | |
stroke-linejoin: round; | |
} | |
.districts { | |
fill: #bbb; | |
} | |
.districts :hover { | |
fill: orange; | |
} | |
.district-boundaries { | |
pointer-events: none; | |
fill: none; | |
stroke: #ddd; | |
} | |
.state-boundaries { | |
pointer-events: none; | |
fill: none; | |
stroke: #fff; | |
stroke-width: 1.5px; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment