consolidate successive translations in D3
问题 The following toy code (jsfiddle here) write to the console log translate(20,0) translate(20,0) translate(20,0) translate(20,0) translate(20,0) . Is it possible to get translate(100,0) as a "consolidated" translation? var svg = d3.select('svg'); var rec=svg.append("rect") .attr("width",20) .attr("height", 20) .attr("x", 0) .attr("y", 20) .attr("fill","#00ffff") .attr("transform","") ; for (var i=0;i<10;i++) { rec .attr("transform",rec.attr("transform")+" translate(20,0)") ; } console.log(rec