2016-04-08 16:06:50 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace manager\module;
|
|
|
|
use \manager\Database;
|
|
|
|
use \manager\sessionManager;
|
|
|
|
use \manager\ManagerError;
|
|
|
|
use \manager\Repo;
|
|
|
|
|
|
|
|
class charts{
|
|
|
|
|
|
|
|
|
|
|
|
/* RETOURNE UN JEU DE DONNEES POUR GRAPHIQUE #FIELD
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public static function field_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(
|
2016-04-09 18:34:05 +00:00
|
|
|
array(12, 3),
|
|
|
|
array(15, 3),
|
|
|
|
array(3, 18),
|
|
|
|
array(18, 1)
|
2016-04-08 16:06:50 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
/* [5] Gestion du retour
|
|
|
|
=========================================================*/
|
|
|
|
return array(
|
|
|
|
'ModuleError' => ManagerError::Success,
|
2016-04-09 18:34:05 +00:00
|
|
|
'data' => $data
|
2016-04-08 16:06:50 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* 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 field_render($data){
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
debug();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$render = "";
|
|
|
|
/* [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)
|
|
|
|
=========================================================*/
|
|
|
|
$ego = "<circle cx='500' cy='500' r='20' fill='#ff5629' />";
|
|
|
|
$close = "<circle cx='500' cy='500' r='400' fill='#ddd' />";
|
|
|
|
$veryclose = "<circle cx='500' cy='500' r='200' fill='#fff' />";
|
|
|
|
|
|
|
|
|
|
|
|
/* [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
|
|
|
|
=========================================================*/
|
|
|
|
$render .= $close;
|
|
|
|
$render .= $veryclose;
|
|
|
|
foreach($inter as $rel) $render .= $rel; // les relations
|
|
|
|
foreach($alters as $alter) $render .= $alter; // les alters
|
|
|
|
$render .= $ego;
|
|
|
|
|
|
|
|
$render .= "</svg>";
|
|
|
|
|
|
|
|
|
|
|
|
/* [6] Gestion du retour
|
|
|
|
=========================================================*/
|
|
|
|
return array(
|
|
|
|
'ModuleError' => ManagerError::Success,
|
|
|
|
'render' => $render
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
?>
|