78 lines
2.0 KiB
JavaScript
78 lines
2.0 KiB
JavaScript
/* [1] Gestion du sociogramme
|
|
=========================================================*/
|
|
/* (0) On recupere les elements importants */
|
|
var SOCIOGRAM = {
|
|
container: document.getElementById('sociogram'),
|
|
sigma: null,
|
|
|
|
request: { path: 'charts/network_data' },
|
|
response: null,
|
|
nodes: null,
|
|
edges: null
|
|
};
|
|
// Initialisation de SIGMA
|
|
SOCIOGRAM.sigma = new sigma(SOCIOGRAM.container);
|
|
|
|
/* (1) On recupere les informations via l'API */
|
|
api.send(SOCIOGRAM.request, function(response){
|
|
// Si erreur, on quitte
|
|
if( response.ModuleError != 0 ) return;
|
|
|
|
// Sinon on enregistre
|
|
SOCIOGRAM.response = response;
|
|
|
|
|
|
/* (2) Parametrage de SIGMA */
|
|
SOCIOGRAM.sigma.settings({
|
|
defaultNodeColor: '#ec5148'
|
|
});
|
|
|
|
|
|
/* (3) On recupere la liste des noeuds */
|
|
SOCIOGRAM.nodes = [];
|
|
|
|
// On calcule l'angle min
|
|
var ang = 2*Math.PI / SOCIOGRAM.response.data.alter.length;
|
|
|
|
// 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': 500+ 100*Math.cos(ang*i),
|
|
'y': 500+ 100*Math.sin(ang*i),
|
|
'size': SOCIOGRAM.response.data.alter[i][2]/10
|
|
});
|
|
}
|
|
|
|
|
|
|
|
/* (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 */
|
|
|
|
|
|
/* (8) On affiche le graphique */
|
|
SOCIOGRAM.sigma.camera.ratio = 2;
|
|
SOCIOGRAM.sigma.refresh();
|
|
|
|
}); |