Skip to content

Instantly share code, notes, and snippets.

@mbostock
Forked from mbostock/.block
Last active February 27, 2019 01:41
Show Gist options
  • Select an option

  • Save mbostock/3682698 to your computer and use it in GitHub Desktop.

Select an option

Save mbostock/3682698 to your computer and use it in GitHub Desktop.
Aitoff
<!DOCTYPE html>
<meta charset="utf-8">
<style>
.ocean {
fill: #a4bac7;
}
.outline {
fill: none;
stroke: #333;
stroke-width: 1.5px;
}
.line {
fill: none;
stroke: #fff;
stroke-width: .5px;
}
.line :nth-child(2n) {
stroke-dasharray: 2,2;
}
.land {
fill: #d7c7ad;
stroke: #766951;
}
.boundary {
fill: none;
stroke: #a5967e;
}
</style>
<body>
<script src="http://d3js.org/d3.v2.min.js"></script>
<script src="https://raw.github.com/d3/d3-plugins/master/winkel3/winkel3.js"></script>
<script>
var width = 960,
height = 500;
var xStepsBig = d3.range(-180, 180 + 1, 22.5),
yStepsBig = d3.range(-90, 90 + 1, 22.5),
xStepsSmall = d3.range(-180, 180 + 1, 2),
yStepsSmall = d3.range(-90, 90 + 1, 2),
xLines = xStepsBig.map(function(x) { return yStepsSmall.map(function(y) { return [x, y]; }); }),
yLines = yStepsBig.map(function(y) { return xStepsSmall.map(function(x) { return [x, y]; }); }),
outline = yStepsSmall.map(function(y) { return [180, y]; }).concat(yStepsSmall.map(function(y) { return [-180, -y]; }));
var projection = d3.geo.aitoff()
.translate([width / 2 - .5, height / 2 - .5]);
var path = d3.geo.path()
.projection(projection);
var svg = d3.select("body").append("svg")
.attr("width", width)
.attr("height", height);
svg.append("path")
.datum(outline)
.attr("class", "ocean")
.attr("d", draw);
svg.append("g")
.attr("class", "x line")
.selectAll("path")
.data(xLines)
.enter().append("path")
.attr("d", draw);
svg.append("g")
.attr("class", "y line")
.selectAll("path")
.data(yLines)
.enter().append("path")
.attr("d", draw);
svg.append("path")
.datum(outline)
.attr("class", "outline")
.attr("d", function(d) { return draw(d) + "Z"; });
d3.json("/d/3682676/readme-boundaries.json", function(collection) {
svg.insert("g", ".line")
.attr("class", "boundary")
.selectAll("path")
.data(collection.features)
.enter().append("path")
.attr("d", path);
});
d3.json("/d/3682676/readme-land.json", function(collection) {
svg.insert("g", ".line,.boundary")
.attr("class", "land")
.selectAll("path")
.data(collection.features)
.enter().append("path")
.attr("d", path);
});
function draw(coordinates) {
return "M" + coordinates.map(projection).join("L");
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment