Skip to content

Instantly share code, notes, and snippets.

@jjelosua
Created September 25, 2015 02:34
Show Gist options
  • Save jjelosua/f0f5e47dae2203ac9d37 to your computer and use it in GitHub Desktop.
Save jjelosua/f0f5e47dae2203ac9d37 to your computer and use it in GitHub Desktop.
D3: Callback when all elements have transitioned
var features = d3.selectAll("path")
features.transition().ease("quad-in-out").duration(1000)
.attr("d",path.pointRadius(set_circle_radius))
.style("fill", set_circle_color)
// call the helper function passing the desired callback function
.call(d3endall, enable_map_events);
//Helper counting function to wait to all elements of a transition to end
function d3endall(transition, callback) {
if (transition.size() === 0) { callback(); }
var n = 0;
transition
.each(function() { ++n; })
.each("end", function() { if (!--n) callback.apply(this, arguments); });
}
function enable_map_events () {
// Enable drag and zoom handlers.
map.dragging.enable();
map.touchZoom.enable();
map.doubleClickZoom.enable();
map.scrollWheelZoom.enable();
// Enable tap handler, if present.
if (map.tap) map.tap.enable();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment