Skip to content

Commit cff8bec

Browse files
committed
Added graph layout options.
1 parent 75d9b38 commit cff8bec

File tree

1 file changed

+74
-3
lines changed

1 file changed

+74
-3
lines changed

drawings/simple_graph.js

Lines changed: 74 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ Drawing.SimpleGraph = function(options) {
5252
var options = options || {};
5353

5454
this.layout = options.layout || "2d";
55+
this.layout_options = options.graphLayout || {};
5556
this.show_stats = options.showStats || false;
5657
this.show_info = options.showInfo || false;
5758
this.selection = options.selection || false;
@@ -143,6 +144,7 @@ Drawing.SimpleGraph = function(options) {
143144
}
144145

145146
function createGraph() {
147+
146148
var node = new Node(0);
147149
graph.addNode(node);
148150
drawNode(node);
@@ -167,13 +169,82 @@ Drawing.SimpleGraph = function(options) {
167169
}
168170
steps++;
169171
}
170-
171-
graph.layout = new Layout.ForceDirected(graph, {width: 2000, height: 2000, iterations: 1000, layout: that.layout});
172+
173+
that.layout_options.width = that.layout_options.width || 2000;
174+
that.layout_options.height = that.layout_options.height || 2000;
175+
that.layout_options.iterations = that.layout_options.iterations || 100000;
176+
that.layout_options.layout = that.layout_options.layout || that.layout;
177+
graph.layout = new Layout.ForceDirected(graph, that.layout_options);
172178
graph.layout.init();
173179
info_text.nodes = "Nodes " + graph.nodes.length;
174180
info_text.edges = "Edges " + graph.edges.length;
175181
}
176182

183+
// for testing...
184+
// function createCube() {
185+
//
186+
// var a1 = new Node("a1");
187+
// graph.addNode(a1);
188+
// drawNode(a1);
189+
//
190+
// var a2 = new Node("a2");
191+
// graph.addNode(a2);
192+
// drawNode(a2);
193+
// var a3 = new Node("a3");
194+
// graph.addNode(a3);
195+
// drawNode(a3);
196+
// var a4 = new Node("a4");
197+
// graph.addNode(a4);
198+
// drawNode(a4);
199+
// var b1 = new Node("b1");
200+
// graph.addNode(b1);
201+
// drawNode(b1);
202+
// var b2 = new Node("b2");
203+
// graph.addNode(b2);
204+
// drawNode(b2);
205+
// var b3 = new Node("b3");
206+
// graph.addNode(b3);
207+
// drawNode(b3);
208+
// var b4 = new Node("b4");
209+
// graph.addNode(b4);
210+
// drawNode(b4);
211+
//
212+
// graph.addEdge(a1, a2);
213+
// drawEdge(a1, a2);
214+
// graph.addEdge(a1, a4);
215+
// drawEdge(a1, a4);
216+
// graph.addEdge(a1, b1);
217+
// drawEdge(a1, b1);
218+
//
219+
// graph.addEdge(a2, a3);
220+
// drawEdge(a2, a3);
221+
// graph.addEdge(a2, b2);
222+
// drawEdge(a2, b2);
223+
//
224+
// graph.addEdge(a3, a4);
225+
// drawEdge(a3, a4);
226+
// graph.addEdge(a3, b3);
227+
// drawEdge(a3, b3);
228+
//
229+
// graph.addEdge(a4, b4);
230+
// drawEdge(a4, b4);
231+
//
232+
// graph.addEdge(b1, b2);
233+
// drawEdge(b1, b2);
234+
// graph.addEdge(b1, b4);
235+
// drawEdge(b1, b4);
236+
//
237+
// graph.addEdge(b2, b3);
238+
// drawEdge(b2, b3);
239+
// graph.addEdge(b3, b4);
240+
// drawEdge(b3, b4);
241+
//
242+
//
243+
// graph.layout = new Layout.ForceDirected(graph, {width: 2000, height: 2000, iterations: 10000, layout: that.layout});
244+
// graph.layout.init();
245+
// info_text.nodes = "Nodes " + graph.nodes.length;
246+
// info_text.edges = "Edges " + graph.edges.length;
247+
// }
177248

178249

179250
function drawNode(node) {
@@ -194,7 +265,7 @@ Drawing.SimpleGraph = function(options) {
194265
// var xm = new THREE.MeshBasicMaterial( { map: new THREE.Texture( labelCanvas ), transparent: true } );
195266
// xm.map.needsUpdate = true;
196267

197-
var area = 2000;
268+
var area = 5000;
198269
draw_object.position.x = Math.floor(Math.random() * (area + area + 1) - area);
199270
draw_object.position.y = Math.floor(Math.random() * (area + area + 1) - area);
200271

0 commit comments

Comments
 (0)