Subversion Repositories Applications.annuaire

Rev

Rev 66 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
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';
18
 
19
	public function genererGraphique($type_graphique, $valeurs, $titre = '', $nom_axe_x = '', $nom_axe_y = '') {
20
 
21
		// Inclusion de la librairie JpGraph
22
		include_once("lib/jpgraph.php");
23
		$graph = null;
24
 
25
		switch($type_graphique) {
26
			case Statistiques::GRAPH_CAMEMBERT:
27
				$graph = $this->genererGraphiqueCamembert($valeurs, $titre);
28
			break;
29
 
30
			case Statistiques::GRAPH_COURBE:
31
				$graph = $this->genererGraphiqueCourbe($valeurs, $titre, $nom_axe_x, $nom_axe_y);
32
			break;
33
 
34
			default:
35
				$graph = $this->genererGraphiqueCourbe($valeurs);
36
			break;
37
		}
38
 
39
		return $graph;
40
	}
41
 
42
	public function genererGraphiqueCamembert($valeurs, $titre) {
43
 
44
		include_once("lib/jpgraph_pie.php");
45
		$graph = new PieGraph(500,500);
46
 
47
		$oPie = new PiePlot(array_values($valeurs));
48
		$oPie->SetLegends(array_keys($valeurs));
49
 
50
		// Ajouter le titre du graphique
51
		$graph->title->Set($titre);
52
 
53
		// position du graphique (légèrement à droite)
54
		$oPie->SetCenter(0.4);
55
 
56
		$oPie->SetValueType(PIE_VALUE_PER);
57
 
58
		// Format des valeurs de type "entier"
59
		$oPie->value->SetFormat('%d');
60
 
61
		$graph->Add($oPie);
62
		return $graph/*->Stroke(_IMG_HANDLER)*/;
63
	}
64
 
65
	public function genererGraphiqueCourbe($valeurs, $titre, $nom_axe_x, $nom_axe_y) {
66
 
67
		include_once("lib/jpgraph_line.php");
68
 
69
		// Création du conteneur
70
		$graph = new Graph(500,500);
71
 
72
		// Fixer les marges
73
		$graph->img->SetMargin(40,30,50,40);
74
 
75
		// Lissage sur fond blanc (évite la pixellisation)
76
		$graph->img->SetAntiAliasing("white");
77
 
78
		// A détailler
79
		$graph->SetScale("textlin");
80
 
81
		// Ajouter une ombre
82
		$graph->SetShadow();
83
 
84
		// Ajouter le titre du graphique
85
		$graph->title->Set($titre);
86
 
87
		// Afficher la grille de l'axe des ordonnées
88
		$graph->ygrid->Show();
89
		// Fixer la couleur de l'axe (bleu avec transparence : @0.7)
90
		$graph->ygrid->SetColor('blue@0.7');
91
		// Des tirets pour les lignes
92
		$graph->ygrid->SetLineStyle('solid');
93
 
94
		// Afficher la grille de l'axe des abscisses
95
		$graph->xgrid->Show();
96
		// Fixer la couleur de l'axe (rouge avec transparence : @0.7)
97
		$graph->xgrid->SetColor('red@0.7');
98
		// Des tirets pour les lignes
99
		$graph->xgrid->SetLineStyle('solid');
100
 
101
		// Créer une courbes
102
		$courbe = new LinePlot(array_values($valeurs));
103
 
104
		// Chaque point de la courbe ****
105
		// Type de point
106
		$courbe->mark->SetType(MARK_FILLEDCIRCLE);
107
		// Couleur de remplissage
108
		$courbe->mark->SetFillColor("green");
109
		// Taille
110
		$courbe->mark->SetWidth(5);
111
 
112
		// Paramétrage des axes
113
		$graph->xaxis->title->Set($nom_axe_x);
114
		$graph->xaxis->SetTickLabels(array_keys($valeurs));
115
 
116
		// Paramétrage des axes
117
		$graph->yaxis->title->Set($nom_axe_y);
118
 
119
		// Ajouter la courbe au conteneur
120
		$graph->Add($courbe);
121
 
122
		return $graph/*->Stroke(_IMG_HANDLER)*/;
123
	}
124
 
125
	public function combinerGraphiques($graph) {
126
 
127
		include_once('lib/jpgraph_mgraph.php');
128
		$mgraph = new MGraph(2000,2000);
129
		$xpos1=3;$ypos1=3;
130
		$xpos2=3;$ypos2=500;
131
		$xpos3=3;$ypos3=1000;
132
		$mgraph->Add($graph['pays'],$xpos1,$ypos1);
133
		$mgraph->Add($graph['activite_bota'],$xpos2,$ypos2);
134
		$mgraph->Add($graph['experience_bota'],$xpos3,$ypos3);
135
		return $mgraph->Stroke(_IMG_HANDLER);
136
	}
137
 
138
}
139
?>