var dataset = [ 5, 10, 15, 20, 25]; //Width and height var w = 800; var h = 200; //Create SVG Element var svg = d3.select("body") .append("svg") .attr("width", w) .attr("height", h); //Import the plane d3.xml("diwali_lamp.svg", "image/svg+xml", function(xml) { var importedNode = document.importNode(xml.documentElement, true); svg.selectAll("g") .data(dataset) .enter() .append("g") .attr("transform", function(d, i){ return "translate(" + (i * (w / dataset.length)) + "," + (h - 200) + ")" +"scale("+ 0.2 +")"; }) .each(function(d, i){ var plane = this.appendChild(importedNode.cloneNode(true)); d3.select(plane).select("g") .transition() .duration(1000) .each(slide); }); function slide() { var flame = d3.select(this); var x = Math.random() * (0.40 - 0.38) + 0.38; var y = Math.random() * (0.49 - 0.48) + 0.48; (function repeat() { //Original matrix - 0.49034383,0,0,0.38263293,-259.96,-418.88496 /* flame = flame.transition() .attr("transform", "matrix(0.50,0.01,0,0.38,-265,-418)") .transition() .attr("transform", "matrix(0.47,0,0.01,0.39,-259.96,-420)") .each("end", repeat); })();*/ flame = flame.transition() .attr("transform", "matrix(" + y + ",0.01,0," + x + ",-265,-418)") .transition() .attr("transform", "matrix(" + y + ",0,0.01,0.39,-259.96,-420)") .each("end", repeat); })(); } });