NxTIC/view/js/charts.js

71 lines
1.3 KiB
JavaScript

/* [1] Gestion du sociogramme
=========================================================*/
/* (0) On recupere les elements importants */
var SOCIOGRAM = {
container: document.getElementById('sociogram'),
sigma: null
};
// Initialisation de SIGMA
SOCIOGRAM.sigma = new sigma(SOCIOGRAM.container);
/* (1) On recupere les informations via l'API */
/* (2) Parametrage de SIGMA */
SOCIOGRAM.sigma.settings({
defaultNodeColor: '#ec5148'
});
/* (3) On recupere la liste des noeuds */
var nodes = [
{
"id": "n0",
"label": "A node",
"x": 0,
"y": 0,
"size": 3
}, {
"id": "n1",
"label": "Another node",
"x": 3,
"y": 1,
"size": 2
}, {
"id": "n2",
"label": "And a last one",
"x": 1,
"y": 3,
"size": 1
}];
/* (4) On recupere la liste des liens */
var edges = [{
"id": "e0",
"source": "n0",
"target": "n1"
}, {
"id": "e1",
"source": "n1",
"target": "n2"
}, {
"id": "e2",
"source": "n2",
"target": "n0"
}];
/* (5) On ajoute nos noeuds */
for( var i = 0 ; i < nodes.length ; i++)
SOCIOGRAM.sigma.graph.addNode(nodes[i]);
/* (6) On ajoute nos liens */
for( var i = 0 ; i < edges.length ; i++)
SOCIOGRAM.sigma.graph.addEdge(edges[i]);
/* (7) Gestion des interactions */
/* (8) On affiche le graphique */
SOCIOGRAM.sigma.camera.ratio = 2;
SOCIOGRAM.sigma.refresh();