I'm trying to apply this suggestion to catch the end of several transitions.
But in my local file I get a Uncaught TypeError: t.call is not a function
error. The code is as follows:
var svg = d3.select('svg');
function endall(transition, callback) {
if (typeof callback !== "function") throw new Error("Wrong callback in endall");
if (transition.size() === 0) { callback() }
var n = 0;
transition
.each(function() { ++n; })
.each("end", function() { if (!--n) callback.apply(this, arguments); });
}
for (var i=0;i<5;i++) {
svg.append('rect')
.attr("x",i*60)
.attr("y",50)
.attr("height",50)
.attr("width",50)
.style("fill","#ff0000");
}
svg.selectAll("rect:not(.active)")
.transition()
.duration(1000)
.style("fill","#00ff00")
.call(endall, function() { alert("all done") });
When I port it on jsfiddle using a D3 template, it works well. On the other hand, when I port it on jsfiddle without a D3 template, I get the same error.
Evidently I'm missing something, but I'm not able to understand what.