Skip to content

Instantly share code, notes, and snippets.

@jasondavies
Forked from jasondavies/README.md
Created September 28, 2012 12:09
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 jasondavies/3799442 to your computer and use it in GitHub Desktop.
Save jasondavies/3799442 to your computer and use it in GitHub Desktop.
Spiral Stress Test

Stress test for antemeridian cutting!

<!DOCTYPE html>
<meta charset="utf-8">
<style>
.foreground {
fill: none;
stroke: #333;
stroke-width: 1.5px;
}
.graticule {
fill: none;
stroke: #000;
stroke-width: .5px;
}
.graticule:nth-child(2n) {
stroke-dasharray: 2,2;
}
.land {
fill: #eee;
stroke: #000;
stroke-width: .5px;
}
.spiral {
fill: red;
fill-opacity: .5;
stroke: #000;
stroke-width: .5px;
}
.boundary {
fill: none;
stroke: #ccc;
}
</style>
<body>
<script src="http://d3js.org/d3.v3.min.js"></script>
<script>
var width = 960,
height = 500;
var projection = d3.geo.equirectangular().translate([width / 2 - .5, height / 2 - .5]).scale(150),
path = d3.geo.path().projection(projection);
var graticule = d3.geo.graticule();
var svg = d3.select("body").append("svg")
.datum({x: 0, y: 0})
.attr("width", width)
.attr("height", height)
.call(d3.behavior.drag()
.origin(Object)
.on("drag", function(d) {
d.x = d3.event.x;
d.y = d3.event.y;
projection.rotate([d.x, -d.y]);
svg.selectAll("path").attr("d", path);
}));
svg.selectAll(".graticule")
.data(graticule.lines)
.enter().append("path")
.attr("class", "graticule")
.attr("d", path);
var n = 1e3, dy = 5;
var spiral = d3.range(0, 1 + 1 / n, 1 / n).map(function(t) {
return [(360 * 10 * t) % 360 - 180, -90 + dy + (90 - dy) * 2 * t];
}).concat(d3.range(1, 0, -1 / n).map(function(t) {
return [(360 * 10 * t) % 360 - 180, -90 + (90 - dy) * 2 * t];
}));
spiral.push(spiral[0]);
svg.append("path")
.datum({type: "Polygon", coordinates: [spiral]})
.attr("class", "spiral")
.attr("d", path);
d3.json("/d/3682676/readme-boundaries.json", function(err, collection) {
svg.insert("g", ".graticule")
.attr("class", "boundary")
.selectAll("path")
.data(collection.geometries)
.enter().append("path")
.attr("d", path);
});
d3.json("/d/3682676/readme-land.json", function(err, collection) {
svg.insert("g", ".graticule,.boundary")
.attr("class", "land")
.selectAll("path")
.data(collection.geometries)
.enter().append("path")
.attr("d", path);
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment