@ -228,6 +228,8 @@ function Network (container, data, options) {
this . targetScale = 0 ;
this . sourceTranslation = 0 ;
this . targetTranslation = 0 ;
this . lockedOnNodeId = null ;
this . lockedOnNodeOffset = null ;
// Node variables
var network = this ;
@ -896,6 +898,8 @@ Network.prototype._handleOnDrag = function(event) {
return ;
}
this . releaseNode ( ) ;
var pointer = this . _getPointer ( event . gesture . center ) ;
var me = this ;
@ -2273,6 +2277,7 @@ Network.prototype.focusOnNode = function (nodeId, options) {
}
var nodePosition = { x : this . nodes [ nodeId ] . x , y : this . nodes [ nodeId ] . y } ;
options . position = nodePosition ;
options . lockedOnNode = nodeId ;
this . moveTo ( options )
}
@ -2324,6 +2329,13 @@ Network.prototype.animateView = function (options) {
return ;
}
// release if something focussed on the node
this . releaseNode ( ) ;
if ( options . locked == true ) {
this . lockedOnNodeId = options . lockedOnNode ;
this . lockedOnNodeOffset = options . offset ;
}
// forcefully complete the old animation if it was still running
if ( this . easingTime != 0 ) {
this . _transitionRedraw ( 1 ) ; // by setting easingtime to 1, we finish the animation.
@ -2348,9 +2360,15 @@ Network.prototype.animateView = function (options) {
// if the time is set to 0, don't do an animation
if ( options . animation . duration == 0 ) {
this . _setScale ( this . targetScale ) ;
this . _setTranslation ( this . targetTranslation . x , this . targetTranslation . y ) ;
this . _redraw ( ) ;
if ( this . lockedOnNodeId != null ) {
this . _classicRedraw = this . _redraw ;
this . _redraw = this . _lockedRedraw ;
}
else {
this . _setScale ( this . targetScale ) ;
this . _setTranslation ( this . targetTranslation . x , this . targetTranslation . y ) ;
this . _redraw ( ) ;
}
}
else {
this . animationSpeed = 1 / ( this . renderRefreshRate * options . animation . duration * 0.001 ) || 1 / this . renderRefreshRate ;
@ -2364,6 +2382,31 @@ Network.prototype.animateView = function (options) {
} ;
Network . prototype . _lockedRedraw = function ( ) {
var nodePosition = { x : this . nodes [ this . lockedOnNodeId ] . x , y : this . nodes [ this . lockedOnNodeId ] . y } ;
var viewCenter = this . DOMtoCanvas ( { x : 0.5 * this . frame . canvas . clientWidth , y : 0.5 * this . frame . canvas . clientHeight } ) ;
var distanceFromCenter = { // offset from view, distance view has to change by these x and y to center the node
x : viewCenter . x - nodePosition . x ,
y : viewCenter . y - nodePosition . y
} ;
var sourceTranslation = this . _getTranslation ( ) ;
var targetTranslation = {
x : sourceTranslation . x + distanceFromCenter . x * this . scale + this . lockedOnNodeOffset . x ,
y : sourceTranslation . y + distanceFromCenter . y * this . scale + this . lockedOnNodeOffset . y
} ;
this . _setTranslation ( targetTranslation . x , targetTranslation . y ) ;
this . _classicRedraw ( ) ;
}
Network . prototype . releaseNode = function ( ) {
if ( this . lockedOnNodeId != null ) {
this . _redraw = this . _classicRedraw ;
this . lockedOnNodeId = null ;
this . lockedOnNodeOffset = null ;
}
}
/ * *
*
* @ param easingTime
@ -2383,10 +2426,16 @@ Network.prototype._transitionRedraw = function (easingTime) {
this . _classicRedraw ( ) ;
this . moving = true ;
// cleanup
if ( this . easingTime >= 1.0 ) {
this . easingTime = 0 ;
this . _redraw = this . _classicRedraw ;
if ( this . lockedOnNodeId != null ) {
this . _redraw = this . _lockedRedraw ;
}
else {
this . _redraw = this . _classicRedraw ;
}
this . emit ( "animationFinished" ) ;
}
} ;