Commit 88a40a81 authored by Romain Loth's avatar Romain Loth

add debug traces to each function, remove trailing spaces in scripts, add...

add debug traces to each function, remove trailing spaces in scripts, add initialization call graph schema
parent 8c5a4451
// dot call_graph.dot -Tpng -o tina_call_graph.png
digraph tina_call_graph {
graph [ordering="out"];
rankdir=LR ;
edge [fontsize=10] ;
label=<<B><U>tinawebJS</U></B><BR/>(initialization callgraph)>;
labelloc="t" ;
// settings
"settings var" -> "settings:SystemStates";
"settings var" -> "settings:sigmaJsDrawingProperties";
"settings var" -> "etc.";
// getUrlParam
"t.globalUtils:getUrlParam" -> "var mainfile (url)" ;
// main 1: get graph
"t.main" -> "var mainfile (url)" ;
"var mainfile (url)" -> "ajax garg" ;
"ajax garg" -> "t.main:MainFunction" ;
// main 2: parse graph
"t.main:MainFunction" -> "t.sigma.parseCustom:ParseCustom" ;
"t.main:MainFunction" -> "t.sigma.parseCustom:scanFile" ;
"t.sigma.parseCustom:scanFile" -> "t.sigma.parseCustom:getJSONCategories" ;
"t.sigma.parseCustom:getJSONCategories" -> "t.sigma.parseCustom:scanJSON" ;
"t.main:MainFunction" -> "t.sigma.parseCustom:makeSystemStates" ;
"t.main:MainFunction" -> "t.sigma.parseCustom:buildInitialState" ;
"t.main:MainFunction" -> "t.sigma.parseCustom:makeDicts" ;
"t.sigma.parseCustom:makeDicts" -> "t.sigma.parseCustom:dictfyJSON" [label="cats={'terms':0}"] ;
// main 3: new TinaWebJS()
"t.main:MainFunction" -> "var twjs_" ;
"var twjs_" -> "t.TinawebJS:TinaWebJS:new" ;
// main 4: adjust canvas routine
"t.main:MainFunction" -> "t.TinawebJS:AdjustSigmaCanvas" ; // twjs_.AdjustSigmaCanvas()
"t.TinawebJS:AdjustSigmaCanvas" -> "t.TinawebJS:sigmaLimits" ;
"t.TinawebJS:sigmaLimits" -> "t.TinawebJS:visibleHeight" ;
"t.TinawebJS:sigmaLimits" -> "new canvas!" ;
// main 5: partialGraph and new SigmaUtils()
"t.main:MainFunction" -> "var partialGraph" ;
"var partialGraph" -> "sigma:init";
"t.main:MainFunction" -> "t.SigmaUtils:SigmaUtils:new" ;
"t.main:MainFunction" -> "t.SigmaUtils:SigmaUtils:FillGraph" ; // [ Poblating the Sigma-Graph ]
"t.SigmaUtils:SigmaUtils:FillGraph" -> "SigmaPublic.addNode" [label="x N"];
"t.SigmaUtils:SigmaUtils:FillGraph" -> "SigmaPublic.addEdge" [label="x N"];
"SigmaPublic.addEdge" -> "t.globalUtils:hex2rga" [label="x M"];
"t.SigmaUtils:SigmaUtils:FillGraph" -> "t.enviroment:updateSearchLabels" [label="N x push labels"];
// main 6: state and settings for partialGraph
// "settings:sigmaJsDrawingProperties" -> "var partialGraph" ;
// "settings:SystemStates" -> "var partialGraph" ;
"var partialGraph" -> "t.main:partialGraph:setState";
// main 7: twjs_.initListeners( categories , partialGraph)
"t.main:MainFunction" -> "t.TinawebJS:initListeners" ;
"t.TinawebJS:initListeners" -> "t.TinawebJS:SelectionEngine:new" [label="initListeners:SelInst"] ;
"t.TinawebJS:initListeners" -> "onclick:#changetype" ;
"t.TinawebJS:initListeners" -> "onclick:#changelevel" ;
"t.TinawebJS:initListeners" -> "onclick:#aUnfold" ;
"t.TinawebJS:initListeners" -> "t.minimap:startMiniMap" [label = "if minimap"] ;
"t.TinawebJS:initListeners" -> "t.methods:pushSWClick" [label = "var swclickActual"] ;
"t.TinawebJS:initListeners" -> "t.methods:cancelSelection" ;
"t.methods:cancelSelection" -> "t.methods:highlightSelectedNodes" [label = "false"] ;
"t.methods:highlightSelectedNodes" -> "t.globalUtils:is_empty" ;
"t.methods:cancelSelection" -> "erase:#names" ;
"t.methods:cancelSelection" -> "erase:#ngrams_actions" ;
"t.methods:cancelSelection" -> "erase:#topPapers" ;
"t.methods:cancelSelection" -> "erase:#opossiteNodes" ;
"t.methods:cancelSelection" -> "erase:#searchinput" ;
"t.methods:cancelSelection" -> "t.methods:LevelButtonDisable" ;
"t.TinawebJS:initListeners" -> "t.sigmaUtils:showMeSomeLabels" ;
"t.sigmaUtils:showMeSomeLabels" -> "t.sigmaUtils:getVisibleNodes" ;
"t.TinawebJS:initListeners" -> "t.TinawebJS:SearchListeners" ;
"t.TinawebJS:SearchListeners" -> "autocomplete:#searchinput" ;
"autocomplete:#searchinput" -> "t.TinawebJS:SelectionEngine:new" [label="SearchListeners:SelInst"] ;
/*t.methods:highlightSelectedNodes*/
}
partialGraph.zoomTo(partialGraph._core.width / 2, partialGraph._core.height / 2, 0.2).draw();
SystemStates
// {
// "level": true,
// "type": [
// true
// ],
// "selections": [],
// "opposites": [],
// "categories": [
// "terms"
// ],
// "categoriesDict": {
// "terms": "0"
// },
// "LouvainFait": false
// }
This diff is collapsed.
......@@ -2,6 +2,8 @@
* Customize as you want ;)
*/
console.log('FUN settings_explorerjs:main')
// ============ < DEVELOPER OPTIONS > ============
var geomap=false;
var colorByAtt = false;
......@@ -78,7 +80,7 @@ var SigmaUtils = function () {};
var TinaWebJS = function () {};
var Relations = {}
var SystemStates = {}
SystemStates.level = true;
......@@ -116,7 +118,7 @@ var desirableScholarSize=6; //Remember that all scholars have the same size!
*Three states:
* - true: fa2 running at start
* - false: fa2 stopped at start, button exists
* - "off": button doesn't exist, fa2 stopped forever
* - "off": button doesn't exist, fa2 stopped forever
**/ var fa2enabled=false;//"off";
var stopcriteria = false;
var iterationsFA2=1000;
......@@ -152,7 +154,7 @@ var sigmaJsMouseProperties = {
maxRatio: 50
};
// ============ < / SIGMA.JS PROPERTIES > ============
// ============ < / DEVELOPER OPTIONS > ============
......@@ -198,14 +200,14 @@ var overviewScale = 0.25;
var overviewHover=false;
var moveDelay = 80, zoomDelay = 2;
//var Vecindad;
var partialGraph;
var partialGraph;
var otherGraph;
var Nodes = [];
var Nodes = [];
var Edges = [];
var nodeslength=0;
var labels = [];
var labels = [];
var numberOfDocs=0;
var numberOfNGrams=0;
......@@ -268,4 +270,3 @@ var RVUniformC = function(seed){
};
}
//unifCont = new RVUniformC(100000000)
function scanDataFolder(){
console.log('FUN t.DataScanner:scanDataFolder')
$.ajax({
type: 'GET',
url: 'php/DirScan_main.php',
//data: "type="+type+"&query="+jsonparams,
//contentType: "application/json",
//dataType: 'json',
success : function(data){
success : function(data){
console.log(data);
dataFolderTree=data;
},
error: function(){
error: function(){
console.log('Page Not found: updateLeftPanel_uni()');
}
});
}
function getGexfPath(v){
console.log('FUN t.DataScanner:getGexfPath')
gexfpath=(gexfDictReverse[v])?gexfDictReverse[v]:v;
return gexfpath;
}
function getGexfLegend(gexfPath){
console.log('FUN t.DataScanner:getGexfLegend')
legend=(gexfDict[gexfPath])?gexfDict[gexfPath]:gexfPath;
return legend;
}
function jsActionOnGexfSelector(gexfLegend){
console.log('FUN t.DataScanner:jsActionOnGexfSelector')
if(getGexfPath[gexfLegend])
window.location=window.location.origin+window.location.pathname+"?file="+encodeURIComponent(getGexfPath(gexfLegend));
else
......@@ -34,6 +38,7 @@ function jsActionOnGexfSelector(gexfLegend){
}
function listGexfs(){
console.log('FUN t.DataScanner:listGexfs')
divlen=$("#gexfs").length;
if(divlen>0) {
param = JSON.stringify(gexfDict);
......@@ -42,7 +47,7 @@ function listGexfs(){
url: 'php/listFiles.php',
//contentType: "application/json",
//dataType: 'json',
success : function(data){
success : function(data){
html="<select style='width:150px;' ";
javs='onchange="'+'jsActionOnGexfSelector(this.value);'+'"';
html+=javs;
......@@ -57,9 +62,9 @@ function listGexfs(){
html+="</select>";
$("#gexfs").html(html);
},
error: function(){
error: function(){
console.log("Page Not found.");
}
});
}
});
}
}
This diff is collapsed.
// Mathieu Jacomy @ Sciences Po Médialab & WebAtlas
var ForceAtlas2 = function(graph) {
console.log('FUN t.asyncFA2:ForceAtlas2')
var self = this;
this.graph = graph;
......@@ -31,6 +32,7 @@ var ForceAtlas2 = function(graph) {
// Runtime (the ForceAtlas2 itself)
this.init = function() {
console.log('FUN t.asyncFA2:init')
self.state = {step: 0, index: 0};
self.graph.nodes.forEach(function(n) {
n.fa2 = {
......@@ -46,10 +48,12 @@ var ForceAtlas2 = function(graph) {
}
this.go = function() {
console.log('FUN t.asyncFA2:go')
while (self.onebucle()) {}
}
this.onebucle = function() {
console.log('FUN t.asyncFA2:onebucle')
var graph = self.graph;
var nodes = graph.nodes;
var edges = graph.edges;
......@@ -233,7 +237,7 @@ var ForceAtlas2 = function(graph) {
totalSwinging += n.fa2.mass * swinging;
swingingSum += swinging;
promdxdy += (Math.abs(n.fa2.dx)+Math.abs(n.fa2.dy))/2; /**/
totalEffectiveTraction += n.fa2.mass *
0.5 *
Math.sqrt(
......@@ -242,15 +246,15 @@ var ForceAtlas2 = function(graph) {
);
}
});
self.p.totalSwinging = totalSwinging;
var convg= ((Math.pow(nodes.length,2))/promdxdy); /**/
var swingingVSnodes_length = swingingSum/nodes.length; /**/
// if(convg > swingingVSnodes_length){
// if(convg > swingingVSnodes_length){
// self.p.banderita=true;
// }
self.p.totalEffectiveTraction = totalEffectiveTraction;
// We want that swingingMovement < tolerance * convergenceMovement
......@@ -346,6 +350,7 @@ var ForceAtlas2 = function(graph) {
}
this.end = function() {
console.log('FUN t.asyncFA2:end')
this.graph.nodes.forEach(function(n) {
n.fa2 = null;
});
......@@ -353,6 +358,7 @@ var ForceAtlas2 = function(graph) {
// Auto Settings
this.setAutoSettings = function() {
console.log('FUN t.asyncFA2:setAutoSettings')
var graph = this.graph;
// Tuning
......@@ -833,6 +839,7 @@ var ForceAtlas2 = function(graph) {
var updateMassAndGeometry = function() {
console.log('FUN t.asyncFA2:updateMassAndGeometry')
if (this.nodes.length > 1) {
// Compute Mass
var mass = 0;
......@@ -878,13 +885,14 @@ var Region = function(nodes, depth) {
massCenterX: 0,
massCenterY: 0
};
console.log("updating mass and geometry");
this.updateMassAndGeometry();
}
var buildSubRegions = function() {
console.log('FUN t.asyncFA2:buildSubRegions')
if (this.nodes.length > 1) {
var leftNodes = [];
var rightNodes = [];
......@@ -936,6 +944,7 @@ var buildSubRegions = function() {
};
var applyForce = function(n, Force, theta) {
console.log('FUN t.asyncFA2:applyForce')
if (this.nodes.length < 2) {
var regionNode = this.nodes[0];
Force.apply_nn(n, regionNode);
......@@ -958,6 +967,7 @@ var applyForce = function(n, Force, theta) {
};
var startForceAtlas2 = function(graph,limit_it) {
console.log('FUN t.asyncFA2:startForceAtlas2')
// pr("inside FA2")
//// if(!this.forceatlas2) {
// pr(graph);
......@@ -981,7 +991,7 @@ var startForceAtlas2 = function(graph,limit_it) {
forceatlas2 = new ForceAtlas2(graph);
forceatlas2.setAutoSettings();
forceatlas2.init();
count=0;
flag=false;
while(true){
......@@ -994,13 +1004,13 @@ var startForceAtlas2 = function(graph,limit_it) {
}
count++;
if(flag||count>limit_it) break;
}
}
// pr(forceatlas2.graph.nodes[0].x)
// pr(forceatlas2.graph.nodes[0].y)
// console.log("\titerations: "+count)
result={
"nodes":forceatlas2.graph.nodes,
"it":count
"it":count
}
return result;
};
......@@ -1016,5 +1026,5 @@ self.addEventListener("message", function(e) {
"nodes":result.nodes,
"it":result.it
});
}, false);
\ No newline at end of file
}, false);
This diff is collapsed.
......@@ -10,6 +10,7 @@ function print(msg) {
//to general utils
function getClientTime(){
console.log('FUN t.globalUtils:getClientTime')
var totalSec = new Date().getTime() / 1000;
var d = new Date();
var hours = d.getHours();
......@@ -20,11 +21,13 @@ function getClientTime(){
}
function compareNumbers(a, b) {
console.log('FUN t.globalUtils:compareNumbers')
return a - b;
}
//python range(a,b) | range(a)
function calc_range(begin, end) {
console.log('FUN t.globalUtils:calc_range')
if (typeof end === "undefined") {
end = begin; begin = 0;
}
......@@ -38,6 +41,7 @@ function calc_range(begin, end) {
//to general utils (not used btw)
function cloneObject(source) {
console.log('FUN t.globalUtils:cloneObject')
for (i in source) {
if (typeof source[i] == 'source') {
this[i] = new cloneObject(source[i]);
......@@ -49,14 +53,16 @@ function cloneObject(source) {
}
function isUndef(variable){
// console.log('FUN t.globalUtils:isUndef')
if(typeof(variable)==="undefined") return true;
else return false;
}
$.fn.toggleClick = function(){
console.log('FUN t.globalUtils:toggleClick')
methods = arguments, // store the passed arguments for future reference
count = methods.length; // cache the number of methods
count = methods.length; // cache the number of methods
//use return this to maintain jQuery chainability
return this.each(function(i, item){
......@@ -71,6 +77,7 @@ $.fn.toggleClick = function(){
getUrlParam = (function () {
console.log('FUN t.globalUtils:getUrlParam')
var get = {
push:function (key,value){
var cur = this[key];
......@@ -101,12 +108,13 @@ getUrlParam = (function () {
function ArraySortByValue(array, sortFunc){
console.log('FUN t.globalUtils:ArraySortByValue')
var tmp = [];
oposMAX=0;
for (var k in array) {
if (array.hasOwnProperty(k)) {
tmp.push({
key: k,
key: k,
value: array[k]
});
if((array[k]) > oposMAX) oposMAX= array[k];
......@@ -115,18 +123,19 @@ function ArraySortByValue(array, sortFunc){
tmp.sort(function(o1, o2) {
return sortFunc(o1.value, o2.value);
});
return tmp;
});
return tmp;
}
function ArraySortByKey(array, sortFunc){
console.log('FUN t.globalUtils:ArraySortByKey')
var tmp = [];
for (var k in array) {
if (array.hasOwnProperty(k)) {
tmp.push({
key: k,
key: k,
value: array[k]
});
}
......@@ -134,12 +143,13 @@ function ArraySortByKey(array, sortFunc){
tmp.sort(function(o1, o2) {
return sortFunc(o1.key, o2.key);
});
return tmp;
});
return tmp;
}
function is_empty(obj) {
console.log('FUN t.globalUtils:is_empty')
// Assume if it has a length property with a non-zero value
// that that property is correct.
if (obj.length && obj.length > 0) return false;
......@@ -153,12 +163,14 @@ function is_empty(obj) {
function getByID(elem) {
console.log('FUN t.globalUtils:getByID')
return document.getElementById(elem);
}
function hex2rga(sent_hex) {
// console.log('FUN t.globalUtils:hex2rga')
result = []
hex = ( sent_hex.charAt(0) === "#" ? sent_hex.substr(1) : sent_hex );
// check if 6 letters are provided
......@@ -173,6 +185,7 @@ function hex2rga(sent_hex) {
}
function calculateFull(hex) {
// console.log('FUN t.globalUtils:calculateFull')
var r = parseInt(hex.substring(0, 2), 16);
var g = parseInt(hex.substring(2, 4), 16);
var b = parseInt(hex.substring(4, 6), 16);
......@@ -182,6 +195,7 @@ function calculateFull(hex) {
// function for calculating 3 letters hex value
function calculatePartial(hex) {
console.log('FUN t.globalUtils:calculatePartial')
var r = parseInt(hex.substring(0, 1) + hex.substring(0, 1), 16);
var g = parseInt(hex.substring(1, 2) + hex.substring(1, 2), 16);
var b = parseInt(hex.substring(2, 3) + hex.substring(2, 3), 16);
......@@ -189,27 +203,31 @@ function calculatePartial(hex) {
}
function componentToHex(c) {
console.log('FUN t.globalUtils:componentToHex')
var hex = c.toString(16);
return hex.length == 1 ? "0" + hex : hex;
}
function rgbToHex(r, g, b) {
console.log('FUN t.globalUtils:rgbToHex')
return "#" + componentToHex(r) + componentToHex(g) + componentToHex(b);
}
/**
* function to load a given css file
*/
* function to load a given css file
*/
loadCSS = function(href) {
console.log('FUN t.globalUtils:loadCSS')
var cssLink = $("<link rel='stylesheet' type='text/css' href='"+href+"'>");
$("head").append(cssLink);
$("head").append(cssLink);
};
/**
* function to load a given js file
*/
* function to load a given js file
*/
loadJS = function(src) {
console.log('FUN t.globalUtils:loadJS')
var jsLink = $("<script type='text/javascript' src='"+src+"'>");
$("head").append(jsLink);
};
\ No newline at end of file
$("head").append(jsLink);
};
/*
/*
Author: Corneliu S. (github.com/upphiminn)
This is a javascript implementation of the Louvain
This is a javascript implementation of the Louvain
community detection algorithm (http://arxiv.org/abs/0803.0476)
Based on https://bitbucket.org/taynaud/python-louvain/overview
Based on https://bitbucket.org/taynaud/python-louvain/overview
*/
(function(){
jLouvain = function(){
console.log('FUN t.jLouvain:jLouvain')
//Constants
var __PASS_MAX = -1
var __MIN = 0.0000001
......@@ -48,16 +49,16 @@ Based on https://bitbucket.org/taynaud/python-louvain/overview
});
return weight;
};
function get_neighbours_of_node(graph, node){
if(typeof graph._assoc_mat[node] == 'undefined')
return [];
var neighbours = Object.keys(graph._assoc_mat[node]);
var neighbours = Object.keys(graph._assoc_mat[node]);
return neighbours;
}
function get_edge_weight(graph, node1, node2){
return graph._assoc_mat[node1] ? graph._assoc_mat[node1][node2] : undefined;
}
......@@ -113,8 +114,9 @@ Based on https://bitbucket.org/taynaud/python-louvain/overview
return temp;
}
//Core-Algorithm Related
//Core-Algorithm Related
function init_status(graph, status, part){
console.log('FUN t.jLouvain:init_status')
status['nodes_to_com'] = {};
status['total_weight'] = 0;
status['internals'] = {};
......@@ -184,13 +186,13 @@ Based on https://bitbucket.org/taynaud/python-louvain/overview
var weights = {};
var neighboorhood = get_neighbours_of_node(graph, node);//make iterable;
neighboorhood.forEach(function(neighbour, i){
if(neighbour != node){
var weight = graph._assoc_mat[node][neighbour] || 1;
var weight = graph._assoc_mat[node][neighbour] || 1;
var neighbourcom = status.nodes_to_com[neighbour];
weights[neighbourcom] = (weights[neighbourcom] || 0) + weight;
}
}
});
return weights;
......@@ -212,7 +214,7 @@ Based on https://bitbucket.org/taynaud/python-louvain/overview
function __renumber(dict){
var count = 0;
var ret = clone(dict); //deep copy :)
var ret = clone(dict); //deep copy :)
var new_values = {};
var dict_keys = Object.keys(dict);
dict_keys.forEach(function(key){
......@@ -255,7 +257,7 @@ Based on https://bitbucket.org/taynaud/python-louvain/overview
best_increase = incr;
best_com = com;
}
});
});
__insert(node, best_com, neigh_communities[best_com] || 0, status);
......@@ -269,6 +271,7 @@ Based on https://bitbucket.org/taynaud/python-louvain/overview
}
function induced_graph(partition, graph){
console.log('FUN t.jLouvain:induced_graph')
var ret = {nodes:[], edges:[], _assoc_mat: {}};
var w_prec, weight;
//add nodes from partition values
......@@ -278,7 +281,7 @@ Based on https://bitbucket.org/taynaud/python-louvain/overview
weight = edge.weight || 1;
var com1 = partition[edge.source];
var com2 = partition[edge.target];
w_prec = (get_edge_weight(ret, com1, com2) || 0);
w_prec = (get_edge_weight(ret, com1, com2) || 0);
var new_weight = (w_prec + weight);
add_edge_to_graph(ret, {'source': com1, 'target': com2, 'weight': new_weight});
});
......@@ -286,6 +289,7 @@ Based on https://bitbucket.org/taynaud/python-louvain/overview
}
function partition_at_level(dendogram, level){
console.log('FUN t.jLouvain:partition_at_level')
var partition = clone(dendogram[0]);
for(var i = 1; i < level + 1; i++ )
Object.keys(partition).forEach(function(key,j){
......@@ -298,7 +302,8 @@ Based on https://bitbucket.org/taynaud/python-louvain/overview
function generate_dendogram(graph, part_init){
console.log('FUN t.jLouvain:generate_dendogram')
if(graph.edges.length == 0){
var part = {};
graph.nodes.forEach(function(node,i){
......@@ -326,14 +331,14 @@ Based on https://bitbucket.org/taynaud/python-louvain/overview
break;
partition = __renumber(status.nodes_to_com);
status_list.push(partition);
status_list.push(partition);
mod = new_mod;
current_graph = induced_graph(partition, current_graph);
init_status(current_graph, status);
}
return status_list;
return status_list;
}
var core = function(){
......@@ -361,7 +366,7 @@ Based on https://bitbucket.org/taynaud/python-louvain/overview
'_assoc_mat': assoc_mat };
}
return core;
};
core.partition_init = function(prttn){
......@@ -373,4 +378,4 @@ Based on https://bitbucket.org/taynaud/python-louvain/overview
return core;
}
})();
\ No newline at end of file
})();
......@@ -38,18 +38,18 @@ var AjaxSync = (function(TYPE, URL, DATA, CT , DT) {
header = (header)?"json":"gexf";
Result = { "OK":true , "format":header , "data":data };
},
error: function(exception) {
error: function(exception) {
Result = { "OK":false , "format":false , "data":exception.status };
}
});
return Result;
}).index();
var urlfile_override = (isUndef(getUrlParam.file))?false:true;
var files_selector = ""
if(urlfile_override)
if(urlfile_override)
mainfile.unshift( getUrlParam.file );
unique_mainfile = mainfile.filter(function(item, pos) {
......@@ -79,13 +79,16 @@ $.ajax({
Result = { "OK":true , "format":header , "data":data };
MainFunction( Result )
},
error: function(exception) {
error: function(exception) {
Result = { "OK":false , "format":false , "data":exception.status };
MainFunction( Result )
}
});
function MainFunction( RES ) {
console.log(' ------------')
console.log('FUN t.main:MainFunction')
console.log(' ------------')
if(!RES["OK"]) {
alert("error: "+RES["data"])
return false;
......@@ -94,7 +97,7 @@ function MainFunction( RES ) {
var fileparam;// = { db|api.json , somefile.json|gexf }
var the_data = RES["data"];
if(file=="db.json") {
getAdditionalInfo = true;
......@@ -126,7 +129,7 @@ function MainFunction( RES ) {
pr(the_data.length)
pr(fileparam)
pr("\n============================\n")
}
}
if (file=="api.json") {
fileparam = file;
......@@ -136,7 +139,7 @@ function MainFunction( RES ) {
if ( file!="db.json" && file!="api.json" )
fileparam = RES["format"];
start = new ParseCustom( fileparam , the_data );
categories = start.scanFile(); //user should choose the order of categories
pr("Categories: ")
......@@ -161,11 +164,11 @@ function MainFunction( RES ) {
for(var i in categories) {
Filters[i] = {}
Filters[i]["#slidercat"+i+"edgesweight"] = true;
}
Filters[i]["#slidercat"+i+"edgesweight"] = true;
}
// [ Initiating Sigma-Canvas ]
var twjs_ = new TinaWebJS('#sigma-example');
var twjs_ = new TinaWebJS('#sigma-example');
print( twjs_.AdjustSigmaCanvas() );
$( window ).resize(function() { print(twjs_.AdjustSigmaCanvas()) });
// [ / Initiating Sigma-Canvas ]
......@@ -217,7 +220,7 @@ function MainFunction( RES ) {
var past = partialGraph.states.slice(-2)[0] // avant Last
print("previous level: "+past.level)
print("new level: "+present.level)
print(" % % % % % % % % % % ")
print("")
......@@ -245,7 +248,7 @@ function MainFunction( RES ) {
$("#category0").hide();
$("#category1").show();
if($("#slidercat1nodesweight").html()=="")
if($("#slidercat1nodesweight").html()=="")
NodeWeightFilter( this.categories , "#slidercat1nodesweight" , this.categories[1], "type" ,"size");
if($("#slidercat1edgesweight").html()=="")
......@@ -263,7 +266,7 @@ function MainFunction( RES ) {
$("#category0").show();
$("#category1").hide();
if($("#slidercat0nodesweight").html()=="")
if($("#slidercat0nodesweight").html()=="")
NodeWeightFilter( this.categories , "#slidercat0nodesweight" , this.categories[0], "type" ,"size");
if($("#slidercat0edgesweight").html()=="")
......@@ -275,7 +278,7 @@ function MainFunction( RES ) {
}
set_ClustersLegend ( "clust_default" )
} else {
//finished
$("#slidercat1nodessize").freshslider({
step:1,
......@@ -295,7 +298,7 @@ function MainFunction( RES ) {
partialGraph.draw();
});
}
});
});
}
......@@ -311,7 +314,7 @@ function MainFunction( RES ) {
}
}).index();
partialGraph.zoomTo(partialGraph._core.width / 2, partialGraph._core.height / 2, 0.8).draw();
// partialGraph.zoomTo(partialGraph._core.width / 2, partialGraph._core.height / 2, 0.8).draw();
// fa2enabled=true; //partialGraph.zoomTo(partialGraph._core.width / 2, partialGraph._core.height / 2, 0.8).draw();
// $.doTimeout(1,function(){
......@@ -337,18 +340,16 @@ function MainFunction( RES ) {
$("footer").remove()
console.log( "FIN" )
fa2enabled=true; partialGraph.startForceAtlas2();
fa2enabled=true; partialGraph.startForceAtlas2();
setTimeout(function() {
console.log( "LALALALALALLA" )
console.log( "hello" )
partialGraph.stopForceAtlas2();
}, fa2seconds*1000);
}
console.log("finish")
This diff is collapsed.
This diff is collapsed.
function draw1Circle(ctx , x , y , color) {
function draw1Circle(ctx , x , y , color) {
console.log('FUN t.minimap:draw1Circle')
ctx.strokeStyle = '#000';
ctx.lineWidth = 1;
ctx.fillStyle = color;
......@@ -14,6 +15,7 @@ function draw1Circle(ctx , x , y , color) {
function trackMouse() {
console.log('FUN t.minimap:trackMouse')
if(!shift_key) {
// $.doTimeout(300,function (){
var ctx = partialGraph._core.domElements.mouse.getContext('2d');
......@@ -22,13 +24,13 @@ function trackMouse() {
x = partialGraph._core.mousecaptor.mouseX;
y = partialGraph._core.mousecaptor.mouseY;
ctx.strokeStyle = '#000';
ctx.lineWidth = 1;
ctx.fillStyle = "#71C3FF";
ctx.globalAlpha = 0.5;
ctx.globalAlpha = 0.5;
ctx.beginPath();
if(partialGraph._core.mousecaptor.ratio>showLabelsIfZoom){
for(var i in partialGraph._core.graph.nodesIndex){
n=partialGraph._core.graph.nodesIndex[i];
......@@ -63,7 +65,7 @@ function trackMouse() {
if(partialGraph.forceatlas2 && partialGraph.forceatlas2.count<=1) {
partialGraph.draw(2,2,2);
}
}
}
ctx.arc(x, y, cursor_size, 0, Math.PI * 2, true);
//ctx.arc(partialGraph._core.width/2, partialGraph._core.height/2, 4, 0, 2 * Math.PI, true);/*todel*/
ctx.closePath();
......@@ -74,6 +76,7 @@ function trackMouse() {
};
function changeGraphPosition(evt, echelle) {
console.log('FUN t.minimap:changeGraphPosition')
document.body.style.cursor = "move";
var _coord = {
x : evt.pageX,
......@@ -86,22 +89,22 @@ function changeGraphPosition(evt, echelle) {
}
function onOverviewMove(evt) {
console.log("onOverViewMove");
console.log('FUN t.minimap:onOverviewMove')
/*
pageX: 1247 pageY: 216
screenX: 1188 screenY: 307
pageX: 1444 pageY: 216
screenX: 1365 screenY: 307
*/
if (partialGraph.dragOn) {
changeGraphPosition(evt,-overviewScale);
}
}
function startMove(evt){
console.log("startMove");
console.log('FUN t.minimap:startMove')
evt.preventDefault();
partialGraph.dragOn = true;
partialGraph.lastMouse = {
......@@ -112,13 +115,14 @@ function startMove(evt){
}
function endMove(evt){
console.log("endMove");
console.log('FUN t.minimap:endMove')
document.body.style.cursor = "default";
partialGraph.dragOn = false;
partialGraph.mouseHasMoved = false;
}
function onGraphScroll(evt, delta) {
console.log('FUN t.minimap:onGraphScroll')
$("#zoomSlider").slider("value",partialGraph.position().ratio);
// partialGraph.totalScroll += delta;
// if (Math.abs(partialGraph.totalScroll) >= 1) {
......@@ -130,13 +134,13 @@ function onGraphScroll(evt, delta) {
// //_off = $(this).offset(),
// //_deltaX = evt.pageX - _el.width() / 2 - _off.left,
// //_deltaY = evt.pageY - _el.height() / 2 - _off.top;
// var
// var
// mx=evt.offsetX,
// my=evt.offsetY;
// partialGraph.centreX=mx*((partialGraph._core.width-1)/(overviewWidth)),
// partialGraph.centreY=my*((partialGraph._core.height-1)/(overviewHeight));
// // console.log("mx: "+mx+" - my: "+ my);
// partialGraph.centreY=my*((partialGraph._core.height-1)/(overviewHeight));
// // console.log("mx: "+mx+" - my: "+ my);
// // console.log("cx: "+cx+" - cy: "+ cy);
// // partialGraph.centreX =cx;
// // partialGraph.centreY =cy;
......@@ -155,13 +159,13 @@ function onGraphScroll(evt, delta) {
// //_off = $(this).offset(),
// //_deltaX = evt.pageX - _el.width() / 2 - _off.left,
// //_deltaY = evt.pageY - _el.height() / 2 - _off.top;
// var
// var
// mx=evt.offsetX,
// my=evt.offsetY;
// partialGraph.centreX=mx*((partialGraph._core.width-1)/(overviewWidth)),
// partialGraph.centreY=my*((partialGraph._core.height-1)/(overviewHeight));
// // console.log("mx: "+mx+" - my: "+ my);
// partialGraph.centreY=my*((partialGraph._core.height-1)/(overviewHeight));
// // console.log("mx: "+mx+" - my: "+ my);
// // console.log("cx: "+cx+" - cy: "+ cy);
// // partialGraph.centreX =cx;
// // partialGraph.centreY =cy;
......@@ -174,9 +178,10 @@ function onGraphScroll(evt, delta) {
}
function initializeMap() {
console.log('FUN t.minimap:initializeMap')
clearInterval(partialGraph.timeRefresh);
partialGraph.oldParams = {};
if(minimap){
$("#overviewzone").css({
width : overviewWidth + "px",
......@@ -191,7 +196,8 @@ function initializeMap() {
}
function updateMap(){
if(minimap){
console.log('FUN t.minimap:updateMap')
if(minimap){
partialGraph.imageMini="";
partialGraph.ctxMini="";
partialGraph.ctxMini = document.getElementById('overview').getContext('2d');
......@@ -205,21 +211,22 @@ function updateMap(){
aleat = Math.random() * numPosibilidades;
partialGraph.ctxMini.arc(((n.displayX/1.2)-200)*0.25 , ((n.displayY/1.2)+110)*0.25 , (0.9 + aleat)*0.25+1 , 0 , Math.PI*2 , true);
// //console.log(n.x*1000 +" * 0.25"+" _ "+ n.y*1000 +" * 0.25"+" _ "+ (0.9 + aleat) +" * 0.25 + 1");
//
//
partialGraph.ctxMini.closePath();
partialGraph.ctxMini.fill();
}
//
//
});
partialGraph.imageMini = partialGraph.ctxMini.getImageData(0, 0, overviewWidth, overviewHeight);
}
}
function traceMap() {
console.log('FUN t.minimap:traceMap')
//pr("\ttracingmap");
partialGraph.echelleGenerale = Math.pow( Math.SQRT2, partialGraph.position().ratio );
partialGraph.ctxMini.putImageData(partialGraph.imageMini, 0, 0);
var _r = 0.25 / partialGraph.echelleGenerale,
cx = partialGraph.centreX,
cy = partialGraph.centreY,
......@@ -235,11 +242,12 @@ function traceMap() {
}
function startMiniMap(){
console.log('FUN t.minimap:startMiniMap')
if(minimap){
partialGraph.ctxMini = document.getElementById('overview').getContext('2d');
partialGraph.ctxMini = document.getElementById('overview').getContext('2d');
partialGraph.ctxMini.clearRect(0, 0, overviewWidth, overviewHeight);
partialGraph.totalScroll=0;
partialGraph.totalScroll=0;
partialGraph.centreX = partialGraph._core.width/2;
partialGraph.centreY = partialGraph._core.heigth/2;
}
}
\ No newline at end of file
}
......@@ -6,6 +6,7 @@ var first_time=true;
sigma.forceatlas2 = sigma.forceatlas2 || {};
sigma.forceatlas2.ForceAtlas2 = function(graph , V , E) {
console.log('FUN t.sigma.forceatlas2:ForceAtlas2')
sigma.classes.Cascade.call(this);
var self = this;
this.graph = graph;
......@@ -149,7 +150,7 @@ sigma.forceatlas2.ForceAtlas2 = function(graph , V , E) {
}
} else {
if( self.firstit ) {
n.x = self.Ox + self.R*Math.cos(Math.PI*self.stepDeg*mult);
n.y = self.Oy + self.R*Math.sin(Math.PI*self.stepDeg*mult);
......@@ -158,7 +159,7 @@ sigma.forceatlas2.ForceAtlas2 = function(graph , V , E) {
}
}
});
self.firstit = false ;
......@@ -274,21 +275,21 @@ sigma.forceatlas2.ForceAtlas2 = function(graph , V , E) {
if (self.p.edgeWeightInfluence == 0) {
while (i < edges.length && i < self.state.index + cInt) {
var e = edges[i++];
if(!e.hidden) {
if(!e.hidden) {
Attraction.apply_nn(e.source, e.target, 1);
}
}
} else if (self.p.edgeWeightInfluence == 1) {
while (i < edges.length && i < self.state.index + cInt) {
var e = edges[i++];
if(!e.hidden) {
if(!e.hidden) {
Attraction.apply_nn(e.source, e.target, e.weight || 1);
}
}
} else {
while (i < edges.length && i < self.state.index + cInt) {
var e = edges[i++];
if(!e.hidden) {
if(!e.hidden) {
Attraction.apply_nn(
e.source, e.target,
Math.pow(e.weight || 1, self.p.edgeWeightInfluence)
......@@ -325,7 +326,7 @@ sigma.forceatlas2.ForceAtlas2 = function(graph , V , E) {
totalSwinging += n.fa2.mass * swinging;
swingingSum += swinging;
promdxdy += (Math.abs(n.fa2.dx)+Math.abs(n.fa2.dy))/2; /**/
totalEffectiveTraction += n.fa2.mass *
0.5 *
Math.sqrt(
......@@ -334,16 +335,16 @@ sigma.forceatlas2.ForceAtlas2 = function(graph , V , E) {
);
}
});
self.p.totalSwinging = totalSwinging;
var convg= ((Math.pow(nodes.length,2))/promdxdy); /**/
var swingingVSnodes_length = swingingSum/nodes.length; /**/
if(stopcriteria && (convg > swingingVSnodes_length)){
if(stopcriteria && (convg > swingingVSnodes_length)){
pr("i've applied the stopcriteria: "+self.count)
partialGraph.stopForceAtlas2();
partialGraph.stopForceAtlas2();
}
self.p.totalEffectiveTraction = totalEffectiveTraction;
// We want that swingingMovement < tolerance * convergenceMovement
......@@ -362,7 +363,7 @@ sigma.forceatlas2.ForceAtlas2 = function(graph , V , E) {
// Save old coordinates
nodes.forEach(function(n) {
if(!n.hidden && n.degree>0) {
if(!n.hidden && n.degree>0) {
n.old_x = +n.x;
n.old_y = +n.y;
}
......@@ -403,7 +404,7 @@ sigma.forceatlas2.ForceAtlas2 = function(graph , V , E) {
}
}
if(self.isolated>0 && self.count%50 == 0) {
nodes.forEach(function(n) {
if(n.degree>0) {
......@@ -982,6 +983,7 @@ sigma.forceatlas2.ForceAtlas2 = function(graph , V , E) {
// The Region class, as used by the Barnes Hut optimization
sigma.forceatlas2.Region = function(nodes, depth) {
console.log('FUN t.sigma.forceatlas2:Region')
sigma.classes.Cascade.call(this);
this.depthLimit = 20;
this.size = 0;
......@@ -994,11 +996,12 @@ sigma.forceatlas2.Region = function(nodes, depth) {
massCenterX: 0,
massCenterY: 0
};
this.updateMassAndGeometry();
}
sigma.forceatlas2.Region.prototype.updateMassAndGeometry = function() {
console.log('FUN t.sigma.forceatlas2:updateMassAndGeometry')
if (this.nodes.length > 1) {
// Compute Mass
var mass = 0;
......@@ -1034,6 +1037,7 @@ sigma.forceatlas2.Region.prototype.updateMassAndGeometry = function() {
};
sigma.forceatlas2.Region.prototype.buildSubRegions = function() {
console.log('FUN t.sigma.forceatlas2:buildSubRegions')
if (this.nodes.length > 1) {
var leftNodes = [];
var rightNodes = [];
......@@ -1085,6 +1089,7 @@ sigma.forceatlas2.Region.prototype.buildSubRegions = function() {
};
sigma.forceatlas2.Region.prototype.applyForce = function(n, Force, theta) {
console.log('FUN t.sigma.forceatlas2:applyForce')
if (this.nodes.length < 2) {
var regionNode = this.nodes[0];
Force.apply_nn(n, regionNode);
......@@ -1109,6 +1114,7 @@ sigma.forceatlas2.Region.prototype.applyForce = function(n, Force, theta) {
sigma.publicPrototype.startForceAtlas2 = function() {
console.log('FUN t.sigma.forceatlas2:applyForce')
//if(!this.forceatlas2) {
if(fa2enabled) {
......@@ -1130,7 +1136,7 @@ sigma.publicPrototype.startForceAtlas2 = function() {
if(isolatedBCauseFilter==ene) {
partialGraph.stopForceAtlas2();
return;
}
}
$("#overviewzone").hide();
......@@ -1148,11 +1154,12 @@ sigma.publicPrototype.startForceAtlas2 = function() {
return;
}
});
}
};
sigma.publicPrototype.stopForceAtlas2 = function() {
console.log('FUN t.sigma.forceatlas2:stopForceAtlas2')
var present = partialGraph.states.slice(-1)[0]
if(this.forceatlas2) {
if(this.forceatlas2.count) {
......
This diff is collapsed.
......@@ -2,16 +2,18 @@
SigmaUtils = function () {
console.log('FUN t.SigmaUtils:SigmaUtils:new')
this.nbCats = 0;
// input = GEXFstring
this.FillGraph = function( initialState , catDict , nodes, edges , graph ) {
console.log('FUN t.SigmaUtils:SigmaUtils:FillGraph')
print("Filling the graaaaph:")
print(catDict)
for(var i in nodes) {
var n = nodes[i];
if(initialState[catDict[n.type]]) {
var node = ({
id : n.id,
......@@ -24,7 +26,7 @@ SigmaUtils = function () {
})
if(n.shape) node.shape = n.shape;
// console.log(node)
if(Number(n.id)==287) console.log("coordinates of node 287: ( "+n.x+" , "+n.y+" ) ")
graph.addNode( n.id , node);
updateSearchLabels( n.id , n.label , n.type);
......@@ -64,11 +66,12 @@ SigmaUtils = function () {
//for socialgraph
function showMeSomeLabels(N){
console.log('FUN t.sigmaUtils:showMeSomeLabels')
/*======= Show some labels at the beginning =======*/
minIn=50,
maxIn=0,
minOut=50,
maxOut=0;
maxOut=0;
partialGraph.iterNodes(function(n){
if(n.hidden==false){
if(parseInt(n.inDegree) < minIn) minIn= n.inDegree;
......@@ -105,28 +108,34 @@ function showMeSomeLabels(N){
}
function getnodes(){
console.log('FUN t.sigmaUtils:getnodes')
return partialGraph._core.graph.nodes;
}
function getnodesIndex(){
console.log('FUN t.sigmaUtils:getnodesIndex')
return partialGraph._core.graph.nodesIndex;
}
function getedges(){
console.log('FUN t.sigmaUtils:getedges')
return partialGraph._core.graph.edges;
}
function getedgesIndex(){
console.log('FUN t.sigmaUtils:getedgesIndex')
return partialGraph._core.graph.edgesIndex;
}
function getVisibleEdges() {
console.log('FUN t.sigmaUtils:getVisibleEdges')
return partialGraph._core.graph.edges.filter(function(e) {
return !e['hidden'];
});
}
function getVisibleNodes() {
console.log('FUN t.sigmaUtils:getVisibleNodes')
return partialGraph._core.graph.nodes.filter(function(n) {
return !n['hidden'];
});
......@@ -134,21 +143,25 @@ function getVisibleNodes() {
function getNodesByAtt(att) {
console.log('FUN t.sigmaUtils:getNodesByAtt')
return partialGraph._core.graph.nodes.filter(function(n) {
return n['type']==att;
});
}
function getn(id){
console.log('FUN t.sigmaUtils:getn')
return partialGraph._core.graph.nodesIndex[id];
}
function gete(id){
console.log('FUN t.sigmaUtils:gete')
return partialGraph._core.graph.edgesIndex[id];
}
function find(label){
console.log('FUN t.sigmaUtils:find')
var results=[];
var nds=getnodesIndex();
label=label.toLowerCase()
......@@ -158,13 +171,14 @@ function find(label){
var possiblematch=n.label.toLowerCase()
if (possiblematch.indexOf(label)!==-1) {
results.push(n);
}
}
}
}
return results;
}
function exactfind(label) {
console.log('FUN t.sigmaUtils:exactfind')
nds=getnodesIndex();
for(var i in nds){
n=nds[i];
......@@ -179,6 +193,7 @@ function exactfind(label) {
function getNodeLabels(elems){
console.log('FUN t.sigmaUtils:getNodeLabels')
var labelss=[]
for(var i in elems){
var id=(!isUndef(elems[i].key))?elems[i].key:i
......@@ -188,11 +203,13 @@ function getNodeLabels(elems){
}
function getNodeIDs(elems){
console.log('FUN t.sigmaUtils:getNodeIDs')
return Object.keys(elems)
}
function getSelections(){
function getSelections(){
console.log('FUN t.sigmaUtils:getSelections')
params=[];
for(var i in selections){
params.push(Nodes[i].label);
......@@ -203,7 +220,8 @@ function getSelections(){
//This receives an array not a dict!
// i added an excpt... why
function getNeighs(sels,arr) {
function getNeighs(sels,arr) {
console.log('FUN t.sigmaUtils:getNeighs')
neighDict={};
for(var i in sels) {
id = sels[i]
......@@ -214,14 +232,15 @@ function getNeighs(sels,arr) {
}
neighDict[id]=1;
}
}
}
return Object.keys(neighDict);
}//It returns an array not a dict!
//Using bipartiteN2D or bipartiteD2N
//This receives an array not a dict!
function getNeighs2(sels,arr){
function getNeighs2(sels,arr){
console.log('FUN t.sigmaUtils:getNeighs2')
neighDict={};
for(var i in sels) {
id = sels[i]
......@@ -232,12 +251,13 @@ function getNeighs2(sels,arr){
}
// neighDict[id]=1;
}
}
}
return Object.keys(neighDict);
}//It returns an array not a dict!
//to general utils
function getArrSubkeys(arr,id) {
console.log('FUN t.sigmaUtils:getArrSubkeys')
var result = []
for(var i in arr) {
result.push(arr[i][id])
......@@ -246,8 +266,9 @@ function getArrSubkeys(arr,id) {
}
function getCountries(){
console.log('FUN t.sigmaUtils:getCountries')
var nodes = getVisibleNodes();
var countries = {}
pr("in getCountries")
for(var i in nodes) {
......@@ -264,6 +285,7 @@ function getCountries(){
function getAcronyms() {
console.log('FUN t.sigmaUtils:getAcronyms')
var nodes = getVisibleNodes();
var acrs = {}
pr("in getAcronyms")
......@@ -280,7 +302,7 @@ function getAcronyms() {
function clustersBy(daclass , att2change ) {
console.log('FUN t.sigmaUtils:clustersBy')
cancelSelection(false);
var v_nodes = getVisibleNodes();
......@@ -400,7 +422,7 @@ function clustersBy(daclass , att2change ) {
function colorsBy(daclass, att2change ) {
console.log('FUN t.sigmaUtils:colorsBy')
pr("")
pr(" = = = = = = = = = = = = = = = = = ")
pr(" = = = = = = = = = = = = = = = = = ")
......@@ -449,7 +471,8 @@ function colorsBy(daclass, att2change ) {
//just for fun
function makeEdgeWeightUndef() {
console.log('FUN t.sigmaUtils:makeEdgeWeightUndef')
for(var e in partialGraph._core.graph.edges) {
partialGraph._core.graph.edges[e].weight=1;
}
}
\ 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