Skip to content

Instantly share code, notes, and snippets.

@mbostock
Last active February 8, 2016 23:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mbostock/870118 to your computer and use it in GitHub Desktop.
Save mbostock/870118 to your computer and use it in GitHub Desktop.
Fill-Rule Evenodd
license: gpl-3.0
<!DOCTYPE html>
<meta charset="utf-8">
<style>
body {
background: steelblue;
}
.feature {
fill-opacity: .5;
fill-rule: evenodd;
}
.hover {
fill: none;
stroke: #ccc;
pointer-events: all;
}
</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 = 500;
var path = d3.geo.path()
.projection(d3.geo.albers()
.rotate([72.1, 0])
.center([0, 42.1])
.scale(5000));
var svg = d3.select("body").append("svg")
.attr("width", width)
.attr("height", height);
var feature = svg.append("g")
.attr("class", "feature")
.selectAll("path");
d3.json("/mbostock/raw/4090846/us.json", function(error, us) {
if (error) throw error;
var states = topojson.feature(us, us.objects.states);
feature = feature
.data(states.features)
.enter().append("path")
.style("display", "none")
.attr("d", function(d) { return "M0,0H" + width + "V" + height + "H0Z" + path(d); });
svg.append("g")
.attr("class", "hover")
.selectAll("path")
.data(states.features)
.enter().append("path")
.attr("d", path)
.on("mouseover", mouseovered)
.on("mouseout", mouseouted);
});
function mouseovered(d) {
feature.style("display", function(p) { return d === p ? null : "none"; });
}
function mouseouted(d) {
feature.style("display", "none");
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment