@ -17,7 +17,7 @@ class NodesHandler {
this . nodesListeners = {
this . nodesListeners = {
add : ( event , params ) => { this . add ( params . items ) ; } ,
add : ( event , params ) => { this . add ( params . items ) ; } ,
update : ( event , params ) => { this . update ( params . items , params . data ) ; } ,
update : ( event , params ) => { this . update ( params . items , params . data , params . oldData ) ; } ,
remove : ( event , params ) => { this . remove ( params . items ) ; }
remove : ( event , params ) => { this . remove ( params . items ) ; }
} ;
} ;
@ -273,10 +273,12 @@ class NodesHandler {
/ * *
/ * *
* Update existing nodes , or create them when not yet existing
* Update existing nodes , or create them when not yet existing
* @ param { Number [ ] | String [ ] } ids
* @ param { Number [ ] | String [ ] } ids id ' s of changed nodes
* @ param { Array } changedData array with changed data
* @ param { Array | undefined } oldData optional ; array with previous data
* @ private
* @ private
* /
* /
update ( ids , changedData ) {
update ( ids , changedData , oldData ) {
let nodes = this . body . nodes ;
let nodes = this . body . nodes ;
let dataChanged = false ;
let dataChanged = false ;
for ( let i = 0 ; i < ids . length ; i ++ ) {
for ( let i = 0 ; i < ids . length ; i ++ ) {
@ -285,7 +287,9 @@ class NodesHandler {
let data = changedData [ i ] ;
let data = changedData [ i ] ;
if ( node !== undefined ) {
if ( node !== undefined ) {
// update node
// update node
dataChanged = node . setOptions ( data ) ;
if ( node . setOptions ( data ) ) {
dataChanged = true ;
}
}
}
else {
else {
dataChanged = true ;
dataChanged = true ;
@ -294,6 +298,17 @@ class NodesHandler {
nodes [ id ] = node ;
nodes [ id ] = node ;
}
}
}
}
if ( ! dataChanged && oldData !== undefined ) {
// Check for any changes which should trigger a layout recalculation
// For now, this is just 'level' for hierarchical layout
// Assumption: old and new data arranged in same order; at time of writing, this holds.
dataChanged = changedData . some ( function ( newValue , index ) {
let oldValue = oldData [ index ] ;
return ( oldValue && oldValue . level !== newValue . level ) ;
} ) ;
}
if ( dataChanged === true ) {
if ( dataChanged === true ) {
this . body . emitter . emit ( "_dataChanged" ) ;
this . body . emitter . emit ( "_dataChanged" ) ;
}
}