Correction d'affichage des voisins, pseudo-récursif.
This commit is contained in:
parent
45b5c17e72
commit
fd6cb9b73b
|
@ -10,27 +10,38 @@ var SOCIOGRAM = {
|
|||
nodes: null,
|
||||
edges: 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];
|
||||
var tmp = neighbors;
|
||||
|
||||
// Et on recupere les voisins des voisins
|
||||
for( subnodeId in tmp ){
|
||||
var subneighbors = this.allNeighborsIndex[subnodeId];
|
||||
for( subneighbor in subneighbors )
|
||||
neighbors[subneighbor] = subneighbors[subneighbor];
|
||||
// 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;
|
||||
})
|
||||
});
|
||||
|
||||
|
||||
/* (0.8) Initialisation de SIGMA */
|
||||
SOCIOGRAM.sigma = new sigma({renderer: { container:SOCIOGRAM.container, 'type': 'canvas' }});
|
||||
SOCIOGRAM.sigma = new sigma({renderer: { container: SOCIOGRAM.container, 'type': 'canvas' }});
|
||||
|
||||
|
||||
|
||||
|
@ -109,7 +120,7 @@ api.send(SOCIOGRAM.request, function(response){
|
|||
neighborNodes[nodeId] = e.data.node; // on ajoute le noeud clique
|
||||
|
||||
SOCIOGRAM.sigma.graph.nodes().forEach(function(n) {
|
||||
if( neighborNodes[n.id] ) n.color = n.originalColor;
|
||||
if( neighborNodes[n.id] != null ) n.color = n.originalColor;
|
||||
else n.color = '#eee';
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in New Issue