Générateur de svg pour le parcours

This commit is contained in:
xdrm-brackets 2015-11-29 16:49:59 +01:00
parent 0652a000dc
commit 2cdd1e0772
2 changed files with 80 additions and 0 deletions

Binary file not shown.

80
svg.php Normal file
View File

@ -0,0 +1,80 @@
<?php
if( isset($_GET['parcours']) && strlen($_GET['parcours']) > 1 )
$parcours = explode(',', $_GET['parcours']);
else
$parcours = array('S1', 'S2', 'S3', 'S4'); // contient les étapes du parcours d'un étudiant
/* paramètres de texte */
$lettrePixel = 10; // taille d'une lettre pour centrer le texte
$maxLettres = 0;
foreach($parcours as $p) if( strlen($p) > $maxLettres ) $maxLettres = strlen($p); // on récupère le libellé le plus long
/* calcul du positionnement */
// W = longueur du svg
// M = marge (utilisée pour séparer les éléments)
// m = marge de manoeuvre
// n = nombre d'éléments (points du parcours)
// t = longueur du libellé le plus long
$m = 10; // marge de manoeuvre
$t = $maxLettres * $lettrePixel; // longueur du libellé le plus long (px)
$n = count($parcours); // nombre d'élements du parcours
$M = $m + $t/2; // taille de la marge
$W = 2*$M*$n + 2;
/* paramètres graphiques */
$line = array( 'x' => $M, 'y' => '57', 'width' => $W-2*$M, 'height' => 6 );
$dot = array( 'y' => 60, 'r' => ($M <= 20 ) ? $M/3 : 10 );
$text = array( 'y' => 30 );
$themes = array( // couleur des thèmes
'pamplemousse' => '#f34e4e',
'paprika' => '#c42019',
'banana' => '#f3c04e',
'tomato' => '#d50000',
'twitter' => '#30b6ea',
'facebook' => '#3372c5'
);
/* CHOIX DU THEME */
$themeColor = $themes['tomato'];
/****************/
/* DEBUT DU SVG */
/****************/
echo "<svg height='100' width='".($W + 2*$m)."'>";
// [1] ligne de liaison
echo "<rect x='".$line['x']."' y='".$line['y']."' width='".$line['width']."' height='".$line['height']."' fill='".$themeColor."' />";
// [3] points d'ancrages
for($i = 0 ; $i < $n ; $i++){
$ti = $lettrePixel * strlen( $parcours[$i] ); // longueur du texte actuel
echo "<text x='".($M+2*$M*$i - $ti/2)."' y='".$text['y']."' fill='".$themeColor."' style='font-family:Ubuntu;font-size:20px;'>".$parcours[$i]."</text>";
echo "<circle cx='".($M+2*$M*$i)."' cy='".$dot['y']."' r='".$dot['r']."' stroke='".$themeColor."' stroke-width='".(.8*$dot['r'])."' fill='white'/>";
}
echo "</svg>";
/**************/
/* FIN DU SVG */
/**************/
?>