@ -35,6 +35,7 @@ function Network (container, data, options) {
throw new SyntaxError ( 'Constructor must be called with the new operator' ) ;
}
this . _determineBrowserMethod ( ) ;
this . _initializeMixinLoaders ( ) ;
// create variables and set default values
@ -43,8 +44,8 @@ function Network (container, data, options) {
// render and calculation settings
this . renderRefreshRate = 60 ; // hz (fps)
this . renderTimestep = 1000 / this . renderRefreshRate ; // ms -- saves calculation later on
this . renderTime = 0.5 * this . renderTimestep ; // measured time it takes to render a frame
this . maxPhysicsTicksPerRender = 3 ; // max amount of physics ticks per render step.
this . renderTime = 0 ; // measured time it takes to render a frame
this . physicsTime = 0 ; // measured time it takes to render a frame
this . physicsDiscreteStepsize = 0.50 ; // discrete stepsize of the simulation
this . initializing = true ;
@ -349,6 +350,22 @@ function Network (container, data, options) {
// Extend Network with an Emitter mixin
Emitter ( Network . prototype ) ;
Network . prototype . _determineBrowserMethod = function ( ) {
var ua = navigator . userAgent . toLowerCase ( ) ;
this . requiresTimeout = false ;
if ( ua . indexOf ( 'msie 9.0' ) != - 1 ) { // IE 9
this . requiresTimeout = true ;
}
else if ( ua . indexOf ( 'safari' ) != - 1 ) { // safari
if ( ua . indexOf ( 'chrome' ) <= - 1 ) {
this . requiresTimeout = true ;
}
}
}
/ * *
* Get the script path where the vis . js library is located
*
@ -2166,26 +2183,26 @@ Network.prototype._physicsTick = function() {
Network . prototype . _animationStep = function ( ) {
// reset the timer so a new scheduled animation step can be set
this . timer = undefined ;
// handle the keyboad movement
this . _handleNavigation ( ) ;
// this schedules a new animation step
this . start ( ) ;
// start the physics simulation
var calculationTime = Date . now ( ) ;
var maxSteps = 1 ;
var startTime = Date . now ( ) ;
this . _physicsTick ( ) ;
var timeRequired = Date . now ( ) - calculationTime ;
while ( timeRequired < 0.9 * ( this . renderTimestep - this . renderTime ) && maxSteps < this . maxPhysicsTicksPerRender ) {
// run double speed if it is a little graph
if ( this . renderTimestep - this . renderTime > 2 * this . physicsTime ) {
this . _physicsTick ( ) ;
timeRequired = Date . now ( ) - calculationTime ;
maxSteps ++ ;
}
// start the rendering process
var renderTime = Date . now ( ) ;
this . physicsTime = Date . now ( ) - startTime ;
var renderStartTime = Date . now ( ) ;
this . _redraw ( ) ;
this . renderTime = Date . now ( ) - renderTime ;
this . renderTime = Date . now ( ) - renderStartTime ;
// this schedules a new animation step
this . start ( ) ;
} ;
if ( typeof window !== 'undefined' ) {
@ -2204,23 +2221,13 @@ Network.prototype.start = function() {
}
if ( ! this . timer ) {
var ua = navigator . userAgent . toLowerCase ( ) ;
var requiresTimeout = false ;
if ( ua . indexOf ( 'msie 9.0' ) != - 1 ) { // IE 9
requiresTimeout = true ;
}
else if ( ua . indexOf ( 'safari' ) != - 1 ) { // safari
if ( ua . indexOf ( 'chrome' ) <= - 1 ) {
requiresTimeout = true ;
}
}
if ( requiresTimeout == true ) {
if ( this . requiresTimeout == true ) {
this . timer = window . setTimeout ( this . _animationStep . bind ( this ) , this . renderTimestep ) ; // wait this.renderTimeStep milliseconds and perform the animation step function
}
else {
this . timer = window . requestAnimationFrame ( this . _animationStep . bind ( this ) , this . renderTimestep ) ; // wait this.renderTimeStep milliseconds and perform the animation step function
else {
this . timer = window . requestAnimationFrame ( this . _animationStep . bind ( this ) ) ; // wait this.renderTimeStep milliseconds and perform the animation step function
}
}
}