Skip to content

Instantly share code, notes, and snippets.

@larskotthoff
Forked from mbostock/.block
Last active August 29, 2015 13:59
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save larskotthoff/10587926 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
<!DOCTYPE html>
<meta charset="utf-8">
<style>
.land {
fill: #ddd;
}
.boundary {
fill: none;
stroke: #999;
}
</style>
<body>
<script src="http://d3js.org/d3.v3.min.js"></script>
<script src="http://d3js.org/topojson.v1.min.js"></script>
<script>
var width = 960,
height = 800;
var path = d3.geo.path()
.projection(null);
var svg = d3.select("body").append("svg")
.attr("width", width)
.attr("height", height);
var svg2 = d3.select("body").append("svg")
.attr("width", width)
.attr("height", height);
d3.json("ca.json", function(error, ca) {
svg.append("path")
.datum(topojson.feature(ca, ca.objects.counties))
.attr("class", "land")
.attr("d", path)
.on("click", function(d) { svg2.selectAll(".foo").data([d]).enter().append("path").attr("d", path); });
svg.append("path")
.datum(topojson.mesh(ca, ca.objects.counties, function(a, b) { return a !== b; }))
.attr("class", "boundary")
.attr("d", path);
});
d3.select(self.frameElement).style("height", height + "px");
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment