| 66 |
aurelien |
1 |
<?php
|
|
|
2 |
/**
|
|
|
3 |
* PHP Version 5
|
|
|
4 |
*
|
|
|
5 |
* @category PHP
|
|
|
6 |
* @package annuaire
|
|
|
7 |
* @author aurelien <aurelien@tela-botanica.org>
|
|
|
8 |
* @copyright 2010 Tela-Botanica
|
|
|
9 |
* @license http://www.cecill.info/licences/Licence_CeCILL_V2-fr.txt Licence CECILL
|
|
|
10 |
* @version SVN: <svn_id>
|
|
|
11 |
* @link /doc/annuaire/
|
|
|
12 |
*/
|
|
|
13 |
|
|
|
14 |
class Statistiques {
|
|
|
15 |
|
|
|
16 |
const GRAPH_CAMEMBERT = 'pie';
|
|
|
17 |
const GRAPH_COURBE = 'courbe';
|
| 442 |
jpm |
18 |
private $chemin_lib_graph = '';
|
|
|
19 |
|
|
|
20 |
public function __construct() {
|
|
|
21 |
$this->chemin_lib_graph = Config::get('chemin_jpgraph');
|
|
|
22 |
}
|
| 66 |
aurelien |
23 |
|
| 232 |
aurelien |
24 |
public function genererGraphique($type_graphique, $valeurs, $titre = '', $taille = array(800, 800), $nom_axe_x = '', $nom_axe_y = '') {
|
| 442 |
jpm |
25 |
include_once $this->chemin_lib_graph.'jpgraph.php';
|
|
|
26 |
|
| 66 |
aurelien |
27 |
$graph = null;
|
|
|
28 |
switch($type_graphique) {
|
|
|
29 |
case Statistiques::GRAPH_CAMEMBERT:
|
| 232 |
aurelien |
30 |
$graph = $this->genererGraphiqueCamembert($valeurs, $titre, $taille);
|
| 442 |
jpm |
31 |
break;
|
| 66 |
aurelien |
32 |
case Statistiques::GRAPH_COURBE:
|
| 232 |
aurelien |
33 |
$graph = $this->genererGraphiqueCourbe($valeurs, $titre, $taille, $nom_axe_x, $nom_axe_y);
|
| 442 |
jpm |
34 |
break;
|
| 66 |
aurelien |
35 |
default:
|
|
|
36 |
$graph = $this->genererGraphiqueCourbe($valeurs);
|
|
|
37 |
}
|
|
|
38 |
|
|
|
39 |
return $graph;
|
|
|
40 |
}
|
|
|
41 |
|
| 232 |
aurelien |
42 |
public function genererGraphiqueCamembert($valeurs, $titre, $taille) {
|
| 442 |
jpm |
43 |
include_once $this->chemin_lib_graph.'jpgraph_pie.php';
|
| 223 |
aurelien |
44 |
$legendes = array_keys($valeurs);
|
|
|
45 |
$valeurs = array_values($valeurs);
|
| 442 |
jpm |
46 |
//die('<pre>'.print_r($valeurs, true).'</pre>');
|
| 223 |
aurelien |
47 |
$oPie = new PiePlot($valeurs);
|
|
|
48 |
$oPie->SetLegends($legendes);
|
| 66 |
aurelien |
49 |
// position du graphique (légèrement à droite)
|
| 232 |
aurelien |
50 |
$oPie->SetCenter(0.35);
|
| 66 |
aurelien |
51 |
$oPie->SetValueType(PIE_VALUE_PER);
|
|
|
52 |
// Format des valeurs de type "entier"
|
| 223 |
aurelien |
53 |
$oPie->value->SetFormat('%1.2f%%');
|
| 66 |
aurelien |
54 |
|
| 442 |
jpm |
55 |
$graph = new PieGraph($taille[0],$taille[1]);
|
|
|
56 |
// Ajouter le titre du graphique
|
|
|
57 |
$graph->title->Set($titre);
|
| 66 |
aurelien |
58 |
$graph->Add($oPie);
|
| 232 |
aurelien |
59 |
return $graph;
|
| 66 |
aurelien |
60 |
}
|
|
|
61 |
|
| 232 |
aurelien |
62 |
public function genererGraphiqueCourbe($valeurs, $titre, $taille, $nom_axe_x, $nom_axe_y) {
|
| 442 |
jpm |
63 |
include_once $this->chemin_lib_graph.'jpgraph_line.php';
|
|
|
64 |
|
| 66 |
aurelien |
65 |
// Création du conteneur
|
| 232 |
aurelien |
66 |
$graph = new Graph($taille[0],$taille[1],"auto");
|
| 66 |
aurelien |
67 |
|
| 232 |
aurelien |
68 |
$graph->img->SetMargin(50,30,50,100);
|
| 66 |
aurelien |
69 |
|
|
|
70 |
// Lissage sur fond blanc (évite la pixellisation)
|
|
|
71 |
$graph->img->SetAntiAliasing("white");
|
| 232 |
aurelien |
72 |
$graph->SetMarginColor("white");
|
| 66 |
aurelien |
73 |
|
|
|
74 |
// A détailler
|
|
|
75 |
$graph->SetScale("textlin");
|
|
|
76 |
|
|
|
77 |
// Ajouter une ombre
|
|
|
78 |
$graph->SetShadow();
|
|
|
79 |
|
|
|
80 |
// Ajouter le titre du graphique
|
|
|
81 |
$graph->title->Set($titre);
|
|
|
82 |
|
|
|
83 |
// Afficher la grille de l'axe des ordonnées
|
|
|
84 |
$graph->ygrid->Show();
|
|
|
85 |
// Fixer la couleur de l'axe (bleu avec transparence : @0.7)
|
| 232 |
aurelien |
86 |
$graph->ygrid->SetColor('#E6E6E6@0.7');
|
| 66 |
aurelien |
87 |
// Des tirets pour les lignes
|
|
|
88 |
$graph->ygrid->SetLineStyle('solid');
|
|
|
89 |
|
|
|
90 |
// Afficher la grille de l'axe des abscisses
|
| 232 |
aurelien |
91 |
//$graph->xgrid->Show();
|
| 66 |
aurelien |
92 |
// Fixer la couleur de l'axe (rouge avec transparence : @0.7)
|
| 232 |
aurelien |
93 |
//$graph->xgrid->SetColor('red@0.7');
|
| 66 |
aurelien |
94 |
// Des tirets pour les lignes
|
| 232 |
aurelien |
95 |
//$graph->xgrid->SetLineStyle('solid');
|
|
|
96 |
$graph->xaxis->SetLabelAngle(90);
|
|
|
97 |
$graph->xaxis->SetTextLabelInterval(4);
|
| 66 |
aurelien |
98 |
|
|
|
99 |
// Créer une courbes
|
|
|
100 |
$courbe = new LinePlot(array_values($valeurs));
|
|
|
101 |
|
|
|
102 |
// Chaque point de la courbe ****
|
|
|
103 |
// Type de point
|
|
|
104 |
$courbe->mark->SetType(MARK_FILLEDCIRCLE);
|
|
|
105 |
// Couleur de remplissage
|
| 232 |
aurelien |
106 |
$courbe->mark->SetFillColor("red");
|
| 66 |
aurelien |
107 |
// Taille
|
| 232 |
aurelien |
108 |
$courbe->mark->SetWidth(1);
|
| 66 |
aurelien |
109 |
|
|
|
110 |
// Paramétrage des axes
|
| 232 |
aurelien |
111 |
//$graph->xaxis->title->Set($nom_axe_x);
|
|
|
112 |
$txt = new Text($nom_axe_x,270,460);
|
| 66 |
aurelien |
113 |
$graph->xaxis->SetTickLabels(array_keys($valeurs));
|
|
|
114 |
|
|
|
115 |
// Paramétrage des axes
|
|
|
116 |
$graph->yaxis->title->Set($nom_axe_y);
|
|
|
117 |
|
|
|
118 |
// Ajouter la courbe au conteneur
|
|
|
119 |
$graph->Add($courbe);
|
|
|
120 |
|
| 232 |
aurelien |
121 |
return $graph;
|
| 66 |
aurelien |
122 |
}
|
|
|
123 |
|
| 232 |
aurelien |
124 |
public function combinerGraphiques($graph1, $graph2, $taille) {
|
| 442 |
jpm |
125 |
include_once $this->chemin_lib_graph.'jpgraph_mgraph.php';
|
| 66 |
aurelien |
126 |
|
| 232 |
aurelien |
127 |
$mgraph = new MGraph($taille[0],$taille[1],"auto");
|
|
|
128 |
$xpos1=300;$ypos1=3;
|
|
|
129 |
$xpos2=3;$ypos2=200;
|
|
|
130 |
|
|
|
131 |
$graph1->SetFrame(false);
|
|
|
132 |
$graph2->SetFrame(false);
|
|
|
133 |
|
|
|
134 |
//$xpos3=3;$ypos3=1000;
|
|
|
135 |
$mgraph->Add($graph1,$xpos1,$ypos1);
|
|
|
136 |
$mgraph->Add($graph2,$xpos2,$ypos2);
|
|
|
137 |
$mgraph->SetShadow();
|
|
|
138 |
//$mgraph->Add($graph['experience_bota'],$xpos3,$ypos3);
|
|
|
139 |
return $mgraph;
|
| 66 |
aurelien |
140 |
}
|
| 232 |
aurelien |
141 |
|
|
|
142 |
public function dessinerGraph($graph) {
|
|
|
143 |
return $graph->Stroke(_IMG_HANDLER);
|
|
|
144 |
}
|
| 66 |
aurelien |
145 |
}
|
| 442 |
jpm |
146 |
?>
|