@@ -42,7 +42,7 @@ Layout.ForceDirected = function(graph, options) {
42
42
var options = options || { } ;
43
43
44
44
this . layout = options . layout || "2d" ;
45
- this . attraction_multiplier = options . attraction || 5 ;
45
+ this . attraction_multiplier = options . attraction || 0.75 ;
46
46
this . repulsion_multiplier = options . repulsion || 0.75 ;
47
47
this . max_iterations = options . iterations || 1000 ;
48
48
this . graph = graph ;
@@ -74,10 +74,10 @@ Layout.ForceDirected = function(graph, options) {
74
74
attraction_constant = this . attraction_multiplier * forceConstant ;
75
75
repulsion_constant = this . repulsion_multiplier * forceConstant ;
76
76
} ;
77
-
77
+
78
78
this . generate = function ( ) {
79
79
// TODO: stop if total force reached 0
80
- if ( layout_iterations < this . max_iterations ) {
80
+ if ( layout_iterations < this . max_iterations && temperature > 0.000001 ) {
81
81
var start = new Date ( ) . getTime ( ) ;
82
82
83
83
// calculate repulsion
@@ -139,12 +139,12 @@ Layout.ForceDirected = function(graph, options) {
139
139
node_u . layout . offset_z = 0 ;
140
140
}
141
141
}
142
- node_u . layout . offset_x += - ( ( delta_x / delta_length ) * force ) ;
143
- node_u . layout . offset_y += - ( ( delta_y / delta_length ) * force ) ;
142
+ node_u . layout . offset_x -= ( delta_x / delta_length ) * force ;
143
+ node_u . layout . offset_y -= ( delta_y / delta_length ) * force ;
144
144
145
145
if ( this . layout === "3d" ) {
146
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 ) ;
147
+ node_u . layout . offset_z -= ( delta_z / delta_length_z ) * force_z ;
148
148
}
149
149
}
150
150
}
@@ -199,23 +199,31 @@ Layout.ForceDirected = function(graph, options) {
199
199
node . layout . tmp_pos_z += ( node . layout . offset_z / delta_length_z ) * Math . min ( delta_length_z , temperature ) ;
200
200
}
201
201
202
- var c = 200 ;
203
- var updated = false ;
204
- if ( node . position . x < ( node . layout . tmp_pos_x - c ) || node . position . x > ( node . layout . tmp_pos_x + c ) ) {
205
- node . position . x -= ( node . position . x - node . layout . tmp_pos_x ) / 10 ;
206
- updated = true ;
207
- }
208
- if ( node . position . y < ( node . layout . tmp_pos_y - c ) || node . position . y > ( node . layout . tmp_pos_y + c ) ) {
202
+ var updated = true ;
203
+ node . position . x -= ( node . position . x - node . layout . tmp_pos_x ) / 10 ;
209
204
node . position . y -= ( node . position . y - node . layout . tmp_pos_y ) / 10 ;
210
- updated = true ;
211
- }
205
+
212
206
if ( this . layout === "3d" ) {
213
- if ( node . position . z < ( node . layout . tmp_pos_z - c ) || node . position . z > ( node . layout . tmp_pos_z + c ) ) {
214
- node . position . z -= ( node . position . z - node . layout . tmp_pos_z ) / 10 ;
215
- updated = true ;
216
- }
207
+ node . position . z -= ( node . position . z - node . layout . tmp_pos_z ) / 10 ;
217
208
}
218
209
210
+ // var c = 200;
211
+ // var updated = false;
212
+ // if(node.position.x < (node.layout.tmp_pos_x - c) || node.position.x > (node.layout.tmp_pos_x + c)) {
213
+ // node.position.x -= (node.position.x-node.layout.tmp_pos_x)/10;
214
+ // updated = true;
215
+ // }
216
+ // if(node.position.y < (node.layout.tmp_pos_y - c) || node.position.y > (node.layout.tmp_pos_y + c)) {
217
+ // node.position.y -= (node.position.y-node.layout.tmp_pos_y)/10;
218
+ // updated = true;
219
+ // }
220
+ // if(this.layout === "3d") {
221
+ // if(node.position.z < (node.layout.tmp_pos_z - c) || node.position.z > (node.layout.tmp_pos_z + c)) {
222
+ // node.position.z -= (node.position.z-node.layout.tmp_pos_z)/10;
223
+ // updated = true;
224
+ // }
225
+ // }
226
+
219
227
if ( updated && typeof callback_positionUpdated === 'function' ) {
220
228
callback_positionUpdated ( node ) ;
221
229
}
@@ -224,7 +232,9 @@ Layout.ForceDirected = function(graph, options) {
224
232
mean_time += end - start ;
225
233
// info.innerHTML = "node_force: " + parseInt(node_force) + "<br>edge_force: " + edge_force + "<br>div: " + (node_force-edge_force);
226
234
227
- // temperature *= (1.0 - (layout_iterations / this.max_iterations));
235
+ temperature *= ( 1 - ( layout_iterations / this . max_iterations ) ) ;
236
+ // temperature -= 1/100;
237
+ // console.log(temperature);
228
238
layout_iterations ++ ;
229
239
} else {
230
240
if ( ! this . finished ) {
0 commit comments