Using d3timer to Centrally Control Movement
This is a follow-on from "Using attrTween in a Transition to Move an Element Using a Function".
Both this example, and the previous example show exactly the same kind of movement (although the movement here continues unless you explicitly click the "Stop" button). The animation is exactly the same, paths followed are the same etc.
The difference here is that this does not use transitions, it uses the "d3.timer" functionality to call a function that both determines how far around an iteration each element is and to move the element using the transform attribute.
But why on earth do this if we've just done the same thing using a transition?
The issue is one of control: with this approach we can do all kinds of calculations within the "tickFn" on multiple elements. If we wanted we could implement collision detection, manipulate the elements to follow all kinds of wacky routes, and more. This is the kind of thing the "force layout" code does: uses a d3.timer and a tickFn to execute multiple operations on multiple elements before updating their positions.
You could take the previous example and also use a d3.timer function thereby combining the power of transitions and retaining some control, but it could get messy. For me at least.
Modified http://d3js.org/d3.v3.min.js to a secure url
https://d3js.org/d3.v3.min.js