NxTIC/manager/module/chart/networkChart.php

229 lines
6.8 KiB
PHP
Raw Normal View History

<?php
namespace manager\module\chart;
use \manager\sessionManager;
use \manager\ManagerError;
class networkChart{
/* RETOURNE UN JEU DE DONNEES POUR GRAPHIQUE #FIELD
*
*/
public static function data(){
/* [1] On cree de fausses donnees
=========================================================*/
$data = array(
/* (1) ID_EGO */
'ego' => 17,
/* (2) Liste des alters */
'alter' => array(
// Pour chaque alter, on a ID_ALTER, NOM_ALTER, AFFINITE_ALTER
array( 653, "Norris", 2*5/100 ),
array( 1743, "Melissa", 79*5/100 ),
array( 3739, "Sue", 38*5/100 ),
array( 36, "Rasmussen", 34*5/100 ),
array( 1372, "Brown", 35*5/100 ),
array( 3030, "Brock", 84*5/100 ),
array( 3821, "Savage", 21*5/100 ),
array( 1288, "Black", 17*5/100 ),
array( 1443, "Susie", 69*5/100 ),
array( 4129, "Rowe", 66*5/100 ),
array( 71, "Dillard", 87*5/100 ),
array( 1002, "Richmond", 5*5/100 ),
array( 640, "Morris", 24*5/100 ),
array( 2335, "Daugherty", 53*5/100 ),
array( 2541, "Hughes", 74*5/100 ),
array( 3963, "Roach", 13*5/100 ),
array( 4550, "Hazel", 30*5/100 ),
array( 3120, "Eugenia", 97*5/100 ),
array( 4302, "Nicholson", 25*5/100 ),
array( 859, "Marguerite", 70*5/100 ),
array( 2551, "Aurora", 36*5/100 ),
array( 3612, "Tracie", 55*5/100 ),
array( 3040, "Fulton", 62*5/100 ),
array( 1895, "Stuart", 37*5/100 ),
array( 4342, "Latasha", 21*5/100 ),
array( 2957, "Coleen", 1*5/100 ),
array( 2493, "Contreras", 100*5/100 ),
array( 4776, "Holmes", 97*5/100 ),
array( 3623, "Hallie", 88*5/100 ),
array( 3660, "Ginger", 26*5/100 ),
array( 471, "Slater", 23*5/100 ),
array( 4581, "Elnora", 23*5/100 ),
array( 286, "Patton", 71*5/100 ),
array( 3210, "Autumn", 23*5/100 ),
array( 1896, "Benton", 99*5/100 ),
array( 4875, "Fern", 17*5/100 ),
array( 2156, "Bond", 99*5/100 ),
array( 1556, "Ingrid", 34*5/100 ),
array( 2097, "Case", 23*5/100 ),
array( 3024, "Pat", 57*5/100 ),
array( 1121, "Reeves", 41*5/100 ),
array( 1832, "Francis", 75*5/100 ),
array( 3733, "Moore", 77*5/100 ),
array( 737, "Elva", 49*5/100 ),
array( 1137, "Stevenson", 10*5/100 ),
array( 988, "Lauri", 44*5/100 ),
array( 1182, "Boone", 19*5/100 ),
array( 909, "Morin", 68*5/100 )
),
/* (1) Liste des relations */
'inter' => array(
array( 471, 3821 ),
array( 4129, 1137 ),
array( 4302, 2957 ),
array( 859, 3660 ),
array( 640, 71 ),
array( 4129, 1372 ),
array( 909, 4550 ),
array( 2156, 3210 ),
array( 2493, 3660 ),
array( 2541, 4550 ),
array( 1372, 3660 ),
array( 1896, 4875 ),
array( 988, 3120 ),
array( 1121, 1372 ),
array( 4550, 909 ),
array( 988, 3739 ),
array( 2156, 3030 ),
array( 4342, 4302 ),
array( 71, 286 ),
array( 3120, 1182 ),
array( 3821, 3660 ),
array( 2541, 1743 ),
array( 1895, 1182 ),
array( 3030, 1372 ),
array( 3040, 1556 ),
array( 2541, 1832 ),
array( 3660, 3210 ),
array( 1895, 3821 )
)
);
/* [5] Gestion du retour
=========================================================*/
return array(
'ModuleError' => ManagerError::Success,
'data' => $data
);
}
/* RETOURNE UN SVG CORRESPONDANT AU GRAPHIQUE #FIELD
*
* @data<Array> Jeu de donnees
*
* @return render<String> Contenu du svg representation graphique des donnees
*
*/
public static function render($data){
$render = "";
$nb_circles = 4;
// Couleur Facebook
$facebook = 0x3b5998;
/* [1] On genere le debut du svg
=========================================================*/
$render .= '<?xml version="1.0" encoding="UTF-8" standalone="no"?>';
$render .= '<svg height="500" viewBox="0 0 1000 1000" width="500" xmlns="http://www.w3.org/2000/svg">';
/* [2] On cree le contexte (cercles dont ego)
=========================================================*/
$circles = array();
// Difference de rayon (40 = taille ego + espace)
$raddiff = (500-50) / ($nb_circles);
// Pour chaque cercle dont ego
for( $i = 0 ; $i < $nb_circles ; $i++ ){
$circles[$i] = "<circle cx='500' cy='500' r='".(500-50-$i*$raddiff)."' fill='#".(($i%2==0)?'ddd':'fff')."' />";
}
$circles[ $nb_circles ] = "<circle cx='500' cy='500' r='20' fill='#ff5629' />";
/* [3] On cree les elements dynamiques
=========================================================*/
/* (1) On calcule l'angle de diff entre chaque ALTER */
$ang = 2*pi() / count($data['alter']);
/* (2) On ajoute tous les alters */
$alters = array();
$origins = array();
foreach($data['alter'] as $i=>$alter){
// On calcule l'origine (centre du cercle)
$origins[$alter[0]] = array(
'x' => 500 + (5-$alter[2])*(400/5) * cos($ang*$i),
'y' => 500 + (5-$alter[2])*(400/5) * sin($ang*$i)
);
// On ajoute le cercle associe a l'alter courant
$alters[$i] = "<circle cx='".$origins[$alter[0]]['x']."' cy='".$origins[$alter[0]]['y']."' r='20' fill='#53d192' title='".$alter[1]."' />";
}
/* [4] On relie toutes les relations
=========================================================*/
$inter = array();
foreach($data['inter'] as $rel){
$lefthand = isset($origins[$rel[0]]) && is_array($origins[$rel[0]]);
$righthand = isset($origins[$rel[1]]) && is_array($origins[$rel[1]]);
// Si les deux existent, on les relie
if( $lefthand && $righthand )
array_push($inter,
"<line x1='".$origins[$rel[0]]['x']."' y1='".$origins[$rel[0]]['y']."' x2='".$origins[$rel[1]]['x']."' y2='".$origins[$rel[1]]['y']."' stroke-width='5' stroke='#888' />"
);
}
/* [5] On ajoute les elements et on ferme le svg
=========================================================*/
foreach($circles as $circle) $render .= $circle; // les cercles (dont ego)
foreach($inter as $rel) $render .= $rel; // les relations
foreach($alters as $alter) $render .= $alter; // les alters
$render .= "</svg>";
/* [6] Gestion du retour
=========================================================*/
return array(
'ModuleError' => ManagerError::Success,
'render' => $render
);
}
}
?>