Commit 74842dd1 authored by PkSM3's avatar PkSM3

comments for fa2.js

parent 296c2e8c
// Mathieu Jacomy @ Sciences Po Médialab & WebAtlas // Original version made by: Mathieu Jacomy @ http://github.com/jacomyal/sigma.js/blob/deprecated-v0.1/plugins/sigma.forceatlas2.js
// This is a Modified version made by Samuel Castillo.
var ForceAtlas2 = function(graph) { var ForceAtlas2 = function(graph) {
var self = this; var self = this;
this.graph = graph; this.graph = graph;
...@@ -830,8 +830,6 @@ var ForceAtlas2 = function(graph) { ...@@ -830,8 +830,6 @@ var ForceAtlas2 = function(graph) {
}; };
}; };
var updateMassAndGeometry = function() { var updateMassAndGeometry = function() {
if (this.nodes.length > 1) { if (this.nodes.length > 1) {
// Compute Mass // Compute Mass
...@@ -883,7 +881,6 @@ var Region = function(nodes, depth) { ...@@ -883,7 +881,6 @@ var Region = function(nodes, depth) {
this.updateMassAndGeometry(); this.updateMassAndGeometry();
} }
var buildSubRegions = function() { var buildSubRegions = function() {
if (this.nodes.length > 1) { if (this.nodes.length > 1) {
var leftNodes = []; var leftNodes = [];
...@@ -957,13 +954,18 @@ var applyForce = function(n, Force, theta) { ...@@ -957,13 +954,18 @@ var applyForce = function(n, Force, theta) {
} }
}; };
var startForceAtlas2 = function(graph,limit_it) {
// pr("inside FA2")
//// if(!this.forceatlas2) { // [ NEW STUFF FOR WORKERS ]
// pr(graph);
// pr(graph.nodes[0].x) // 01. Return the values to MainContext when spatialization is finished
// pr(graph.nodes[0].y) var startForceAtlas2 = function(graph,limit_it) {
// pr("--------") // pr("inside FA2")
//// if(!this.forceatlas2) {
// pr(graph);
// pr(graph.nodes[0].x)
// pr(graph.nodes[0].y)
// pr("--------")
// nodes = graph.nodes; // nodes = graph.nodes;
// for(var n in nodes) { // for(var n in nodes) {
...@@ -995,26 +997,31 @@ var startForceAtlas2 = function(graph,limit_it) { ...@@ -995,26 +997,31 @@ var startForceAtlas2 = function(graph,limit_it) {
count++; count++;
if(flag||count>limit_it) break; if(flag||count>limit_it) break;
} }
// pr(forceatlas2.graph.nodes[0].x) // pr(forceatlas2.graph.nodes[0].x)
// pr(forceatlas2.graph.nodes[0].y) // pr(forceatlas2.graph.nodes[0].y)
// console.log("\titerations: "+count) // console.log("\titerations: "+count)
result={ result={
"nodes":forceatlas2.graph.nodes, "nodes":forceatlas2.graph.nodes,
"it":count "it":count
} }
return result; return result;
}; };
self.addEventListener("message", function(e) {
var graph = { // 02. This receives the Input from MainContext. This will execute startForceAtlas2() and will "post" the returned values in MainContext.
self.addEventListener("message", function(e) {
var graph = { // Input: nodes and edges.
"nodes":e.data.nodes, "nodes":e.data.nodes,
"edges":e.data.edges "edges":e.data.edges
} }
var limit_it=e.data.it; var limit_it=e.data.it; // Input: nb of iterations max.
result=startForceAtlas2(graph,limit_it) result=startForceAtlas2(graph,limit_it) // executing Jacomy's Algo.
postMessage({ postMessage({ // "posting" the results in MainContext.
"nodes":result.nodes, "nodes":result.nodes,
"it":result.it "it":result.it
}); });
}, false); }, false);
\ No newline at end of file
// [ / NEW STUFF FOR WORKERS ]
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment