-$svg_colors = Array('red'=>'#ffa0a0', 'green'=>'#a0ffa0', 'yellow'=>'#ffdd80', 'blue'=>'#a0a0ff');
-
-function svg_circle($color, $size=4) {
- global $svg_colors;
- if (array_key_exists($color, $svg_colors)) { $color = $svg_colors[$color]; }
- $r = (int)$size; $cx = $r+1; $cy = $r+1;
- $svg = '<svg width="'.(2+2*$r).'" height="'.(2+2*$r).'" style="margin: 1px; vertical-align: middle;">';
- $svg .= "<circle cx='$cx' cy='$cy' r='$r' stroke='black' stroke-width='0' fill='$color' />";
- $svg .= '</svg>';
- return $svg;
-}
-
-function svg_pie_chart($values, $size=16) {
- global $svg_colors;
- $color_names = Array('blue', 'red', 'green', 'yellow'); $color_idx = 0;
- $total = 0.0; foreach ($values as $v) { $total += $v; }
- $r = (int)$size; $cx = $r+1; $cy = $r+1; $rad = 2*pi()/$total; $old_a = 0;
- $svg = '<svg width="'.(2+2*$r).'" height="'.(2+2*$r).'" style="margin: 2px; vertical-align: middle;">';
- foreach ($values as $a) {
- $color = $svg_colors[$color_names[$color_idx++]];
- if ($a == $total) {
- $svg .= "<circle cx='$cx' cy='$cy' r='$r' stroke='black' stroke-width='0' fill='$color' />";
- } elseif ($a > 0) {
- $x1 = $cx + $r * cos(-$old_a * $rad);
- $y1 = $cy + $r * sin(-$old_a * $rad);
- $x2 = $cx + $r * cos(-($old_a + $a) * $rad);
- $y2 = $cy + $r * sin(-($old_a + $a) * $rad);
- $big = ($a > ($total/2)) ? '1' : '0';
- $svg .= "<path d=\"M$cx,$cy L$x1,$y1 A$r,$r 0 $big,0 $x2,$y2 z\" style=\"stroke: 0 black; fill: $color;\" />";
- }
- $old_a += $a;
- }
- $svg .= '</svg>';
- return $svg;
-}
-
-function svg_bar($values, $width=100, $height=5) {
- global $svg_colors;
- $color_names = Array('blue', 'red', 'green', 'yellow'); $color_idx = 0;
- $total = 0.0; foreach ($values as $v) { $total += $v; }
- $svg = "<svg width='$width' height='$height' style='float: left; margin: 2px; vertical-align: middle;'>";
- $x = 0;
- foreach ($values as $v) {
- $color = $svg_colors[$color_names[$color_idx++]];
- $w = round(($width*$v)/$total);
- if ($w > 0) {
- $svg .= "<rect x='$x' y='0' width='$w' height='$height' style='stroke: 0 black; fill: $color;' />";
- $x += $w;
- }
- }
- $svg .= '</svg>';
- return $svg;
-}
-
-function progression_html($valeurs, $progres) {
- global $svg_bar_width, $svg_bar_height;
- $somme_valeurs = 0; foreach ($valeurs as $v) $somme_valeurs += $v;
- if (!$somme_valeurs) return '';
- $result = svg_bar($valeurs, $svg_bar_width, $svg_bar_height);
- $result .= round((100*$progres)/$somme_valeurs)."%";
- return $result;
-}
-