File tree Expand file tree Collapse file tree 2 files changed +20
-3
lines changed Expand file tree Collapse file tree 2 files changed +20
-3
lines changed Original file line number Diff line number Diff line change @@ -14,6 +14,8 @@ class DirectedGraphTracer extends Tracer {
1414 constructor ( name ) {
1515 super ( name ) ;
1616
17+ this . nodePositions = [ ] ;
18+
1719 if ( this . isNew ) initView ( this ) ;
1820 }
1921
@@ -43,6 +45,13 @@ class DirectedGraphTracer extends Tracer {
4345 return this ;
4446 }
4547
48+ _setNodePositions ( obj ) {
49+ for ( var i = 0 ; i < obj . length ; i ++ ) {
50+ this . nodePositions . push ( obj [ i ] ) ;
51+ }
52+ super . dirtyData ( ) ;
53+ }
54+
4655 processStep ( step , options ) {
4756 switch ( step . type ) {
4857 case 'setTreeData' :
@@ -116,7 +125,6 @@ class DirectedGraphTracer extends Tracer {
116125
117126 setData ( G , undirected ) {
118127 if ( super . setData . apply ( this , arguments ) ) return true ;
119-
120128 this . graph . clear ( ) ;
121129 const nodes = [ ] ;
122130 const edges = [ ] ;
@@ -127,8 +135,8 @@ class DirectedGraphTracer extends Tracer {
127135 nodes . push ( {
128136 id : this . n ( i ) ,
129137 label : '' + i ,
130- x : .5 + Math . sin ( currentAngle ) / 2 ,
131- y : .5 + Math . cos ( currentAngle ) / 2 ,
138+ x : ( this . nodePositions [ i ] ) ? this . nodePositions [ i ] . x : .5 + Math . sin ( currentAngle ) / 2 ,
139+ y : ( this . nodePositions [ i ] ) ? this . nodePositions [ i ] . y : .5 + Math . cos ( currentAngle ) / 2 ,
132140 size : 1 ,
133141 color : this . color . default ,
134142 weight : 0
Original file line number Diff line number Diff line change @@ -77,12 +77,21 @@ class Tracer {
7777 $name . text ( name || this . defaultName ) ;
7878 }
7979
80+ dirtyData ( ) {
81+ this . isNew = true ;
82+ }
83+
84+ cleanData ( ) {
85+ this . isNew = false ;
86+ }
87+
8088 setData ( ) {
8189 const data = toJSON ( arguments ) ;
8290 if ( ! this . isNew && this . lastData === data ) {
8391 return true ;
8492 }
8593 this . lastData = this . capsule . lastData = data ;
94+ this . cleanData ( ) ;
8695 return false ;
8796 }
8897
You can’t perform that action at this time.
0 commit comments