163 lines
4.0 KiB
PHP
163 lines
4.0 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(15, 'Jean', 90), // 90% proche
|
|
array(3, 'George', 20),
|
|
array(18, 'Jacques', 30),
|
|
array(11, 'Jacquie', 40),
|
|
array(1, 'Martin', 50),
|
|
array(12, 'Martine', 60)
|
|
),
|
|
|
|
/* (1) Liste des relations */
|
|
'inter' => array(
|
|
array(12, 3),
|
|
array(15, 3),
|
|
array(3, 18),
|
|
array(18, 1)
|
|
)
|
|
|
|
);
|
|
|
|
/* [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
|
|
);
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
?>
|