Skip to content

Commit e679087

Browse files
committed
Added domElement for events, added stop_calculating method to stop the layout calculation.
1 parent c42e9f0 commit e679087

File tree

2 files changed

+20
-13
lines changed

2 files changed

+20
-13
lines changed

drawings/simple_graph.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ Drawing.SimpleGraph = function(options) {
7474

7575
function init() {
7676
// Three.js initialization
77+
renderer = new THREE.WebGLRenderer({antialias: true});
78+
renderer.setSize( window.innerWidth, window.innerHeight );
79+
7780
camera = new THREE.TrackballCamera({
7881
fov: 40,
7982
aspect: window.innerWidth / window.innerHeight,
@@ -89,6 +92,8 @@ Drawing.SimpleGraph = function(options) {
8992

9093
staticMoving: false,
9194
dynamicDampingFactor: 0.3,
95+
96+
domElement: renderer.domElement,
9297

9398
keys: [ 65, 83, 68 ]
9499
});
@@ -105,6 +110,7 @@ Drawing.SimpleGraph = function(options) {
105110

106111
if(that.selection) {
107112
object_selection = new THREE.ObjectSelection({
113+
domElement: renderer.domElement,
108114
selected: function(obj) {
109115
// display info
110116
if(obj != null) {
@@ -117,9 +123,6 @@ Drawing.SimpleGraph = function(options) {
117123
});
118124
}
119125

120-
renderer = new THREE.WebGLRenderer({antialias: true});
121-
renderer.setSize( window.innerWidth, window.innerHeight );
122-
123126
document.body.appendChild( renderer.domElement );
124127

125128
// Stats.js
@@ -302,9 +305,11 @@ Drawing.SimpleGraph = function(options) {
302305
draw_object.materials[0].map.image = textCanvas;
303306
}
304307

305-
306308
function randomFromTo(from, to) {
307309
return Math.floor(Math.random() * (to - from + 1) + from);
308310
}
309-
311+
312+
this.stop_calculating = function() {
313+
graph.layout.stop_calculating();
314+
}
310315
}

drawings/sphere_graph.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ Drawing.SphereGraph = function(options) {
6565

6666
function init() {
6767
// Three.js initialization
68+
renderer = new THREE.WebGLRenderer({antialias: true});
69+
renderer.setSize( window.innerWidth, window.innerHeight );
70+
6871
camera = new THREE.TrackballCamera({
6972
fov: 35,
7073
aspect: window.innerWidth / window.innerHeight,
@@ -80,6 +83,8 @@ Drawing.SphereGraph = function(options) {
8083

8184
staticMoving: false,
8285
dynamicDampingFactor: 0.3,
86+
87+
domElement: renderer.domElement,
8388

8489
keys: [ 65, 83, 68 ]
8590
});
@@ -171,6 +176,7 @@ Drawing.SphereGraph = function(options) {
171176

172177
if(that.selection) {
173178
object_selection = new THREE.ObjectSelection({
179+
domElement: renderer.domElement,
174180
selected: function(obj) {
175181
// display info
176182
if(obj != null) {
@@ -182,10 +188,6 @@ Drawing.SphereGraph = function(options) {
182188
});
183189
}
184190

185-
renderer = new THREE.WebGLRenderer({antialias: true});
186-
187-
renderer.setSize( window.innerWidth, window.innerHeight );
188-
189191
document.body.appendChild( renderer.domElement );
190192

191193
// Stats.js
@@ -464,9 +466,7 @@ Drawing.SphereGraph = function(options) {
464466
}
465467
str += info_text[index];
466468
}
467-
if(str != '') {
468-
document.getElementById("graph-info").innerHTML = str;
469-
}
469+
document.getElementById("graph-info").innerHTML = str;
470470
}
471471

472472
function drawText(draw_object, text) {
@@ -480,9 +480,11 @@ Drawing.SphereGraph = function(options) {
480480
draw_object.materials[0].map.image = textCanvas;
481481
}
482482

483-
484483
function randomFromTo(from, to) {
485484
return Math.floor(Math.random() * (to - from + 1) + from);
486485
}
487486

487+
this.stop_calculating = function() {
488+
graph.layout.stop_calculating();
489+
}
488490
}

0 commit comments

Comments
 (0)