Skip to content

Instantly share code, notes, and snippets.

@awoodruff
Last active December 20, 2015 04:28
Show Gist options
  • Save awoodruff/6070584 to your computer and use it in GitHub Desktop.
Save awoodruff/6070584 to your computer and use it in GitHub Desktop.
Rotating globe tween from http://work.axismaps.com/amd/gc/oil/. See it in action there by mousing over the bar chart. Code more or less ripped from examples like http://bl.ocks.org/mbostock/4183330, but on IE9 and IE10, especially on slower machines, countries that are supposed to rotate to the back of the globe and disappear have a tendency to …
// map is at http://work.axismaps.com/amd/gc/oil/
function move_globe( coords, animate, end )
{
if ( insetShowing ) return;
if( animate )
{
coords[ 1 ] = coords[ 1 ] > 30 ? 30 :
coords[ 1 ] < -30 ? -30 :
coords[ 1 ];
d3.transition()
.duration( 500 )
.tween( "rotate", function()
{
var r = d3.interpolate( projection.rotate(), coords );
return function( t )
{
projection.rotate( r( t ) );
countries.selectAll( "path" ).attr( "d", path );
insets.selectAll( "path" ).attr( "d", path );
d3.select( "#insetOutlines" ).selectAll( "path" ).attr( "d", path );
};
})
.each( "end", end || function(){} ); // Function to run at the end of the animation
}
else
{
projection.rotate( coords );
countries.selectAll( "path" ).attr( "d", path );
insets.selectAll( "path" ).attr( "d", path );
d3.select( "#insetOutlines" ).selectAll( "path" ).attr( "d", path );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment