How do I add a transition delay between multiple i

2020-03-26 02:37发布

问题:

The original Code can be found at: http://bl.ocks.org/Guerino1/3a51eeb95d3a8345bc27370e8c9d5b77

I have numerous polygons that are transitioning onto an svg canvas (from left to right, at the bottom of the HTML page).

The code I use to create an transition the chevrons leverages D3 Polygon:

    // Create Polygons for SDLC
    svgCanvas.selectAll("a")
        .data(dataSet)
      .enter().append("a")
        .attr("xlink:href", function(d) { return d.link; })
      .append("svg:polygon")
    //svgCanvas.selectAll("polygon")
        //.data(dataSet)
      //.enter().append("polygon")
        .attr("id", function(d,i){ return (selectString.replace(/ /g,'_').replace(/#/g,'') + "_index_" + i); })
        .attr("originalcolor","violet")
        .style("stroke","blue")
        .style("fill","violet")
        .style("stroke-width",2)
        .attr("points", origin)
        .on('mouseover', chevronMouseOver)
        .on("mouseout", chevronMouseOut)
        .on("click", chevronMouseOut)
        .transition() // <------- TRANSITION STARTS HERE --------
        .duration(3000)
        .attr("points", calculateChevron);

Currently, all polygons transition into the svg canvas, together. I'd like to put a delay between each of them, so that it looks more like dealing from a deck of cards, one at a time.

How would I properly add a D3 delay to make this happen?

Thanks for any help you can offer.

回答1:

try this..

 .transition() // <------- TRANSITION STARTS HERE --------
 .delay(function(d,i){ return 100*i; }) 
 .duration(3000)
 .attr("points", calculateChevron);