@ -4,6 +4,7 @@ var DataView = require('../../DataView');
var Edge = require ( "./components/Edge" ) . default ;
var Edge = require ( "./components/Edge" ) . default ;
var Label = require ( "./components/shared/Label" ) . default ;
var Label = require ( "./components/shared/Label" ) . default ;
var LayoutEngine = require ( "./LayoutEngine" ) . default ; // For access to LayoutEngine.getStaticType()
class EdgesHandler {
class EdgesHandler {
constructor ( body , images , groups ) {
constructor ( body , images , groups ) {
@ -115,11 +116,11 @@ class EdgesHandler {
bindEventListeners ( ) {
bindEventListeners ( ) {
// this allows external modules to force all dynamic curves to turn static.
// this allows external modules to force all dynamic curves to turn static.
this . body . emitter . on ( "_forceDisableDynamicCurves" , ( type ) => {
this . body . emitter . on ( "_forceDisableDynamicCurves" , ( type , emit = true ) => {
if ( type === 'dynamic' ) {
if ( type === 'dynamic' ) {
type = 'continuous' ;
type = 'continuous' ;
}
}
let emitChange = false ;
let dataChanged = false ;
for ( let edgeId in this . body . edges ) {
for ( let edgeId in this . body . edges ) {
if ( this . body . edges . hasOwnProperty ( edgeId ) ) {
if ( this . body . edges . hasOwnProperty ( edgeId ) ) {
let edge = this . body . edges [ edgeId ] ;
let edge = this . body . edges [ edgeId ] ;
@ -137,18 +138,25 @@ class EdgesHandler {
else {
else {
edge . setOptions ( { smooth : { type : type } } ) ;
edge . setOptions ( { smooth : { type : type } } ) ;
}
}
emitChange = true ;
dataChanged = true ;
}
}
}
}
}
}
}
}
}
}
if ( emitChange === true ) {
if ( emit === true && data Changed === true ) {
this . body . emitter . emit ( "_dataChanged" ) ;
this . body . emitter . emit ( "_dataChanged" ) ;
}
}
} ) ;
} ) ;
// this is called when options of EXISTING nodes or edges have changed.
// this is called when options of EXISTING nodes or edges have changed.
//
// NOTE: Not true, called when options have NOT changed, for both existing as well as new nodes.
// See update() for logic.
// TODO: Verify and examine the consequences of this. It might still trigger when
// non-option fields have changed, but then reconnecting edges is still useless.
// Alternatively, it might also be called when edges are removed.
//
this . body . emitter . on ( "_dataUpdated" , ( ) => {
this . body . emitter . on ( "_dataUpdated" , ( ) => {
this . reconnectEdges ( ) ;
this . reconnectEdges ( ) ;
} ) ;
} ) ;
@ -247,6 +255,7 @@ class EdgesHandler {
this . add ( ids , true ) ;
this . add ( ids , true ) ;
}
}
this . body . emitter . emit ( '_adjustEdgesForHierarchicalLayout' ) ;
if ( doNotEmit === false ) {
if ( doNotEmit === false ) {
this . body . emitter . emit ( "_dataChanged" ) ;
this . body . emitter . emit ( "_dataChanged" ) ;
}
}
@ -274,6 +283,8 @@ class EdgesHandler {
edges [ id ] = this . create ( data ) ;
edges [ id ] = this . create ( data ) ;
}
}
this . body . emitter . emit ( '_adjustEdgesForHierarchicalLayout' ) ;
if ( doNotEmit === false ) {
if ( doNotEmit === false ) {
this . body . emitter . emit ( "_dataChanged" ) ;
this . body . emitter . emit ( "_dataChanged" ) ;
}
}
@ -308,6 +319,7 @@ class EdgesHandler {
}
}
if ( dataChanged === true ) {
if ( dataChanged === true ) {
this . body . emitter . emit ( '_adjustEdgesForHierarchicalLayout' ) ;
this . body . emitter . emit ( "_dataChanged" ) ;
this . body . emitter . emit ( "_dataChanged" ) ;
}
}
else {
else {