Classization du sociogramme (js/includes/sociogram.js) + gestion de l'include déjà chargé.

This commit is contained in:
xdrm-brackets 2016-04-18 14:56:49 +02:00
parent 61b0d515f1
commit ffdce0d6dd
7 changed files with 1154 additions and 421 deletions

1071
js/includes/sociogram.js Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1 +0,0 @@
var a = 'Hello World!';

View File

@ -106,14 +106,56 @@ Element.prototype.anim = function(className, timeout){
// INCLUSION D'UN SCRIPT JAVASCRIPT // INCLUSION D'UN SCRIPT JAVASCRIPT
function include(jsResource, callback){ var includes = [];
var tag = document.createElement('script'); var includeTags = [];
tag.type = 'text/javascript'; function include(jsResource, callback, action){ // action=true -> EXCLUSION, SINON -> INCLUSION
tag.src = jsResource; /* (0) On formatte les arguments */
jsResource = typeof jsResource === 'string' ? jsResource : null;
callback = typeof callback === 'function' ? callback : function(){ console.log('[x] '+jsResource+' loaded'); };
action = typeof action === 'boolean' ? action : false;
document.head.appendChild( tag ); // Si la ressource n'est pas donnée
if( jsResource == null ) return false;
tag.onload = callback;
/* (1) Gestion de l'inclusion */
if( !action ){
// Si le fichier est déja inclus, on lance le callback
if( includes.indexOf(jsResource) > -1 ){
callback();
return true;
}
// On crée l'élément dans le tag <head>
var tag = document.createElement('script');
tag.type = 'text/javascript';
tag.src = jsResource;
document.head.appendChild( tag );
// On ajoute la ressource et le tag à la liste
includes.push(jsResource);
includeTags.push(tag);
// On définit le callback
tag.onload = callback;
return true;
/* (2) Gestion de l'exclusion */
}else{
var index = includes.indexOf(jsResource);
// On vérifie que le fichier est déja inclus
if( index == -1 ) return false;
// On supprime l'élément
document.head.removeChild( includeTags[index] );
// On dé-indexe l'élément
includes.splice(index, 1);
includeTags.splice(index, 1);
return true;
}
} }

15
tags
View File

@ -3171,7 +3171,7 @@ id_user manager/repo/user.php /^ $id_user = $checkCreate->fetch();$/;" v
ignore_regexes sftp-config.json /^ "ignore_regexes": [$/;" f ignore_regexes sftp-config.json /^ "ignore_regexes": [$/;" f
import js/lib/sigma/plugins/sigma.plugins.filter.min.js /^(function(undefined){"use strict";function register(a,b,c){if(c!=undefined&&"string"!=typeof c)throw'The filter key "'+c.toString()+'" must be a string.';if(c!=undefined&&!c.length)throw"The filter key must be a non-empty string.";if("function"!=typeof a)throw'The predicate of key "'+c+'" must be a function.';if("undo"===c)throw'"undo" is a reserved key.';if(_keysIndex[c])throw'The filter "'+c+'" already exists.';c&&(_keysIndex[c]=!0),_chain.push({key:c,processor:a,predicate:b})}function unregister(a){_chain=_chain.filter(function(b){return!(b.key in a)});for(var b in a)delete _keysIndex[b]}function Filter(a){_s=a,_g=a.graph}function deepCopy(o){var copy=Object.create(null);for(var i in o)"object"==typeof o[i]&&null!==o[i]?copy[i]=deepCopy(o[i]):"function"==typeof o[i]&&null!==o[i]?eval(" copy[i] = "+o[i].toString()):copy[i]=o[i];return copy}function cloneChain(a){for(var b=a.slice(0),c=0,d=b.length;d>c;c++)b[c]=deepCopy(b[c]),"function"==typeof b[c].processor&&(b[c].processor="filter.processors."+b[c].processor.name);return b}if("undefined"==typeof sigma)throw"sigma is not declared";sigma.utils.pkg("sigma.plugins"),sigma.classes.graph.hasMethod("adjacentNodes")||sigma.classes.graph.addMethod("adjacentNodes",function(a){if("string"!=typeof a)throw"adjacentNodes: the node id must be a string.";var b,c=[];for(b in this.allNeighborsIndex[a])c.push(this.nodesIndex[b]);return c}),sigma.classes.graph.hasMethod("adjacentEdges")||sigma.classes.graph.addMethod("adjacentEdges",function(a){if("string"!=typeof a)throw"adjacentEdges: the node id must be a string.";var b,c,d=this.allNeighborsIndex[a],e=[];for(c in d)for(b in d[c])e.push(d[c][b]);return e});var _g=undefined,_s=undefined,_chain=[],_keysIndex=Object.create(null),Processors={};Processors.nodes=function(a){for(var b=_g.nodes(),c=b.length,d=_g.edges(),e=d.length;c--;)b[c].hidden=!a.call(_g,b[c])||b[c].hidden;for(;e--;)(_g.nodes(d[e].source).hidden||_g.nodes(d[e].target).hidden)&&(d[e].hidden=!0)},Processors.edges=function(a){for(var b=_g.edges(),c=b.length;c--;)b[c].hidden=!a.call(_g,b[c])||b[c].hidden},Processors.neighbors=function a(b){for(var c=_g.nodes(),d=c.length,e=_g.edges(),f=e.length,a=_g.adjacentNodes(b),g=a.length,h={};g--;)h[a[g].id]=!0;for(;d--;)c[d].id===b||c[d].id in h||(c[d].hidden=!0);for(;f--;)(_g.nodes(e[f].source).hidden||_g.nodes(e[f].target).hidden)&&(e[f].hidden=!0)},Filter.prototype.nodesBy=function(a,b){return register(Processors.nodes,a,b),this},Filter.prototype.edgesBy=function(a,b){return register(Processors.edges,a,b),this},Filter.prototype.neighborsOf=function(a,b){if("string"!=typeof a)throw'The node id "'+a.toString()+'" must be a string.';if(!a.length)throw"The node id must be a non-empty string.";return register(Processors.neighbors,a,b),this},Filter.prototype.apply=function(){for(var a=0,b=_chain.length;b>a;++a)_chain[a].processor(_chain[a].predicate);return _chain[0]&&"undo"===_chain[0].key&&_chain.shift(),_s.refresh(),this},Filter.prototype.undo=function(a){function b(){for(var a=_g.nodes(),b=a.length,c=_g.edges(),d=c.length;b--;)a[b].hidden=!1;for(;d--;)c[d].hidden=!1}var c=Object.create(null),d=arguments.length;if(1===d)if("[object Array]"===Object.prototype.toString.call(a))for(var e=0,f=a.length;f>e;e++)c[a[e]]=!0;else c[a]=!0;else if(d>1)for(var e=0;d>e;e++)c[arguments[e]]=!0;else this.clear();return unregister(c),_chain.unshift({key:"undo",processor:b}),this},Filter.prototype.clear=function(){return _chain.length=0,_keysIndex=Object.create(null),this},Filter.prototype.export=function(){var a=cloneChain(_chain);return a},Filter.prototype.import=function(a){if(a===undefined)throw"Wrong arguments.";if("[object Array]"!==Object.prototype.toString.call(a))throw'The chain" must be an array.';for(var b=cloneChain(a),c=0,d=b.length;d>c;c++){if(b[c].predicate===undefined||b[c].processor===undefined)throw"Wrong arguments.";if(b[c].key!=undefined&&"string"!=typeof b[c].key)throw'The filter key "'+b[c].key.toString()+'" must be a string.';if("function"!=typeof b[c].predicate)throw'The predicate of key "'+b[c].key+'" must be a function.';if("string"!=typeof b[c].processor)throw'The processor of key "'+b[c].key+'" must be a string.';switch(b[c].processor){case"filter.processors.nodes":b[c].processor=Processors.nodes;break;case"filter.processors.edges":b[c].processor=Processors.edges;break;case"filter.processors.neighbors":b[c].processor=Processors.neighbors;break;default:throw"Unknown processor "+b[c].processor}}return _chain=b,this};var filter=null;sigma.plugins.filter=function(a){return filter||(filter=new Filter(a)),filter}}).call(this);/;" m import js/lib/sigma/plugins/sigma.plugins.filter.min.js /^(function(undefined){"use strict";function register(a,b,c){if(c!=undefined&&"string"!=typeof c)throw'The filter key "'+c.toString()+'" must be a string.';if(c!=undefined&&!c.length)throw"The filter key must be a non-empty string.";if("function"!=typeof a)throw'The predicate of key "'+c+'" must be a function.';if("undo"===c)throw'"undo" is a reserved key.';if(_keysIndex[c])throw'The filter "'+c+'" already exists.';c&&(_keysIndex[c]=!0),_chain.push({key:c,processor:a,predicate:b})}function unregister(a){_chain=_chain.filter(function(b){return!(b.key in a)});for(var b in a)delete _keysIndex[b]}function Filter(a){_s=a,_g=a.graph}function deepCopy(o){var copy=Object.create(null);for(var i in o)"object"==typeof o[i]&&null!==o[i]?copy[i]=deepCopy(o[i]):"function"==typeof o[i]&&null!==o[i]?eval(" copy[i] = "+o[i].toString()):copy[i]=o[i];return copy}function cloneChain(a){for(var b=a.slice(0),c=0,d=b.length;d>c;c++)b[c]=deepCopy(b[c]),"function"==typeof b[c].processor&&(b[c].processor="filter.processors."+b[c].processor.name);return b}if("undefined"==typeof sigma)throw"sigma is not declared";sigma.utils.pkg("sigma.plugins"),sigma.classes.graph.hasMethod("adjacentNodes")||sigma.classes.graph.addMethod("adjacentNodes",function(a){if("string"!=typeof a)throw"adjacentNodes: the node id must be a string.";var b,c=[];for(b in this.allNeighborsIndex[a])c.push(this.nodesIndex[b]);return c}),sigma.classes.graph.hasMethod("adjacentEdges")||sigma.classes.graph.addMethod("adjacentEdges",function(a){if("string"!=typeof a)throw"adjacentEdges: the node id must be a string.";var b,c,d=this.allNeighborsIndex[a],e=[];for(c in d)for(b in d[c])e.push(d[c][b]);return e});var _g=undefined,_s=undefined,_chain=[],_keysIndex=Object.create(null),Processors={};Processors.nodes=function(a){for(var b=_g.nodes(),c=b.length,d=_g.edges(),e=d.length;c--;)b[c].hidden=!a.call(_g,b[c])||b[c].hidden;for(;e--;)(_g.nodes(d[e].source).hidden||_g.nodes(d[e].target).hidden)&&(d[e].hidden=!0)},Processors.edges=function(a){for(var b=_g.edges(),c=b.length;c--;)b[c].hidden=!a.call(_g,b[c])||b[c].hidden},Processors.neighbors=function a(b){for(var c=_g.nodes(),d=c.length,e=_g.edges(),f=e.length,a=_g.adjacentNodes(b),g=a.length,h={};g--;)h[a[g].id]=!0;for(;d--;)c[d].id===b||c[d].id in h||(c[d].hidden=!0);for(;f--;)(_g.nodes(e[f].source).hidden||_g.nodes(e[f].target).hidden)&&(e[f].hidden=!0)},Filter.prototype.nodesBy=function(a,b){return register(Processors.nodes,a,b),this},Filter.prototype.edgesBy=function(a,b){return register(Processors.edges,a,b),this},Filter.prototype.neighborsOf=function(a,b){if("string"!=typeof a)throw'The node id "'+a.toString()+'" must be a string.';if(!a.length)throw"The node id must be a non-empty string.";return register(Processors.neighbors,a,b),this},Filter.prototype.apply=function(){for(var a=0,b=_chain.length;b>a;++a)_chain[a].processor(_chain[a].predicate);return _chain[0]&&"undo"===_chain[0].key&&_chain.shift(),_s.refresh(),this},Filter.prototype.undo=function(a){function b(){for(var a=_g.nodes(),b=a.length,c=_g.edges(),d=c.length;b--;)a[b].hidden=!1;for(;d--;)c[d].hidden=!1}var c=Object.create(null),d=arguments.length;if(1===d)if("[object Array]"===Object.prototype.toString.call(a))for(var e=0,f=a.length;f>e;e++)c[a[e]]=!0;else c[a]=!0;else if(d>1)for(var e=0;d>e;e++)c[arguments[e]]=!0;else this.clear();return unregister(c),_chain.unshift({key:"undo",processor:b}),this},Filter.prototype.clear=function(){return _chain.length=0,_keysIndex=Object.create(null),this},Filter.prototype.export=function(){var a=cloneChain(_chain);return a},Filter.prototype.import=function(a){if(a===undefined)throw"Wrong arguments.";if("[object Array]"!==Object.prototype.toString.call(a))throw'The chain" must be an array.';for(var b=cloneChain(a),c=0,d=b.length;d>c;c++){if(b[c].predicate===undefined||b[c].processor===undefined)throw"Wrong arguments.";if(b[c].key!=undefined&&"string"!=typeof b[c].key)throw'The filter key "'+b[c].key.toString()+'" must be a string.';if("function"!=typeof b[c].predicate)throw'The predicate of key "'+b[c].key+'" must be a function.';if("string"!=typeof b[c].processor)throw'The processor of key "'+b[c].key+'" must be a string.';switch(b[c].processor){case"filter.processors.nodes":b[c].processor=Processors.nodes;break;case"filter.processors.edges":b[c].processor=Processors.edges;break;case"filter.processors.neighbors":b[c].processor=Processors.neighbors;break;default:throw"Unknown processor "+b[c].processor}}return _chain=b,this};var filter=null;sigma.plugins.filter=function(a){return filter||(filter=new Filter(a)),filter}}).call(this);/;" m
inArray js/lib/highcharts/js/highcharts.src.js /^ };$/;" f inArray js/lib/highcharts/js/highcharts.src.js /^ };$/;" f
include js/lib/reset.js /^function include(jsResource, callback){$/;" f include js/lib/reset.js /^function include(jsResource, callback, action){ \/\/ action=true -> EXCLUSION, SINON -> INCLUSION$/;" f
inflate manager/MenuManager.php /^ public function inflate(){$/;" f inflate manager/MenuManager.php /^ public function inflate(){$/;" f
input api/manifest.default.json /^ "input": {$/;" f input api/manifest.default.json /^ "input": {$/;" f
inputChecker js/lib/input-checker.js /^function inputChecker(){};$/;" c inputChecker js/lib/input-checker.js /^function inputChecker(){};$/;" c
@ -3903,6 +3903,19 @@ sigma.webgl.nodes.fast.initProgram js/lib/sigma/sigma.require.js /^ },$/;" m
sigma.webgl.nodes.fast.render js/lib/sigma/sigma.js /^ },$/;" m sigma.webgl.nodes.fast.render js/lib/sigma/sigma.js /^ },$/;" m
sigma.webgl.nodes.fast.render js/lib/sigma/sigma.require.js /^ },$/;" m sigma.webgl.nodes.fast.render js/lib/sigma/sigma.require.js /^ },$/;" m
sms automate.php /^ $sms = $answer->get('sms');$/;" v sms automate.php /^ $sms = $answer->get('sms');$/;" v
sociogramClass js/includes/sociogram.js /^function sociogramClass(container){$/;" c
sociogramClass.addEdges js/includes/sociogram.js /^sociogramClass.prototype.addEdges = function(){$/;" m
sociogramClass.addNodes js/includes/sociogram.js /^sociogramClass.prototype.addNodes = function(){$/;" m
sociogramClass.arrange js/includes/sociogram.js /^sociogramClass.prototype.arrange = function(nodeId, pos, alone){$/;" m
sociogramClass.bindings js/includes/sociogram.js /^sociogramClass.prototype.bindings.clickNode = function(thisPtr, e){$/;" m
sociogramClass.bindings js/includes/sociogram.js /^sociogramClass.prototype.bindings.clickStage = function(thisPtr, e){$/;" m
sociogramClass.extractEdgesFromResponse js/includes/sociogram.js /^sociogramClass.prototype.extractEdgesFromResponse = function(){$/;" m
sociogramClass.extractNodesFromResponse js/includes/sociogram.js /^sociogramClass.prototype.extractNodesFromResponse = function(){$/;" m
sociogramClass.load js/includes/sociogram.js /^sociogramClass.prototype.load = function(){$/;" m
sociogramClass.nodeAt js/includes/sociogram.js /^sociogramClass.prototype.nodeAt = function(x, y){$/;" m
sociogramClass.overload js/includes/sociogram.js /^sociogramClass.prototype.overload.nodeDirectNeighbors = function(nodeId){$/;" m
sociogramClass.overload js/includes/sociogram.js /^sociogramClass.prototype.overload.nodeNeighbors = function(nodeId){$/;" m
sociogramClass.overloadGraph js/includes/sociogram.js /^sociogramClass.prototype.overloadGraph = function(){$/;" m
sortedCALL manager/module/call_log.php /^ $sortedCALL = array();$/;" v sortedCALL manager/module/call_log.php /^ $sortedCALL = array();$/;" v
sortedMSMS manager/module/call_log.php /^ $sortedMSMS = array();$/;" v sortedMSMS manager/module/call_log.php /^ $sortedMSMS = array();$/;" v
st config/dispatcher-tree.json /^ "st" : "\/src\/static",$/;" f st config/dispatcher-tree.json /^ "st" : "\/src\/static",$/;" f

View File

@ -1,410 +1,18 @@
/* [1] Gestion du sociogramme /* [1] Gestion du sociogramme
=========================================================*/ =========================================================*/
var sociogram;
/* (1) On essaie de charger la classe du sociogramme */
var alreadyLoaded = include('/js/includes/sociogram.js', null, true);
/* (2) Si il est pas déja chargé, on initialise le sociogramme */
include('/js/includes/sociogram.js', function(){
// On ajoute les méthodes si c'est la première fois qu'on charge
if( !alreadyLoaded ) sociogramClass.prototype.overloadGraph();
// On charge le graphique
/* (0) On recupere les elements importants */ sociogram = new sociogramClass(document.getElementById('sociogram'));
var SOCIOGRAM = { sociogram.load();
container: document.getElementById('sociogram'),
sigma: null,
request: { path: 'charts/network_data' },
response: null,
nodes: null,
edges: null,
rad: 500,
nodeDistance: 100,
arrange: null
};
/* (0.5) Surcharge graph */
// On recupere les voisins d'un noeud
sigma.classes.graph.addMethod('nodeNeighbors', function(nodeId){
// On recupere les voisins du noeud courant
var neighbors = this.allNeighborsIndex[nodeId];
// Pile des voisins pour lesquels il faut chercher leurs voisins
var stack = [];
for( neighborId in neighbors ) stack.push(neighborId);
// Tant qu'il reste des voisins a trouver
while( stack.length > 0 ){
var subneighbors = this.allNeighborsIndex[stack[0]];
for( subId in subneighbors )
// Si le voisin est pas deja dans la liste/pile, on l'ajoute a la liste des voisins
if( neighbors[subId] == null ){
stack.push(subId); // On ajoute a la pile
neighbors[subId] = subneighbors[subId]; // On ajoute a la liste complete
}
stack.shift();
}
// On retourne le resultat
return neighbors;
});
// On recupere les voisins directs d'un noeud
sigma.classes.graph.addMethod('nodeDirectNeighbors', function(nodeId){
// On retourne les voisins directs
return this.allNeighborsIndex[nodeId];
});
/* (0.8) Initialisation de SIGMA */
SOCIOGRAM.sigma = new sigma({renderer: { container: SOCIOGRAM.container, 'type': 'canvas' }});
/* (1) On recupere les informations via l'API */
api.send(SOCIOGRAM.request, function(response){
console.log( response );
// Si erreur, on quitte
if( response.ModuleError != 0 ) return;
// Sinon on enregistre
SOCIOGRAM.response = response;
/* (2) Parametrage de SIGMA */
SOCIOGRAM.sigma.settings({
defaultNodeColor: '#348ed8',
defaultLabelSize: 14,
defaultLabelBGColor: "#ddd",
defaultHoverLabelBGColor: "#002147",
defaultLabelHoverColor: "#fff",
labelThreshold: 10,
defaultEdgeType: "line"
});
/* (3) On recupere la liste des noeuds */
SOCIOGRAM.nodes = [];
// Pour chaque alter
for( var i = 0 ; i < SOCIOGRAM.response.data.alter.length ; i++ ){
SOCIOGRAM.nodes.push({
'id': 'n-'+SOCIOGRAM.response.data.alter[i][0],
'label': SOCIOGRAM.response.data.alter[i][1],
'x': 0,
'y': 0,
'size': SOCIOGRAM.response.data.alter[i][2]
});
}
/* (4) On recupere la liste des liens */
SOCIOGRAM.edges = [];
for( var i = 0 ; i < SOCIOGRAM.response.data.inter.length ; i++ ){
SOCIOGRAM.edges.push({
'id': 'e-'+SOCIOGRAM.response.data.inter[i][0]+'-'+SOCIOGRAM.response.data.inter[i][1],
'source': 'n-'+SOCIOGRAM.response.data.inter[i][0],
'target': 'n-'+SOCIOGRAM.response.data.inter[i][1]
});
}
/* (5) On ajoute nos noeuds */
for( var i = 0 ; i < SOCIOGRAM.nodes.length ; i++)
SOCIOGRAM.sigma.graph.addNode(SOCIOGRAM.nodes[i]);
/* (6) On ajoute nos liens */
for( var i = 0 ; i < SOCIOGRAM.edges.length ; i++)
SOCIOGRAM.sigma.graph.addEdge(SOCIOGRAM.edges[i]);
/* (7) Gestion des interactions */
/* RETOURNE LA DISTANCE AVEC LE NOEUD LE PLUS PRES
*
* @x<float> Abscisse du point
* @y<float> Ordonnees du point
*
* @return distance<float> Retourne la distance du noeud le plus proche
*
*/
SOCIOGRAM.nodeAt = function(x, y){
var nodes = SOCIOGRAM.sigma.graph.nodes();
var minDistance = null;
for( nodeId in nodes ){
var distance = Math.sqrt( Math.pow(x-nodes[nodeId].x, 2) + Math.pow(y-nodes[nodeId].y, 2) );
if( minDistance == null || distance < minDistance )
minDistance = distance;
}
return minDistance;
};
/* POSITIONNE LES VOISINS AUTOUR DU NOEUD COURANT
*
* @nodeId<String> Id du noeud courant
* @pos<Object> Contient {x, y} position initiale, sinon la position actuelle du noeud
*
*/
SOCIOGRAM.arrange = function(nodeId, pos, alone){
var node = SOCIOGRAM.sigma.graph.nodes(nodeId);
// Si le noeud est deja place, on ne fais rien
if( node.x != 0 || node.y != 0 ) return;
var pos = (pos==null) ? {x: node.x, y: node.y} : pos; // On recupere la position
// Tant que le noeud est trop proche d'un autre, on l'eloigne
// UNIQUEMENT si alone n'est pas NULL
if( alone ){
while( SOCIOGRAM.nodeAt(pos.x, pos.y) < 2*SOCIOGRAM.nodeDistance ){
pos = {
x: pos.x + 2*SOCIOGRAM.nodeDistance*Math.cos(Math.random()*2*Math.PI),
y: pos.y + 2*SOCIOGRAM.nodeDistance*Math.sin(Math.random()*2*Math.PI)
};
}
}
// On recupere les voisins directs
var neighborsId = SOCIOGRAM.sigma.graph.nodeDirectNeighbors(nodeId);
var neighbors = {};
var neighborsCount = 0;
for( neighborId in neighborsId ){
neighbors[neighborId] = SOCIOGRAM.sigma.graph.nodes(neighborId);
neighborsCount++;
}
// On positionne le noeud
node.x = pos.x;
node.y = pos.y;
var angles = [];
// On positionne chaque voisin si c'est pas deja fait
for( neighborId in neighbors ){
var current = SOCIOGRAM.sigma.graph.nodes(neighborId);
// Si n'est pas deja positionne
if( current.x == 0 && current.y == 0 ){
// On cherche un angle tant qu'il est pas trop pres d'un deja pris
var angle, alreadyUsed = false;
do{
angle = Math.random()*2*Math.PI;
for( var i = 0 ; i < angles.length ; i++ )
if( Math.abs(angle-angles[i]) > Math.PI/10 ){
alreadyUsed = true;
break;
}
}while( alreadyUsed );
current.x = pos.x + SOCIOGRAM.nodeDistance*Math.cos(angle);
current.y = pos.y + SOCIOGRAM.nodeDistance*Math.sin(angle);
SOCIOGRAM.arrange(current.id);
}
}
SOCIOGRAM.sigma.refresh();
};
// On affiche que les voisins d'un noeud
SOCIOGRAM.sigma.bind('clickNode', function(e){
var nodeId = e.data.node.id;
// On recupere les voisins
var neighborNodes = SOCIOGRAM.sigma.graph.nodeNeighbors(nodeId);
neighborNodes[nodeId] = e.data.node; // on ajoute le noeud clique
SOCIOGRAM.sigma.graph.nodes().forEach(function(n) {
if( neighborNodes[n.id] != null ) n.color = n.originalColor;
else n.color = '#eee';
});
SOCIOGRAM.sigma.refresh();
});
// On affiche tous les noeuds quand on clique dans le vide
SOCIOGRAM.sigma.bind('clickStage', function(e){
SOCIOGRAM.sigma.graph.nodes().forEach(function(n){ n.color = n.originalColor; });
SOCIOGRAM.sigma.refresh();
});
/* (8) On affiche le graphique */
SOCIOGRAM.sigma.camera.ratio = 1.2;
// On repartit les noeuds
SOCIOGRAM.sigma.refresh();
SOCIOGRAM.sigma.graph.nodes().forEach(function(n){ SOCIOGRAM.arrange(n.id, null, true); });
SOCIOGRAM.sigma.refresh();
}); });
// var i,
// s,
// o,
// L = 10,
// N = 100,
// E = 500,
// g = {
// nodes: [],
// edges: []
// },
// step = 0;
// // Generate a random graph:
// for (i = 0; i < N; i++) {
// o = {
// id: 'n' + i,
// label: 'Node ' + i,
// circular_x: L * Math.cos(Math.PI * 2 * i / N - Math.PI / 2),
// circular_y: L * Math.sin(Math.PI * 2 * i / N - Math.PI / 2),
// circular_size: Math.random(),
// circular_color: '#' + (
// Math.floor(Math.random() * 16777215).toString(16) + '000000'
// ).substr(0, 6),
// grid_x: i % L,
// grid_y: Math.floor(i / L),
// grid_size: 1,
// grid_color: '#ccc'
// };
// ['x', 'y', 'size', 'color'].forEach(function(val) {
// o[val] = o['grid_' + val];
// });
// g.nodes.push(o);
// }
// for (i = 0; i < E; i++)
// g.edges.push({
// id: 'e' + i,
// source: 'n' + (Math.random() * N | 0),
// target: 'n' + (Math.random() * N | 0),
// });
// // Instantiate sigma:
// s = new sigma({
// graph: g,
// renderer: { container: document.getElementById('graph-container'), 'type': 'canvas' },
// settings: {
// animationsTime: 1000
// }
// });
// setInterval(function(){
// var prefix = ['grid_', 'circular_'][step = +!step];
// sigma.plugins.animate(
// s,
// {
// x: prefix + 'x',
// y: prefix + 'y',
// size: prefix + 'size',
// color: prefix + 'color'
// }
// );
// }, 10000);