For each json a circle is created and x and y are arbitrarily set
for(var d = 0; d<json.length; d++){ circlexloc[d] = ((Math.random()*2*r)-r); circleyloc[d] = ((Math.random()*2*r)-r); };
Declaring an environment variable when setting attributes and animations
var circle = svg.selectAll("circle").data(json) circle.enter().append('circle')
Animation
circle.transition() .duration(1000) .attr("fill", "blue") .attr('opacity',0.6) .attr('r', 5) .attr("cx", function(d, i) {return circlexloc[i] }) .attr("cy", function(d, i) {return circleyloc[i] }); circle.exit().transition().duration(1000) .attr('opacity',0) .attr("r",0) .remove();
Attach technology to circles
var text = svg.selectAll('text') text.data(json) .enter().append("svg:text") .style("font-size", "10px") .text(function(d) { return d.TechName; }) .transition().duration(1000) .attr('opacity', 1) .attr("x", function (d, i) { return (circlexloc[i]+6)}) .attr("y", function (d, i) { return (circleyloc[i]+4)});
});
Currently, they tend to bend each other. How can I prevent this? Suggestions and examples will be appreciated - thanks.
source share