@ -39,7 +39,7 @@ import allOptions from './modules/components/AllOptions.js';
* { Array } edges
* { Array } edges
* @ param { Object } options Options
* @ param { Object } options Options
* /
* /
function Network ( container , data , options ) {
function Network ( container , data , options ) {
if ( ! ( this instanceof Network ) ) {
if ( ! ( this instanceof Network ) ) {
throw new SyntaxError ( 'Constructor must be called with the new operator' ) ;
throw new SyntaxError ( 'Constructor must be called with the new operator' ) ;
}
}
@ -61,35 +61,35 @@ function Network (container, data, options) {
nodes : null , // A DataSet or DataView
nodes : null , // A DataSet or DataView
edges : null // A DataSet or DataView
edges : null // A DataSet or DataView
} ,
} ,
functions : {
createNode : ( ) => { } ,
createEdge : ( ) => { } ,
getPointer : ( ) => { }
functions : {
createNode : function ( ) { } ,
createEdge : function ( ) { } ,
getPointer : function ( ) { }
} ,
} ,
emitter : {
emitter : {
on : this . on . bind ( this ) ,
off : this . off . bind ( this ) ,
on : this . on . bind ( this ) ,
off : this . off . bind ( this ) ,
emit : this . emit . bind ( this ) ,
emit : this . emit . bind ( this ) ,
once : this . once . bind ( this )
once : this . once . bind ( this )
} ,
} ,
eventListeners : {
eventListeners : {
onTap : function ( ) { } ,
onTouch : function ( ) { } ,
onDoubleTap : function ( ) { } ,
onHold : function ( ) { } ,
onDragStart : function ( ) { } ,
onDrag : function ( ) { } ,
onDragEnd : function ( ) { } ,
onTap : function ( ) { } ,
onTouch : function ( ) { } ,
onDoubleTap : function ( ) { } ,
onHold : function ( ) { } ,
onDragStart : function ( ) { } ,
onDrag : function ( ) { } ,
onDragEnd : function ( ) { } ,
onMouseWheel : function ( ) { } ,
onMouseWheel : function ( ) { } ,
onPinch : function ( ) { } ,
onMouseMove : function ( ) { } ,
onRelease : function ( ) { } ,
onContext : function ( ) { }
onPinch : function ( ) { } ,
onMouseMove : function ( ) { } ,
onRelease : function ( ) { } ,
onContext : function ( ) { }
} ,
} ,
container : container ,
container : container ,
view : {
view : {
scale : 1 ,
translation : { x : 0 , y : 0 }
scale : 1 ,
translation : { x : 0 , y : 0 }
}
}
} ;
} ;
@ -97,20 +97,20 @@ function Network (container, data, options) {
this . bindEventListeners ( ) ;
this . bindEventListeners ( ) ;
// setting up all modules
// setting up all modules
var images = new Images ( ( ) => this . body . emitter . emit ( "_requestRedraw" ) ) ; // object with images
this . groups = new Groups ( ) ; // object with groups
this . canvas = new Canvas ( this . body ) ; // DOM handler
this . selectionHandler = new SelectionHandler ( this . body , this . canvas ) ; // Selection handler
this . interactionHandler = new InteractionHandler ( this . body , this . canvas , this . selectionHandler ) ; // Interaction handler handles all the hammer bindings (that are bound by canvas), key
this . view = new View ( this . body , this . canvas ) ; // camera handler, does animations and zooms
this . renderer = new CanvasRenderer ( this . body , this . canvas ) ; // renderer, starts renderloop, has events that modules can hook into
this . physics = new PhysicsEngine ( this . body ) ; // physics engine, does all the simulations
this . layoutEngine = new LayoutEngine ( this . body ) ; // layout engine for inital layout and hierarchical layout
this . clustering = new ClusterEngine ( this . body ) ; // clustering api
this . manipulation = new ManipulationSystem ( this . body , this . canvas , this . selectionHandler ) ; // data manipulation system
this . nodesHandler = new NodesHandler ( this . body , images , this . groups , this . layoutEngine ) ; // Handle adding, deleting and updating of nodes as well as global options
this . edgesHandler = new EdgesHandler ( this . body , images , this . groups ) ; // Handle adding, deleting and updating of edges as well as global options
this . images = new Images ( ( ) => this . body . emitter . emit ( "_requestRedraw" ) ) ; // object with images
this . groups = new Groups ( ) ; // object with groups
this . canvas = new Canvas ( this . body ) ; // DOM handler
this . selectionHandler = new SelectionHandler ( this . body , this . canvas ) ; // Selection handler
this . interactionHandler = new InteractionHandler ( this . body , this . canvas , this . selectionHandler ) ; // Interaction handler handles all the hammer bindings (that are bound by canvas), key
this . view = new View ( this . body , this . canvas ) ; // camera handler, does animations and zooms
this . renderer = new CanvasRenderer ( this . body , this . canvas ) ; // renderer, starts renderloop, has events that modules can hook into
this . physics = new PhysicsEngine ( this . body ) ; // physics engine, does all the simulations
this . layoutEngine = new LayoutEngine ( this . body ) ; // layout engine for inital layout and hierarchical layout
this . clustering = new ClusterEngine ( this . body ) ; // clustering api
this . manipulation = new ManipulationSystem ( this . body , this . canvas , this . selectionHandler ) ; // data manipulation system
this . nodesHandler = new NodesHandler ( this . body , this . images , this . groups , this . layoutEngine ) ; // Handle adding, deleting and updating of nodes as well as global options
this . edgesHandler = new EdgesHandler ( this . body , this . images , this . groups ) ; // Handle adding, deleting and updating of edges as well as global options
this . configurationSystem = new ConfigurationSystem ( this ) ;
this . configurationSystem = new ConfigurationSystem ( this ) ;
@ -136,7 +136,7 @@ Emitter(Network.prototype);
Network . prototype . setOptions = function ( options ) {
Network . prototype . setOptions = function ( options ) {
if ( options !== undefined ) {
if ( options !== undefined ) {
let errorFound = Validator . validate ( options , allOptions ) ;
let errorFound = Validator . validate ( options , allOptions ) ;
if ( errorFound === true ) {
if ( errorFound === true ) {
options = { } ;
options = { } ;
console . log ( '%cErrors have been found in the supplied options object. None of the options will be used.' , printStyle ) ;
console . log ( '%cErrors have been found in the supplied options object. None of the options will be used.' , printStyle ) ;
@ -192,7 +192,7 @@ Network.prototype.setOptions = function (options) {
* Update the this . body . nodeIndices with the most recent node index list
* Update the this . body . nodeIndices with the most recent node index list
* @ private
* @ private
* /
* /
Network . prototype . _updateVisibleIndices = function ( ) {
Network . prototype . _updateVisibleIndices = function ( ) {
let nodes = this . body . nodes ;
let nodes = this . body . nodes ;
let edges = this . body . edges ;
let edges = this . body . edges ;
this . body . nodeIndices = [ ] ;
this . body . nodeIndices = [ ] ;
@ -215,7 +215,11 @@ Network.prototype._updateVisibleIndices = function() {
}
}
} ;
} ;
Network . prototype . bindEventListeners = function ( ) {
/ * *
* Bind all events
* /
Network . prototype . bindEventListeners = function ( ) {
// this event will trigger a rebuilding of the cache everything. Used when nodes or edges have been added or removed.
// this event will trigger a rebuilding of the cache everything. Used when nodes or edges have been added or removed.
this . body . emitter . on ( "_dataChanged" , ( params ) => {
this . body . emitter . on ( "_dataChanged" , ( params ) => {
// update shortcut lists
// update shortcut lists
@ -236,6 +240,7 @@ Network.prototype.bindEventListeners = function() {
} ) ;
} ) ;
}
}
/ * *
/ * *
* Set nodes and edges , and optionally options as well .
* Set nodes and edges , and optionally options as well .
*
*
@ -247,7 +252,7 @@ Network.prototype.bindEventListeners = function() {
* { Options } [ options ] Object with options
* { Options } [ options ] Object with options
* @ param { Boolean } [ disableStart ] | optional : disable the calling of the start function .
* @ param { Boolean } [ disableStart ] | optional : disable the calling of the start function .
* /
* /
Network . prototype . setData = function ( data ) {
Network . prototype . setData = function ( data ) {
// reset the physics engine.
// reset the physics engine.
this . body . emitter . emit ( "resetPhysics" ) ;
this . body . emitter . emit ( "resetPhysics" ) ;
this . body . emitter . emit ( "_resetData" ) ;
this . body . emitter . emit ( "_resetData" ) ;
@ -257,7 +262,7 @@ Network.prototype.setData = function(data) {
if ( data && data . dot && ( data . nodes || data . edges ) ) {
if ( data && data . dot && ( data . nodes || data . edges ) ) {
throw new SyntaxError ( 'Data must contain either parameter "dot" or ' +
throw new SyntaxError ( 'Data must contain either parameter "dot" or ' +
' parameter pair "nodes" and "edges", but not both.' ) ;
' parameter pair "nodes" and "edges", but not both.' ) ;
}
}
// set options
// set options
@ -265,7 +270,7 @@ Network.prototype.setData = function(data) {
// set all data
// set all data
if ( data && data . dot ) {
if ( data && data . dot ) {
// parse DOT file
// parse DOT file
if ( data && data . dot ) {
if ( data && data . dot ) {
var dotData = dotparser . DOTToGraph ( data . dot ) ;
var dotData = dotparser . DOTToGraph ( data . dot ) ;
this . setData ( dotData ) ;
this . setData ( dotData ) ;
return ;
return ;
@ -273,7 +278,7 @@ Network.prototype.setData = function(data) {
}
}
else if ( data && data . gephi ) {
else if ( data && data . gephi ) {
// parse DOT file
// parse DOT file
if ( data && data . gephi ) {
if ( data && data . gephi ) {
var gephiData = gephiParser . parseGephi ( data . gephi ) ;
var gephiData = gephiParser . parseGephi ( data . gephi ) ;
this . setData ( gephiData ) ;
this . setData ( gephiData ) ;
return ;
return ;
@ -298,16 +303,45 @@ Network.prototype.setData = function(data) {
* network . destroy ( ) ;
* network . destroy ( ) ;
* network = null ;
* network = null ;
* /
* /
Network . prototype . destroy = function ( ) {
Network . prototype . destroy = function ( ) {
this . body . emitter . emit ( "destroy" ) ;
this . body . emitter . emit ( "destroy" ) ;
// clear events
// clear events
this . body . emitter . off ( ) ;
this . body . emitter . off ( ) ;
this . off ( ) ;
this . off ( ) ;
// delete modules
delete this . groups ;
delete this . canvas ;
delete this . selectionHandler ;
delete this . interactionHandler ;
delete this . view ;
delete this . renderer ;
delete this . physics ;
delete this . layoutEngine ;
delete this . clustering ;
delete this . manipulation ;
delete this . nodesHandler ;
delete this . edgesHandler ;
delete this . configurationSystem ;
delete this . images ;
// delete emitter bindings
delete this . body . emitter . emit ;
delete this . body . emitter . on ;
delete this . body . emitter . off ;
delete this . body . emitter . once ;
delete this . body . emitter ;
for ( var nodeId in this . body . nodes ) {
delete this . body . nodes [ nodeId ] ;
}
for ( var edgeId in this . body . edges ) {
delete this . body . edges [ edgeId ] ;
}
// remove the container and everything inside it recursively
// remove the container and everything inside it recursively
util . recursiveDOMDelete ( this . body . container ) ;
util . recursiveDOMDelete ( this . body . container ) ;
} ;
} ;
@ -319,7 +353,7 @@ Network.prototype.destroy = function() {
* setValueRange ( min , max ) .
* setValueRange ( min , max ) .
* @ private
* @ private
* /
* /
Network . prototype . _updateValueRange = function ( obj ) {
Network . prototype . _updateValueRange = function ( obj ) {
var id ;
var id ;
// determine the range of the objects
// determine the range of the objects