diff --git a/lib/animation/Animation.js b/lib/animation/Animation.js index dc57b40..cf7d2db 100644 --- a/lib/animation/Animation.js +++ b/lib/animation/Animation.js @@ -62,11 +62,13 @@ const EASE_IN_OUT = function(pos) { const TOKEN_SIZE = 20; -export default function Animation(canvas, eventBus, scopeFilter) { +export default function Animation(config, canvas, eventBus, scopeFilter) { this._eventBus = eventBus; this._scopeFilter = scopeFilter; this._canvas = canvas; + this._randomize = config && config.randomize !== false; + this._animations = new Set(); this._speed = 1; @@ -127,7 +129,7 @@ Animation.prototype.createAnimation = function(connection, scope, done = noop) { const tokenGfx = this._createTokenGfx(group, scope); - const animation = new TokenAnimation(tokenGfx, connection.waypoints, () => { + const animation = new TokenAnimation(tokenGfx, connection.waypoints, this._randomize, () => { this._animations.delete(animation); done(); @@ -237,16 +239,18 @@ Animation.prototype._getGroup = function(scope) { }; Animation.$inject = [ + 'config.animation', 'canvas', 'eventBus', 'scopeFilter' ]; -function TokenAnimation(gfx, waypoints, done) { +function TokenAnimation(gfx, waypoints, randomize, done) { this.gfx = gfx; this.waypoints = waypoints; this.done = done; + this.randomize = randomize; this._paused = true; this._t = 0; @@ -362,7 +366,7 @@ TokenAnimation.prototype.create = function() { return d; }, []).flat().join(' '); - const totalDuration = getAnimationDuration(totalLength); + const totalDuration = getAnimationDuration(totalLength, this._randomize); this._parts = parts.reduce((parts, part, index) => { const duration = totalDuration / totalLength * part.length; @@ -404,8 +408,8 @@ TokenAnimation.prototype.setSpeed = function(speed) { this._speed = speed; }; -function getAnimationDuration(length) { - return Math.log(length) * randomBetween(250, 300); +function getAnimationDuration(length, randomize = false) { + return Math.log(length) * (randomize ? randomBetween(250, 300) : 250); } function randomBetween(min, max) { diff --git a/test/spec/SimulationSpec.js b/test/spec/SimulationSpec.js index 85473d9..4eebd66 100644 --- a/test/spec/SimulationSpec.js +++ b/test/spec/SimulationSpec.js @@ -3,7 +3,7 @@ import ModelerModule from 'lib/modeler'; import SimulationSupportModule from 'lib/simulation-support'; import { - bootstrapModeler, + bootstrapModeler as _bootstrapModeler, inject, getBpmnJS, withBpmnJs @@ -21,6 +21,20 @@ const TestModule = { ] }; +function bootstrapModeler(diagram, config) { + const { + animation = {}, + ...restConfig + } = config; + + return _bootstrapModeler(diagram, { + ...restConfig, + animation: { + randomize: false, + ...animation + } + }); +} describe('simulation', function() {