@ -46,6 +46,7 @@ function Network (container, data, options) {
this . renderTimestep = 1000 / this . renderRefreshRate ; // ms -- saves calculation later on
this . renderTime = 0 ; // measured time it takes to render a frame
this . physicsTime = 0 ; // measured time it takes to render a frame
this . runDoubleSpeed = false ;
this . physicsDiscreteStepsize = 0.50 ; // discrete stepsize of the simulation
this . initializing = true ;
@ -2149,6 +2150,23 @@ Network.prototype._discreteStepNodes = function() {
return false ;
} ;
Network . prototype . _revertPhysicsState = function ( ) {
var nodes = this . nodes ;
for ( var nodeId in nodes ) {
if ( nodes . hasOwnProperty ( nodeId ) ) {
nodes [ nodeId ] . revertPosition ( ) ;
}
}
}
Network . prototype . _revertPhysicsTick = function ( ) {
this . _doInAllActiveSectors ( "_revertPhysicsState" ) ;
if ( this . constants . smoothCurves . enabled == true && this . constants . smoothCurves . dynamic == true ) {
this . _doInSupportSector ( "_revertPhysicsState" ) ;
}
}
/ * *
* A single simulation step ( or "tick" ) in the physics simulation
*
@ -2172,6 +2190,17 @@ Network.prototype._physicsTick = function() {
// determine if the network has stabilzied
this . moving = mainMovingStatus || supportMovingStatus ;
if ( this . moving == false ) {
this . _revertPhysicsTick ( ) ;
}
else {
// this is here to ensure that there is no start event when the network is already stable.
if ( this . startedStabilization == false ) {
this . emit ( "startStabilization" ) ;
this . startedStabilization = true ;
}
}
this . stabilizationIterations ++ ;
}
}
@ -2193,13 +2222,17 @@ Network.prototype._animationStep = function() {
var startTime = Date . now ( ) ;
this . _physicsTick ( ) ;
var physicsTime = Date . now ( ) - startTime ;
// run double speed if it is a little graph
if ( this . renderTimestep - this . renderTime > 2 * this . physicsTim e) {
if ( ( this . renderTimestep - this . renderTime > 2 * physicsTime || this . runDoubleSpeed == true ) && this . moving == tru e) {
this . _physicsTick ( ) ;
}
this . physicsTime = Date . now ( ) - startTime ;
// this makes sure there is no jitter. The decision is taken once to run it at double speed.
if ( this . renderTime != 0 ) {
this . runDoubleSpeed = true
}
}
var renderStartTime = Date . now ( ) ;
this . _redraw ( ) ;
@ -2219,11 +2252,6 @@ if (typeof window !== 'undefined') {
* /
Network . prototype . start = function ( ) {
if ( this . moving == true || this . xIncrement != 0 || this . yIncrement != 0 || this . zoomIncrement != 0 ) {
if ( this . startedStabilization == false ) {
this . emit ( "startStabilization" ) ;
this . startedStabilization = true ;
}
if ( ! this . timer ) {
if ( this . requiresTimeout == true ) {
this . timer = window . setTimeout ( this . _animationStep . bind ( this ) , this . renderTimestep ) ; // wait this.renderTimeStep milliseconds and perform the animation step function
@ -2235,7 +2263,8 @@ Network.prototype.start = function() {
}
else {
this . _redraw ( ) ;
if ( this . stabilizationIterations > 0 ) {
// this check is to ensure that the network does not emit these events if it was already stabilized and setOptions is called (setting moving to true and calling start())
if ( this . stabilizationIterations > 1 ) {
// trigger the "stabilized" event.
// The event is triggered on the next tick, to prevent the case that
// it is fired while initializing the Network, in which case you would not
@ -2244,12 +2273,15 @@ Network.prototype.start = function() {
var params = {
iterations : me . stabilizationIterations
} ;
me . stabilizationIterations = 0 ;
me . startedStabilization = false ;
this . stabilizationIterations = 0 ;
this . startedStabilization = false ;
setTimeout ( function ( ) {
me . emit ( "stabilized" , params ) ;
} , 0 ) ;
}
else {
this . stabilizationIterations = 0 ;
}
}
} ;