1- var s = null , graph = null , graphMode = "default" ;
1+ var s = null , graph = null , graphMode = null ;
22
3- function GraphTracer ( ) {
4- Tracer . call ( this , GraphTracer ) ;
3+ GraphTracer . graphMode = "default" ;
54
6- if ( s && graph && graphMode == "default" ) return ;
7- initSigma ( ) ;
5+ function GraphTracer ( module ) {
6+ Tracer . call ( this , module || GraphTracer ) ;
7+ return initGraph ( this . module ) ;
88}
99
1010GraphTracer . prototype = Object . create ( Tracer . prototype ) ;
@@ -26,9 +26,8 @@ GraphTracer.prototype.reset = function () {
2626
2727// Override
2828GraphTracer . prototype . setData = function ( G ) {
29- Tracer . prototype . setData . call ( this , G ) ;
29+ if ( Tracer . prototype . setData . call ( this , arguments ) ) return ;
3030
31- this . G = G ;
3231 graph . clear ( ) ;
3332 var nodes = [ ] ;
3433 var edges = [ ] ;
@@ -73,11 +72,11 @@ Tracer.prototype.clear = function () {
7372} ;
7473
7574Tracer . prototype . visit = function ( targetNode , sourceNode ) {
76- this . pushStep ( { type : 'visit' , node : targetNode , parent : sourceNode } , true ) ;
75+ this . pushStep ( { type : 'visit' , node : targetNode , Tracer : sourceNode } , true ) ;
7776} ;
7877
7978Tracer . prototype . leave = function ( targetNode , sourceNode ) {
80- this . pushStep ( { type : 'leave' , node : targetNode , parent : sourceNode } , true ) ;
79+ this . pushStep ( { type : 'leave' , node : targetNode , Tracer : sourceNode } , true ) ;
8180} ;
8281
8382GraphTracer . prototype . processStep = function ( step , options ) {
@@ -92,15 +91,15 @@ GraphTracer.prototype.processStep = function (step, options) {
9291 var node = graph . nodes ( n ( step . node ) ) ;
9392 var color = visit ? graphColor . visited : graphColor . left ;
9493 node . color = color ;
95- if ( step . parent !== undefined ) {
96- var edgeId = e ( step . parent , step . node ) ;
94+ if ( step . Tracer !== undefined ) {
95+ var edgeId = e ( step . Tracer , step . node ) ;
9796 var edge = graph . edges ( edgeId ) ;
9897 edge . color = color ;
9998 graph . dropEdge ( edgeId ) . addEdge ( edge ) ;
10099 }
101- var parent = step . parent ;
102- if ( parent === undefined ) parent = '' ;
103- printTrace ( visit ? parent + ' -> ' + step . node : parent + ' <- ' + step . node ) ;
100+ var Tracer = step . Tracer ;
101+ if ( Tracer === undefined ) Tracer = '' ;
102+ printTrace ( visit ? Tracer + ' -> ' + step . node : Tracer + ' <- ' + step . node ) ;
104103 break ;
105104 }
106105} ;
@@ -187,7 +186,11 @@ var e = function (v1, v2) {
187186 return 'e' + v1 + '_' + v2 ;
188187} ;
189188
190- var initSigma = function ( ) {
189+ var initGraph = function ( module ) {
190+ if ( s && graph && graphMode == module . graphMode ) return false ;
191+ graphMode = module . graphMode ;
192+
193+ $ ( '.visualize_container' ) . empty ( ) ;
191194 s = new sigma ( {
192195 renderer : {
193196 container : $ ( '.visualize_container' ) [ 0 ] ,
@@ -256,4 +259,6 @@ var initSigma = function () {
256259 } ) ;
257260 } ;
258261 sigma . plugins . dragNodes ( s , s . renderers [ 0 ] ) ;
262+
263+ return true ;
259264} ;
0 commit comments