Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change object attribute following transition D3

I want to give an object an attribute once a transition is finished. I'm simply updating an images position as follows:

tmp.transition().duration(1000)
                    .attr("transform", function(d) {return 'translate(' + 
                    coordinates[d].x +',' + 
                    coordinates[d].y + ')'})

Once it finishes, I want to give the object tmp an attribute "moved" with the value "no". I tried:

tmp.transition().duration(1000)
     .attr("transform", function(d) {return 'translate(' + 
            coordinates[d].x +',' + 
            coordinates[d].y + ')'}).end('moved', 'no')

But without success. Any tips? Thanks,

like image 783
mike Avatar asked Nov 05 '25 12:11

mike


1 Answers

According to the documentation, you can use .each:

tmp.transition().duration(1000)
 .attr("transform", function(d) {return 'translate(' + 
        coordinates[d].x +',' + 
        coordinates[d].y + ')'}
 ).each('end', function() {
     d3.select(this).attr('moved', 'no');
     // or maybe also this.setAttribute('moved', 'no');
 });
like image 127
Felix Kling Avatar answered Nov 07 '25 01:11

Felix Kling



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!