@@ -84,21 +84,25 @@ Layout.ForceDirected = function(graph, options) {
84
84
for ( var i = 0 ; i < nodes_length ; i ++ ) {
85
85
var node_v = graph . nodes [ i ] ;
86
86
node_v . layout = node_v . layout || { } ;
87
- node_v . layout . offset_x = 0 ;
88
- node_v . layout . offset_y = 0 ;
89
- if ( this . layout === "3d" ) {
90
- node_v . layout . offset_z = 0 ;
87
+ if ( i == 0 ) {
88
+ node_v . layout . offset_x = 0 ;
89
+ node_v . layout . offset_y = 0 ;
90
+ if ( this . layout === "3d" ) {
91
+ node_v . layout . offset_z = 0 ;
92
+ }
91
93
}
94
+
92
95
node_v . layout . force = 0 ;
93
96
node_v . layout . tmp_pos_x = node_v . layout . tmp_pos_x || node_v . position . x ;
94
97
node_v . layout . tmp_pos_y = node_v . layout . tmp_pos_y || node_v . position . y ;
95
98
if ( this . layout === "3d" ) {
96
99
node_v . layout . tmp_pos_z = node_v . layout . tmp_pos_z || node_v . position . z ;
97
100
}
98
101
99
- for ( var j = 0 ; j < nodes_length ; j ++ ) {
102
+ for ( var j = i + 1 ; j < nodes_length ; j ++ ) {
100
103
var node_u = graph . nodes [ j ] ;
101
- if ( node_v . id != node_u . id ) {
104
+ // if(node_v.id != node_u.id) {
105
+ if ( i != j ) {
102
106
node_u . layout = node_u . layout || { } ;
103
107
node_u . layout . tmp_pos_x = node_u . layout . tmp_pos_x || node_u . position . x ;
104
108
node_u . layout . tmp_pos_y = node_u . layout . tmp_pos_y || node_u . position . y ;
@@ -127,8 +131,20 @@ Layout.ForceDirected = function(graph, options) {
127
131
128
132
node_v . layout . offset_x += ( delta_x / delta_length ) * force ;
129
133
node_v . layout . offset_y += ( delta_y / delta_length ) * force ;
134
+
135
+ if ( i == 0 ) {
136
+ node_u . layout . offset_x = 0 ;
137
+ node_u . layout . offset_y = 0 ;
138
+ if ( this . layout === "3d" ) {
139
+ node_u . layout . offset_z = 0 ;
140
+ }
141
+ }
142
+ node_u . layout . offset_x += - ( ( delta_x / delta_length ) * force ) ;
143
+ node_u . layout . offset_y += - ( ( delta_y / delta_length ) * force ) ;
144
+
130
145
if ( this . layout === "3d" ) {
131
146
node_v . layout . offset_z += ( delta_z / delta_length_z ) * force_z ;
147
+ node_u . layout . offset_z += - ( ( delta_z / delta_length_z ) * force_z ) ;
132
148
}
133
149
}
134
150
}
0 commit comments