Listing du fichier jphistopct.php avec syntaxhighlighter
<?php # error_reporting(E_ALL | E_NOTICE | E_STRICT ) ; # redirection éventuelle de www.info vers forge.info (à cause de jpgraph) $host = getenv("HTTP_HOST") ; #echo " HOST : $host " ; include("std7.php") ; if ($host=="www.info.univ-angers.fr") { $titre = "jpHistoPct" ; $temps = 0 ; $newUrl = "http://forge.info.univ-angers.fr/~gh/jphistopct.php" ; debutPageRedir($titre,$temps,$newUrl) ; } ; # fin si function aide() { debutPage("Histogramme de fréquences par script PHP") ; echo "<blockquote>\n" ; echo "<h1>JPHISTOPCT.PHP " ; echo "(<a href=\"forge.info.univ-angers.fr/~gh\">gH</a>) : </h1>\n" ; echo "<h2> un script PHP rapide pour tracer des histogrammes de fréquences</h2>\n" ; echo "<h2> à l'aide de la librairie " ; #echo "<a href=\"http://www.aditus.nu/jpgraph/features.php\" target=\"_blank\">JPGRAPH</a>." ; echo "<a href=\"http://jpgraph.net/features/\" target=\"_blank\">JPGRAPH</a>." ; echo " Tout de suite un exemple :</h2>\n" ; $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" ; echo "<blockquote>\n" ; echo "<blockquote>\n" ; echo " \n<img src=\"$prm\" alt=\"demo histo\" />\n" ; echo "</blockquote>\n" ; echo "</blockquote>\n" ; echo "<h2>Il y a deux façons d'utiliser ce script</h2>\n" ; echo "<blockquote>\n" ; echo " - <font color=\"#880000\"><b>directement</b> comme une URL</font> ;<br />" ; echo " par exemple http://forge.info.univ-angers.fr/~gh/jphistopct.php?vdata=100_300_200 ;\n" ; echo " ; testez <a href=\"jphistopct.php?vdata=100_300_200\">ici</a> cette URL.<p> </p>\n" ; echo " - <font color=\"#880000\"><b>indirectement</b> comme une image</font> ;<br />" ; echo " par exemple <img src=\"http://forge.info.univ-angers.fr/~gh/jphistopct.php?vdata=100_300_200\">" ; echo "(comme l'image ci-dessus).<p> </p>\n" ; echo "</blockquote>\n" ; echo "<h2>Le tracé de l'histogramme dépend des variables passées en paramètres :</h2>\n" ; echo "<blockquote>" ; echo " Seule la variable <font color=\"#008800\"><b>vdata</b></font> est obligatoire.<p> </p>\n" ; echo "<table summary='t1'>\n" ; echo "<tr>\n" ; echo "<th>\n" ; echo "Variable\n" ; echo "</th>\n" ; echo "<th align=\"left\">\n" ; echo " Fonction\n" ; echo "</th>\n" ; echo "<th align=\"left\">\n" ; echo " Exemple\n" ; echo "</th>\n" ; echo "</tr>\n" ; echo "<tr>\n" ; 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>" ; echo "</tr>\n" ; echo "<tr>\n" ; echo "<td> <font color=\"#880000\"><b>tailx</b></font></td><td> hauteur</td><td> 350</td>" ; echo "</tr>\n" ; echo "<tr>\n" ; echo "<td> <font color=\"#880000\"><b>taily</b></font></td><td> largeur</td><td> 400</td>" ; echo "</tr>\n" ; echo "<tr>\n" ; echo "<td> <font color=\"#880000\"><b>titr </b></font></td><td> titre</td><td> Ventes sur 4 mois</td>" ; echo "</tr>\n" ; echo "<tr>\n" ; echo "<td> <font color=\"#880000\"><b>xmrks</b></font></td><td> labels séparés par '_'</td><td> Jan_Juin_Aout_Dec</td>" ; echo "</tr>\n" ; echo "</table>\n" ; echo "<p> </p>\n" ; echo "</blockquote>\n" ; echo "<h2>Exemple : </h2><p> </p>\n" ; echo "<blockquote>" ; $prm1 = "jphistopct.php?vdata=3_40_5_8_15&titr=%20Ventes%20en%20semaine" ; $prm2 = "&xmrks=Lun_Mar_Mer_Jeu_Ven&tailx=400&taily=250" ; echo "<b> <font color=\"#000088\">$prm1</font></b><br />\n" ; echo "<font color=\"#000088\"><b> " ; echo " " ; echo " " ; echo " " ; echo " $prm2</b></font><p>\n" ; echo "soit l'histogramme</p>" ; $prm = "jphistopct.php?vdata=3_40_5_8_15&titr=".urlencode("Ventes en semaines")."&xmrks=Lun_Mar_Mer_Jeu_Ven&tailx=400&taily=250" ; echo " <img src=\"$prm\" alt=\"histo\" />" ; echo "</blockquote>" ; echo "<h3>Pour des tracés plus personnalisés, il faut modifier le script " ; echo "ou apprendre en détail <a href=\"http://jpgraph.net\" target=\"_blank\">JPGRAPH</a>.</h3>\n" ; echo "Voici ce que fait en gros le script après avoir calculé les pourcentages correspondant aux valeurs :\n" ; echo "et la hauteur maximale ramenée à 100 % ce qui permet d'avoir des histogrammes comparables :" ; echo "<pre>" ; echo " // définition du graphique \n" ; echo " \n" ; echo " \$graph = new Graph(\$dimx,\$dimy); \n" ; echo " \$graph->SetScale(\"textlin\");\n" ; echo " \$graph->xaxis->SetTickLabels(\$xmrks);\n" ; echo " \$graph->title-> Set(\"\$titr\");\n" ; echo " \n" ; echo " // paramètres de l'histogramme\n" ; echo " \n" ; echo " \$barg = new BarPlot(\$data);\n" ; echo " \$barg->SetFillGradient(\"navy\",\"lightsteelblue\",GRAD_MIDVER);\n" ; echo " \$barg->SetColor(\"red\");\n" ; echo " \$barg->SetWidth(0.6);\n" ; echo " \$barg->SetShadow();\n" ; echo " \n" ; echo " // ajout de l'histogramme au graphique et affichage\n" ; echo " \n" ; echo " \$graph->Add(\$barg);\n" ; echo " \$graph->Stroke();\n" ; echo " \n" ; echo "</pre>" ; echo "Cliquer <a href=\"jphistopct.txt\">ici</a> pour voir une copie texte du script de tracé.</blockquote>" ; echo "<blockquote> \n" ; echo "<table summary='t2'>\n" ; echo "<tr>\n" ; 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" ; 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" ; 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" ; echo "</tr>\n" ; echo "<tr>\n" ; 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" ; 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" ; 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" ; echo "</tr>\n" ; echo "<tr>\n" ; 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" ; 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" ; 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" ; echo "</tr>\n" ; echo "<tr>\n" ; 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" ; 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" ; 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" ; echo "</tr>\n" ; echo "</table>\n" ; echo "<p> </p> \n" ; echo "<a href=\"forge.info.univ-angers.fr/~gh/\"><img src=\"return.gif\" alt=\"retour gH\" /></a> \n" ; echo " Retour à la page principale de \n" ; echo "<font color=\"#008800\">(gH)</font> \n" ; echo "<p> </p> \n" ; echo "<p> </p> \n" ; echo "</blockquote> \n" ; echo "</blockquote>" ; echo "</body> \n" ; echo "</html> \n" ; return ; } ; # fin de fonction aide ############################### ## ## ## programme principal ## ## ## ############################### # affichage de l'aide si pas de variable vdata if (!isset($_GET["vdata"])) { aide() ; return ; } ; ###################### exemple d'appel # # $prm = "" ; # $prm .= "titr= Pourcentage par classe d'E.C. " ; # $prm .= "&tailx=500" ; # $prm .= "&taily=400" ; # $prm .= "&hdata= 22_8_57_11_0_2_0 ; # valeurs $hdata" ; # $prm .= "&xmrks=1.*_2.*_3.0_4.*_5.*_6.*" ; # nom des barres # # echo "<img src=\"jphisto.php?$prm\"><p>" ; # # soit : # # jphisto.php?titr= Pourcentage par classe d'E.C. &tailx=500&taily=400 # &vdata=31_11_82_16_0_3&xmrks=1.*_2.*_3.0_4.*_5.*_6.*&grace=63 # # ###################################################### $dbg = 0 ; /* 0 en normal, 1 pour test */ # valeurs par défaut $dimx = 500 ; $dimy = 400 ; $leti = "pas de données via titr tailx taily xmrks " ; $xmrk = "1_2_3_4_5_6_7_8_9_10_11_12" ; # lecture des classes graphiques include ("jpgraph/jpgraph.php"); include ("jpgraph/jpgraph_bar.php"); # récupération des données if (isset($_GET["tailx"])) { $dimx = $_GET["tailx"] ; } ; if (isset($_GET["taily"])) { $dimy = $_GET["taily"] ; } ; if (isset($_GET["vdata"])) { $vdat = urldecode($_GET["vdata"]) ; } ; if (isset($_GET["xmrks"])) { $xmrk = $_GET["xmrks"] ; } ; if (isset($_GET["titr" ])) { $leti = $_GET["titr"] ; } ; if (isset($_GET["dbg" ])) { $dbg = $_GET["dbg"] ; } ; $xlab = explode("_",$xmrk) ; $teff = explode("_",$vdat) ; # préparation des tableaux $data = array() ; $nbd = 0 ; $nbv = count($teff) ; // calcul du total $tot = 0 ; foreach ($teff as $valr) { $tot += $valr ; } ; // calcul des pourcentages $vmax = 0 ; foreach ($teff as $valr) { $cpct = $valr/$tot ; if ($vmax<$cpct) { $vmax = $cpct ; } $data[$nbd] = round(100*$cpct) ; $nbd++; } ; # fin pour # calcul de la "grace" pour arriver à 100 % # ce qui permet de comparer des histogrammes # si on donne la même taille aux graphiques # plutot que de mettre une fonction exponentielle # décroissante (illisible) on utilise des # valeurs par cas. $hmax = round(100*$vmax) ; $gras = 900 ; if ($hmax>10) { $gras = 700 ; } if ($hmax>14) { $gras = 550 ; } if ($hmax>19) { $gras = 380 ; } if ($hmax>20) { $gras = 365 ; } if ($hmax>21) { $gras = 350 ; } if ($hmax>24) { $gras = 260 ; } if ($hmax>29) { $gras = 220 ; } if ($hmax>34) { $gras = 170 ; } if ($hmax>39) { $gras = 130 ; } if ($hmax>44) { $gras = 110 ; } if ($hmax>49) { $gras = 90 ; } if ($hmax>53) { $gras = 76 ; } if ($hmax>58) { $gras = 60 ; } if ($hmax>66) { $gras = 40 ; } if ($hmax>79) { $gras = 25 ; } if ($hmax>80) { $gras = 20 ; } if ($hmax>84) { $gras = 10 ; } if ($hmax>89) { $gras = 10 ; } if ($hmax>93) { $gras = 03 ; } if ($hmax>96) { $gras = 00 ; } #$gras = -6.0 * $hmax + 380 ; if ($gras<0) { $gras = 80 ; } ; $hdat = implode("_",$data) ; /* en fonction de dbg, affichage des valeurs ou du graphique */ if ($dbg==1) { # pour test : $leti = "gras $gras hmax $hmax " ; echo " vdata $vdat<br>\n" ; echo " hdata $hdat<br>\n" ; echo " grac $gras<br>\n" ; echo " xmrk $xmrk<br>\n" ; echo " leti $leti<br>\n" ; echo " dimx $dimx<br>\n" ; echo " dimx $dimy<br>\n" ; } else { // définition du graphe $graph = new Graph($dimx,$dimy); $graph->SetScale("textlin"); $graph->xaxis->SetTickLabels($xlab); $fgras = sprintf("%5.1f",$gras) ; # pour test : $graph->title-> Set("\n $hmax -> $fgras $leti\n"); $leti = urldecode($leti) ; # juin 2007 $graph->title-> Set("\n$leti\n"); ## dbg :$graph->title-> Set("\n$hmax $gras $leti\n"); # pour arriver à 100 % $graph-> yaxis->scale->SetGrace ($gras); // paramètres de l'histogramme $barg = new BarPlot($data); $barg->SetFillGradient("navy","lightsteelblue",GRAD_MIDVER); $barg->SetColor("navy"); $barg->SetWidth(0.6); $barg->SetShadow(); // ajout et affichage $graph->Add($barg); $graph->Stroke(); } ; # fin de si dbg ?>La coloration syntaxique est réalisée par : SyntaxHighlighter.
Si vous préférez, vous pouvez utiliser celle de geshi ou même celle construite autour de la fonction highlight_file.
Retour à la page principale de (gH)