0

I am trying to listen end of the transition event on each of my circles:

            var n=0;
            //drawing the plot
            var circles = svg.selectAll("circle")
            .data(dataset)
            .enter()                
            .append("circle")                               
            .attr("cx", function(d, i){return xScale(max-createDate(dataset[dataset.length-1-i]["Time"]));})
            .attr("cy", -100)
            .attr("r", 5)                
            .attr("fill", function(d){return d["Doping"]?"#ff1d25":"#009267";})
            .each(function() { n++; console.log(n)})
            .transition()                                
            .delay(function(d,i){return i*50})                
            .duration(1500)
            .attr("cy", function(d){return yScale(d["Place"]);})
            .each('end', function() {                   
                   n--;
                   if (!n) {
                       console.log("end")
                   }
               })

But "end" is never printed! What am I doing wrong? The full code is here

kurumkan
  • 2,635
  • 3
  • 31
  • 55
  • did you see the error in your browsers developer tools console? – Jaromanda X Oct 10 '16 at 09:37
  • @JaromandaX no error messages =/ – kurumkan Oct 10 '16 at 09:39
  • 1
    then you are not using your browsers developer tools console ... firefox says `TypeError: t.call is not a function` - the problem is, that your last .each is invalid – Jaromanda X Oct 10 '16 at 09:40
  • thank you... I can't figure out what s wrong - all the data entries are in the same format ... https://raw.githubusercontent.com/FreeCodeCamp/ProjectReferenceData/master/cyclist-data.json – kurumkan Oct 10 '16 at 09:44
  • 1
    it should be `.on('end', ...` instead of `.each('end', ...` – Jaromanda X Oct 10 '16 at 09:45
  • the code is from here (payne8) http://stackoverflow.com/questions/14024447/d3-js-transition-end-event Are you familiar with d3? Why this code doesn't work for me and works for them?( – kurumkan Oct 10 '16 at 09:48
  • @JaromandaX - your comment is a valid solution! Thank you – kurumkan Oct 10 '16 at 09:52
  • 1
    I'm amazed at that other question - perhaps `.each` worked differently 4 years ago! just checked and there was some change - https://github.com/d3/d3/blob/master/CHANGES.md#transitions-d3-transition – Jaromanda X Oct 10 '16 at 09:55

0 Answers0