NxTIC/manager/module/chart/networkChart.php

230 lines
6.5 KiB
PHP

<?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 ),
array( 1743, "Melissa", 79 ),
array( 3739, "Sue", 38 ),
array( 36, "Rasmussen", 34 ),
array( 1372, "Brown", 35 ),
array( 3030, "Brock", 84 ),
array( 3821, "Savage", 21 ),
array( 1288, "Black", 17 ),
array( 1443, "Susie", 69 ),
array( 4129, "Rowe", 66 ),
array( 71, "Dillard", 87 ),
array( 1002, "Richmond", 5 ),
array( 640, "Morris", 24 ),
array( 2335, "Daugherty", 53 ),
array( 2541, "Hughes", 74 ),
array( 3963, "Roach", 13 ),
array( 4550, "Hazel", 30 ),
array( 3120, "Eugenia", 97 ),
array( 4302, "Nicholson", 25 ),
array( 859, "Marguerite", 70 ),
array( 2551, "Aurora", 36 ),
array( 3612, "Tracie", 55 ),
array( 3040, "Fulton", 62 ),
array( 1895, "Stuart", 37 ),
array( 4342, "Latasha", 21 ),
array( 2957, "Coleen", 1 ),
array( 2493, "Contreras", 100 ),
array( 4776, "Holmes", 97 ),
array( 3623, "Hallie", 88 ),
array( 3660, "Ginger", 26 ),
array( 471, "Slater", 23 ),
array( 4581, "Elnora", 23 ),
array( 286, "Patton", 71 ),
array( 3210, "Autumn", 23 ),
array( 1896, "Benton", 99 ),
array( 4875, "Fern", 17 ),
array( 2156, "Bond", 99 ),
array( 1556, "Ingrid", 34 ),
array( 2097, "Case", 23 ),
array( 3024, "Pat", 57 ),
array( 1121, "Reeves", 41 ),
array( 1832, "Francis", 75 ),
array( 3733, "Moore", 77 ),
array( 737, "Elva", 49 ),
array( 1137, "Stevenson", 10 ),
array( 988, "Lauri", 44 ),
array( 1182, "Boone", 19 ),
array( 909, "Morin", 68 )
),
/* (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( 1896, 1896 ),
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 + (100-$alter[2])*(400/100) * cos($ang*$i),
'y' => 500 + (100-$alter[2])*(400/100) * 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
);
}
}
?>