I have two g elements, each of which contains circles. Circles are organized using force.layout . Elements of g go over.
You can look here: demo . Short code:
var dots = svg.selectAll(".dots") .data(data_groups) .enter().append("g") .attr("class", "dots") .attr("id", function (d) { return d.name; }) ... .each(addCircles); dots.transition() .duration(30000) .ease("linear") .attr("transform", function (d, i) { return "translate(" + (150 + i * 100) + ", " + 450 + ")"; }); function addCircles(d) { d3.select(this).selectAll('circle') .data(data_circles.filter(function (D) { return D.name == d.name })) .enter() .append('circle') .attr("class", "dot") .attr("id", function (d) { return d.id; }) ... .call(forcing); } function forcing(E) { function move_towards(alpha) { ... } var force = d3.layout.force() .nodes(E.data()) .gravity(-0.01) .charge(-1.9) .friction(0.9) .on("tick", function (e) { ... }); force.start(); }
I need to move a circle (e.g. id = 1) from the first element g to the second using a transition.
Any suggestions are welcome.
source share