I generated a geometric SVG pattern with D3 and I wanted to animate it. I wanted to have the circles and square spinning around their centre. However when they rotate the ce
For D3 to rotate around a given center, you need to provide a custom tween function which can make use of a string interpolator:
function spinCircles() {
d3
.selectAll("#fixedGroup")
.transition()
.duration(4000)
.attrTween("transform", function() {
var center = "" + m/2 + "," + m/2;
return d3.interpolateString("rotate(0," + center + ")", "rotate(90," + center + ")");
});
}
Have a look at the updated codepen for a working example.