Skip to content

Instantly share code, notes, and snippets.

@stephanebachelier
Last active August 29, 2015 14:03
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 stephanebachelier/49771f8d01167e5bd945 to your computer and use it in GitHub Desktop.
Save stephanebachelier/49771f8d01167e5bd945 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>
.state {
fill: #ccc;
}
.state-boundary {
fill: none;
stroke: #fff;
}
.state.selected {
fill: orange;
stroke: #000;
}
</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 = 600;
var projection = d3.geo.mercator()
.scale(800)
.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);
d3.json("./data.json", function(error, countries) {
svg.append("path")
.datum(topojson.feature(countries, countries.objects.ne_10m_admin_0_countries))
.attr("class", "state")
.attr("d", path);
svg.append("path")
.datum(topojson.mesh(countries, countries.objects.ne_10m_admin_0_countries, function(a, b) { return a !== b; }))
.attr("class", "state-boundary")
.attr("d", path);
svg.append("path")
.datum(topojson.merge(countries, countries.objects.ne_10m_admin_0_countries.geometries.filter(function(g) {
return g.properties.ISO_A3 in ['SSD', 'SDN'];
})))
.attr("class", "state selected")
.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