Listing du fichier jphistopct.php
00001 <?php
00002
00003 # error_reporting(E_ALL | E_NOTICE | E_STRICT ) ;
00004
00005 # redirection éventuelle de www.info vers forge.info (à cause de jpgraph)
00006
00007 $host = getenv("HTTP_HOST") ; #echo " HOST : $host " ;
00008 include("std7.php") ;
00009
00010 if ($host=="www.info.univ-angers.fr") {
00011
00012 $titre = "jpHistoPct" ;
00013 $temps = 0 ;
00014 $newUrl = "http://forge.info.univ-angers.fr/~gh/jphistopct.php" ;
00015
00016 debutPageRedir($titre,$temps,$newUrl) ;
00017
00018 } ; # fin si
00019
00020 function aide() {
00021
00022 debutPage("Histogramme de fréquences par script PHP") ;
00023
00024 echo "<blockquote>\n" ;
00025 echo "<h1>JPHISTOPCT.PHP " ;
00026 echo "(<a href=\"forge.info.univ-angers.fr/~gh\">gH</a>) : </h1>\n" ;
00027 echo "<h2> un script PHP rapide pour tracer des histogrammes de fréquences</h2>\n" ;
00028 echo "<h2> à l'aide de la librairie " ;
00029 #echo "<a href=\"http://www.aditus.nu/jpgraph/features.php\" target=\"_blank\">JPGRAPH</a>." ;
00030 echo "<a href=\"http://jpgraph.net/features/\" target=\"_blank\">JPGRAPH</a>." ;
00031 echo " Tout de suite un exemple :</h2>\n" ;
00032
00033 $prm = "jphistopct.php?vdata=5_20_10_15&titr=".urlencode("Bénéfices")."%20pour%204%20mois%20significatifs&xmrks=Jan_Juin_Aout_Dec&tailx=400&taily=250" ;
00034 echo "<blockquote>\n" ;
00035 echo "<blockquote>\n" ;
00036 echo " \n<img src=\"$prm\" alt=\"demo histo\" />\n" ;
00037 echo "</blockquote>\n" ;
00038 echo "</blockquote>\n" ;
00039
00040
00041 echo "<h2>Il y a deux façons d'utiliser ce script</h2>\n" ;
00042 echo "<blockquote>\n" ;
00043 echo " - <font color=\"#880000\"><b>directement</b> comme une URL</font> ;<br />" ;
00044 echo " par exemple http://forge.info.univ-angers.fr/~gh/jphistopct.php?vdata=100_300_200 ;\n" ;
00045 echo " ; testez <a href=\"jphistopct.php?vdata=100_300_200\">ici</a> cette URL.<p> </p>\n" ;
00046 echo " - <font color=\"#880000\"><b>indirectement</b> comme une image</font> ;<br />" ;
00047 echo " par exemple <img src=\"http://forge.info.univ-angers.fr/~gh/jphistopct.php?vdata=100_300_200\">" ;
00048 echo "(comme l'image ci-dessus).<p> </p>\n" ;
00049 echo "</blockquote>\n" ;
00050
00051 echo "<h2>Le tracé de l'histogramme dépend des variables passées en paramètres :</h2>\n" ;
00052 echo "<blockquote>" ;
00053 echo " Seule la variable <font color=\"#008800\"><b>vdata</b></font> est obligatoire.<p> </p>\n" ;
00054 echo "<table summary='t1'>\n" ;
00055 echo "<tr>\n" ;
00056 echo "<th>\n" ;
00057 echo "Variable\n" ;
00058 echo "</th>\n" ;
00059 echo "<th align=\"left\">\n" ;
00060 echo " Fonction\n" ;
00061 echo "</th>\n" ;
00062 echo "<th align=\"left\">\n" ;
00063 echo " Exemple\n" ;
00064 echo "</th>\n" ;
00065 echo "</tr>\n" ;
00066 echo "<tr>\n" ;
00067 echo "<td> <font color=\"#880000\"><b>vdata</b></font></td><td> données entières séparées par '_'</td><td> 100_450_50_200</td>" ;
00068 echo "</tr>\n" ;
00069 echo "<tr>\n" ;
00070 echo "<td> <font color=\"#880000\"><b>tailx</b></font></td><td> hauteur</td><td> 350</td>" ;
00071 echo "</tr>\n" ;
00072 echo "<tr>\n" ;
00073 echo "<td> <font color=\"#880000\"><b>taily</b></font></td><td> largeur</td><td> 400</td>" ;
00074 echo "</tr>\n" ;
00075 echo "<tr>\n" ;
00076 echo "<td> <font color=\"#880000\"><b>titr </b></font></td><td> titre</td><td> Ventes sur 4 mois</td>" ;
00077 echo "</tr>\n" ;
00078 echo "<tr>\n" ;
00079 echo "<td> <font color=\"#880000\"><b>xmrks</b></font></td><td> labels séparés par '_'</td><td> Jan_Juin_Aout_Dec</td>" ;
00080 echo "</tr>\n" ;
00081 echo "</table>\n" ;
00082 echo "<p> </p>\n" ;
00083 echo "</blockquote>\n" ;
00084
00085 echo "<h2>Exemple : </h2><p> </p>\n" ;
00086 echo "<blockquote>" ;
00087 $prm1 = "jphistopct.php?vdata=3_40_5_8_15&titr=%20Ventes%20en%20semaine" ;
00088 $prm2 = "&xmrks=Lun_Mar_Mer_Jeu_Ven&tailx=400&taily=250" ;
00089 echo "<b> <font color=\"#000088\">$prm1</font></b><br />\n" ;
00090 echo "<font color=\"#000088\"><b> " ;
00091 echo " " ;
00092 echo " " ;
00093 echo " " ;
00094 echo " $prm2</b></font><p>\n" ;
00095 echo "soit l'histogramme</p>" ;
00096 $prm = "jphistopct.php?vdata=3_40_5_8_15&titr=".urlencode("Ventes en semaines")."&xmrks=Lun_Mar_Mer_Jeu_Ven&tailx=400&taily=250" ;
00097 echo " <img src=\"$prm\" alt=\"histo\" />" ;
00098 echo "</blockquote>" ;
00099
00100 echo "<h3>Pour des tracés plus personnalisés, il faut modifier le script " ;
00101 echo "ou apprendre en détail <a href=\"http://jpgraph.net\" target=\"_blank\">JPGRAPH</a>.</h3>\n" ;
00102 echo "Voici ce que fait en gros le script après avoir calculé les pourcentages correspondant aux valeurs :\n" ;
00103 echo "et la hauteur maximale ramenée à 100 % ce qui permet d'avoir des histogrammes comparables :" ;
00104 echo "<pre>" ;
00105
00106 echo " // définition du graphique \n" ;
00107 echo " \n" ;
00108 echo " \$graph = new Graph(\$dimx,\$dimy); \n" ;
00109 echo " \$graph->SetScale(\"textlin\");\n" ;
00110 echo " \$graph->xaxis->SetTickLabels(\$xmrks);\n" ;
00111 echo " \$graph->title-> Set(\"\$titr\");\n" ;
00112 echo " \n" ;
00113 echo " // paramètres de l'histogramme\n" ;
00114 echo " \n" ;
00115 echo " \$barg = new BarPlot(\$data);\n" ;
00116 echo " \$barg->SetFillGradient(\"navy\",\"lightsteelblue\",GRAD_MIDVER);\n" ;
00117 echo " \$barg->SetColor(\"red\");\n" ;
00118 echo " \$barg->SetWidth(0.6);\n" ;
00119 echo " \$barg->SetShadow();\n" ;
00120 echo " \n" ;
00121 echo " // ajout de l'histogramme au graphique et affichage\n" ;
00122 echo " \n" ;
00123 echo " \$graph->Add(\$barg);\n" ;
00124 echo " \$graph->Stroke();\n" ;
00125 echo " \n" ;
00126
00127
00128 echo "</pre>" ;
00129 echo "Cliquer <a href=\"jphistopct.txt\">ici</a> pour voir une copie texte du script de tracé.</blockquote>" ;
00130
00131 echo "<blockquote> \n" ;
00132
00133 echo "<table summary='t2'>\n" ;
00134 echo "<tr>\n" ;
00135 echo "<td><img src=\"http://forge.info.univ-angers.fr/~gh/jphistopct.php?vdata=10_10_10_10_10_10_10_10_10_10&tailx=300&taily=200&titr=".urlencode("Avec tous ces")." \" alt=\"histo\" /></td>\n" ;
00136 echo "<td><img src=\"http://forge.info.univ-angers.fr/~gh/jphistopct.php?vdata=10_10_10_10_10&tailx=300&taily=200&titr=".urlencode("histogrammes, il est ")."\" alt=\"histo\" /></td>\n" ;
00137 echo "<td><img src=\"http://forge.info.univ-angers.fr/~gh/jphistopct.php?vdata=25_25_25_25&tailx=300&taily=200&titr=".urlencode("possible de comparer")."\" alt=\"histo\" /></td>\n" ;
00138 echo "</tr>\n" ;
00139 echo "<tr>\n" ;
00140 echo "<td><img src=\"http://forge.info.univ-angers.fr/~gh/jphistopct.php?vdata=30_30_30_10&tailx=300&taily=200&titr=".urlencode(" visuellement les ")."\" alt=\"histo\" /></td>\n" ;
00141 echo "<td><img src=\"http://forge.info.univ-angers.fr/~gh/jphistopct.php?vdata=20_20_10&tailx=300&taily=200&titr=".urlencode("différences de pourcentages.")."\" alt=\"histo\" /></td>\n" ;
00142 echo "<td><img src=\"http://forge.info.univ-angers.fr/~gh/jphistopct.php?vdata=50_25_10_15&tailx=300&taily=200&titr=".urlencode("Au passage,")."\" alt=\"histo\" /></td>\n" ;
00143 echo "</tr>\n" ;
00144 echo "<tr>\n" ;
00145 echo "<td><img src=\"http://forge.info.univ-angers.fr/~gh/jphistopct.php?vdata=20_60_10_10&tailx=300&taily=200&titr=".urlencode("on peut se rendre")."\" alt=\"histo\" /></td>\n" ;
00146 echo "<td><img src=\"http://forge.info.univ-angers.fr/~gh/jphistopct.php?vdata=10_70_20&tailx=300&taily=200&titr=".urlencode("compte que les")."\" alt=\"histo\" /></td>\n" ;
00147 echo "<td><img src=\"http://forge.info.univ-angers.fr/~gh/jphistopct.php?vdata=75_5_20_5&tailx=300&taily=200&titr=".urlencode('graduations')."\" alt=\"histo\" /></td>\n" ;
00148 echo "</tr>\n" ;
00149 echo "<tr>\n" ;
00150 echo "<td><img src=\"http://forge.info.univ-angers.fr/~gh/jphistopct.php?vdata=80_5_10_5&tailx=300&taily=200&titr=".urlencode("varient en fonction")."\" alt=\"histo\" /></td>\n" ;
00151 echo "<td><img src=\"http://forge.info.univ-angers.fr/~gh/jphistopct.php?vdata=5_90_5&tailx=300&taily=200&titr=".urlencode("du maximum")."\" alt=\"histo\" /></td>\n" ;
00152 echo "<td><img alt=\"histo\" src=\"http://forge.info.univ-angers.fr/~gh/jphistopct.php?vdata=0_100_0_0&tailx=300&taily=200&titr=".urlencode("en Y.")."\" /></td>\n" ;
00153 echo "</tr>\n" ;
00154 echo "</table>\n" ;
00155
00156 echo "<p> </p> \n" ;
00157 echo "<a href=\"forge.info.univ-angers.fr/~gh/\"><img src=\"return.gif\" alt=\"retour gH\" /></a> \n" ;
00158 echo " Retour à la page principale de \n" ;
00159 echo "<font color=\"#008800\">(gH)</font> \n" ;
00160 echo "<p> </p> \n" ;
00161 echo "<p> </p> \n" ;
00162 echo "</blockquote> \n" ;
00163 echo "</blockquote>" ;
00164 echo "</body> \n" ;
00165 echo "</html> \n" ;
00166
00167 return ;
00168 } ; # fin de fonction aide
00169
00170 ###############################
00171 ## ##
00172 ## programme principal ##
00173 ## ##
00174 ###############################
00175
00176 # affichage de l'aide si pas de variable vdata
00177
00178 if (!isset($_GET["vdata"])) { aide() ; return ; } ;
00179
00180 ###################### exemple d'appel
00181 #
00182 # $prm = "" ;
00183 # $prm .= "titr= Pourcentage par classe d'E.C. " ;
00184 # $prm .= "&tailx=500" ;
00185 # $prm .= "&taily=400" ;
00186 # $prm .= "&hdata= 22_8_57_11_0_2_0 ; # valeurs $hdata" ;
00187 # $prm .= "&xmrks=1.*_2.*_3.0_4.*_5.*_6.*" ; # nom des barres
00188 #
00189 # echo "<img src=\"jphisto.php?$prm\"><p>" ;
00190 #
00191 # soit :
00192 #
00193 # jphisto.php?titr= Pourcentage par classe d'E.C. &tailx=500&taily=400
00194 # &vdata=31_11_82_16_0_3&xmrks=1.*_2.*_3.0_4.*_5.*_6.*&grace=63
00195 #
00196 #
00197 ######################################################
00198
00199 $dbg = 0 ; /* 0 en normal, 1 pour test */
00200
00201 # valeurs par défaut
00202
00203 $dimx = 500 ;
00204 $dimy = 400 ;
00205 $leti = "pas de données via titr tailx taily xmrks " ;
00206 $xmrk = "1_2_3_4_5_6_7_8_9_10_11_12" ;
00207
00208 # lecture des classes graphiques
00209
00210 include ("jpgraph/jpgraph.php");
00211 include ("jpgraph/jpgraph_bar.php");
00212
00213 # récupération des données
00214
00215 if (isset($_GET["tailx"])) { $dimx = $_GET["tailx"] ; } ;
00216 if (isset($_GET["taily"])) { $dimy = $_GET["taily"] ; } ;
00217 if (isset($_GET["vdata"])) { $vdat = urldecode($_GET["vdata"]) ; } ;
00218 if (isset($_GET["xmrks"])) { $xmrk = $_GET["xmrks"] ; } ;
00219 if (isset($_GET["titr" ])) { $leti = $_GET["titr"] ; } ;
00220 if (isset($_GET["dbg" ])) { $dbg = $_GET["dbg"] ; } ;
00221
00222 $xlab = explode("_",$xmrk) ;
00223 $teff = explode("_",$vdat) ;
00224
00225 # préparation des tableaux
00226
00227 $data = array() ;
00228 $nbd = 0 ;
00229 $nbv = count($teff) ;
00230
00231 // calcul du total
00232
00233 $tot = 0 ;
00234 foreach ($teff as $valr) { $tot += $valr ; } ;
00235
00236 // calcul des pourcentages
00237
00238 $vmax = 0 ;
00239 foreach ($teff as $valr) {
00240 $cpct = $valr/$tot ;
00241 if ($vmax<$cpct) { $vmax = $cpct ; }
00242 $data[$nbd] = round(100*$cpct) ;
00243 $nbd++;
00244 } ; # fin pour
00245
00246 # calcul de la "grace" pour arriver à 100 %
00247 # ce qui permet de comparer des histogrammes
00248 # si on donne la même taille aux graphiques
00249 # plutot que de mettre une fonction exponentielle
00250 # décroissante (illisible) on utilise des
00251 # valeurs par cas.
00252
00253 $hmax = round(100*$vmax) ;
00254 $gras = 900 ;
00255
00256 if ($hmax>10) { $gras = 700 ; }
00257 if ($hmax>14) { $gras = 550 ; }
00258 if ($hmax>19) { $gras = 380 ; }
00259 if ($hmax>20) { $gras = 365 ; }
00260 if ($hmax>21) { $gras = 350 ; }
00261 if ($hmax>24) { $gras = 260 ; }
00262 if ($hmax>29) { $gras = 220 ; }
00263 if ($hmax>34) { $gras = 170 ; }
00264 if ($hmax>39) { $gras = 130 ; }
00265 if ($hmax>44) { $gras = 110 ; }
00266 if ($hmax>49) { $gras = 90 ; }
00267 if ($hmax>53) { $gras = 76 ; }
00268 if ($hmax>58) { $gras = 60 ; }
00269 if ($hmax>66) { $gras = 40 ; }
00270 if ($hmax>79) { $gras = 25 ; }
00271 if ($hmax>80) { $gras = 20 ; }
00272 if ($hmax>84) { $gras = 10 ; }
00273 if ($hmax>89) { $gras = 10 ; }
00274 if ($hmax>93) { $gras = 03 ; }
00275 if ($hmax>96) { $gras = 00 ; }
00276
00277 #$gras = -6.0 * $hmax + 380 ;
00278 if ($gras<0) { $gras = 80 ; } ;
00279
00280 $hdat = implode("_",$data) ;
00281
00282 /* en fonction de dbg, affichage des valeurs ou du graphique */
00283
00284 if ($dbg==1) {
00285
00286 # pour test : $leti = "gras $gras hmax $hmax " ;
00287
00288 echo " vdata $vdat<br>\n" ;
00289 echo " hdata $hdat<br>\n" ;
00290 echo " grac $gras<br>\n" ;
00291 echo " xmrk $xmrk<br>\n" ;
00292 echo " leti $leti<br>\n" ;
00293 echo " dimx $dimx<br>\n" ;
00294 echo " dimx $dimy<br>\n" ;
00295
00296 } else {
00297
00298 // définition du graphe
00299
00300 $graph = new Graph($dimx,$dimy);
00301 $graph->SetScale("textlin");
00302 $graph->xaxis->SetTickLabels($xlab);
00303 $fgras = sprintf("%5.1f",$gras) ;
00304 # pour test : $graph->title-> Set("\n $hmax -> $fgras $leti\n");
00305 $leti = urldecode($leti) ; # juin 2007
00306 $graph->title-> Set("\n$leti\n");
00307 ## dbg :$graph->title-> Set("\n$hmax $gras $leti\n");
00308 # pour arriver à 100 %
00309 $graph-> yaxis->scale->SetGrace ($gras);
00310
00311 // paramètres de l'histogramme
00312
00313 $barg = new BarPlot($data);
00314 $barg->SetFillGradient("navy","lightsteelblue",GRAD_MIDVER);
00315 $barg->SetColor("navy");
00316 $barg->SetWidth(0.6);
00317 $barg->SetShadow();
00318
00319 // ajout et affichage
00320
00321 $graph->Add($barg);
00322 $graph->Stroke();
00323
00324 } ; # fin de si dbg
00325 ?>
La coloration syntaxique est réalisée par un enrobage de la function php nommée highlight_file
mais si vous préférez, vous pouvez utiliser celle de SyntaxHighlighter ou même celle de geshi.
Pour ne pas voir les numéros de ligne, ajoutez &nl=non à la suite du nom du fichier.
Retour à la page principale de (gH)