Skip to content

Instantly share code, notes, and snippets.

@almccon
Forked from mbostock/.block
Last active June 15, 2016 18:29
Show Gist options
  • Save almccon/5717687 to your computer and use it in GitHub Desktop.
Save almccon/5717687 to your computer and use it in GitHub Desktop.
Waterman outlines
Display the source blob
Display the rendered blob
Raw
Loading
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>
body {
background: #fcfcfa;
}
.stroke {
fill: none;
stroke: none;
}
.fill {
fill: none;
}
.graticule {
fill: none;
stroke: none;
}
.land {
fill: none;
stroke: #000;
stroke-width: .5px;
}
.boundary {
fill: none;
stroke: #000;
stroke-width: .5px;
}
</style>
<body>
<script src="http://d3js.org/d3.v3.min.js"></script>
<script src="http://d3js.org/d3.geo.polyhedron.v0.min.js"></script>
<script src="http://d3js.org/topojson.v1.min.js"></script>
<script>
var width = 960,
height = 550;
var projection = d3.geo.polyhedron.waterman()
.rotate([30, -20])
.scale(150)
.translate([width / 2, height / 2])
.precision(.1);
var path = d3.geo.path()
.projection(projection);
var graticule = d3.geo.graticule();
var svg = d3.select("body").append("svg")
.attr("width", width)
.attr("height", height);
var defs = svg.append("defs");
defs.append("path")
.datum({type: "Sphere"})
.attr("id", "sphere")
.attr("d", path);
defs.append("clipPath")
.attr("id", "clip")
.append("use")
.attr("xlink:href", "#sphere");
svg.append("use")
.attr("class", "stroke")
.attr("xlink:href", "#sphere");
svg.append("use")
.attr("class", "fill")
.attr("xlink:href", "#sphere");
svg.append("path")
.datum(graticule)
.attr("class", "graticule")
.attr("clip-path", "url(#clip)")
.attr("d", path);
d3.json("countries_lakes_50m.json", function(error, world) {
console.log(world);
svg.insert("path", ".graticule")
.datum(topojson.mesh(world, world.objects.ne_50m_admin_0_countries_lakes, function(a, b) { return a == b; }))
.attr("class", "land")
.attr("clip-path", "url(#clip)")
.attr("d", path);
svg.insert("path", ".graticule")
.datum(topojson.mesh(world, world.objects.ne_50m_admin_0_countries_lakes, function(a, b) { return a !== b; }))
.attr("class", "boundary")
.attr("clip-path", "url(#clip)")
.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