I’m working with go.Animation to animate strokeDashOffset on a Shape representing flow in a pipe. I want to dynamically adjust the animation speed when the value changes, and I’m trying to do this by updating the .duration property on the existing go.Animation instance.
My current setup looks like this:
const animation = new go.Animation();
animation.duration = initialSpeed;
animation.runCount = Infinity;
animation.add(strokeShape, "strokeDashOffset", 0, 20);
animation.start();
// Later, when the speed needs to change:
animation.duration = newSpeed;
However, updating animation.duration like this does not appear to affect the running animation. It continues at the original speed.
❓ My questions:
Is it possible to update .duration on a running go.Animation instance?
If not, is the correct pattern to stop and recreate the animation with the new duration?
Is there a better way to create a smooth transition between speeds without restarting the animation and causing a visible jump?
Animate strokeDashOffset to simulate flow in a pipe, with the ability to dynamically update the speed (animation duration) at any time, based on live values.
🧪 What we’ve tried:
Stopping the current animation and starting a new one with the updated duration (which works).
Randomizing speed and the time of the update, to simulate a realistic stream of incoming updates.
Preserving the current strokeDashOffset before restarting to avoid full reset.
🧩 Remaining challenge:
Even when trying to capture the current strokeDashOffset and continuing from that value, a visible “jump” or reset often occurs, especially if the new animation doesn’t align smoothly with the previous offset.
We understand GoJS animations don’t offer hooks tied to cycle completion. But we’re wondering:
❓ Questions:
Is there a better way to pause and resume strokeDashOffset animations without a visible jump?
Is there a way to read or sync with the internal progress/cycle of an infinite go.Animation?
We’ve tried approximating smooth transitions by watching strokeDashOffset manually and only restarting when near 0, but it adds a lot of complexity.
Any suggestions to make this smoother would be greatly appreciated!
You’ve got 99% of it, all you really need to do is make sure that the new animation starts exactly where the old one leaves off. So instead of animating from 0 to some stroke dash value, you always want to animate to the current value, plus a consistent offset. So not this:
I replaced the randomization with 4 buttons, just for testing. You can see that repeatedly clicking any of the buttons (like 2000) won’t jitter any more.