Skip to content

Instantly share code, notes, and snippets.

@mpmckenna8
Last active August 29, 2015 14:02
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 mpmckenna8/434839f120c552ad0048 to your computer and use it in GitHub Desktop.
Save mpmckenna8/434839f120c552ad0048 to your computer and use it in GitHub Desktop.
Basic d3 Animations gnomic south pole

Experimenting with transformations and d3 geo stuff in general. I like the way the north pole

<!DOCTYPE html>
<meta charset="utf-8">
<style>
.graticule {
fill: none;
stroke: #777;
stroke-width: .5px;
stroke-opacity: .5;
}
.land {
fill: #222;
}
.boundary {
fill: none;
stroke: #fff;
stroke-width: .5px;
}
</style>
<body>
<script src="http://d3js.org/d3.v3.js"></script>
<script src="http://d3js.org/topojson.v1.min.js"></script>
<script>
var width = 960,
height = 960;
var projection = d3.geo.gnomonic()
.clipAngle(90 - 1e-3)
.scale(150)
.translate([width/2, height / 2])
.precision(.1)
// rotate([yaw, pitch, roll]) or long lat and roll
.rotate([100,90,-190])
// .center([-240,20])
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);
svg.append("path")
.datum(graticule)
.attr("class", "graticule")
.attr("d", path);
d3.json("/mpmckenna8/raw/9965876/world-50m.json", function(error, world) {
svg.insert("path", ".graticule")
.datum(topojson.feature(world, world.objects.land))
.attr("class", "land")
.attr("d", path);
svg.insert("path", ".graticule")
.datum(topojson.mesh(world, world.objects.countries, function(a, b) { return a !== b; }))
.attr("class", "boundary")
.attr("d", path);
d3.selectAll('path')
.transition()
.duration(5000)
.attr("transform", "translate(" + width / 2 + "," + height / 2 + ")scale("+.3 + ")translate(" + -600 + "," + -500 + ")")
.style("stroke-width", 4 + "px")
.style("stroke", "pink");
d3.selectAll('.land')
.transition()
.delay(6999)
.duration(6999)
.style("fill","lawngreen");
d3.selectAll('svg')
.on('click', function(){
console.log('flip should have changed');
flip = 1
d3.selectAll('path')
.transition()
.duration(1000)
//couldn't get this part to do anything fun like change the zoom to anythin back to 1, click to see
.attr("transform", "translate(" - width / 2 + "," -height / 2 + ")scale("+4 +")")
.style("stroke-width", 4 + "px")
.style("stroke", "orange");
})
});
d3.select(self.frameElement).style("height", height + "px");
d3.select('svg')
.style('background', 'green')
.transition()
.delay(4000)
.duration(3000)
.style('background', 'blue')
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment