<?

/* after the example of http://www.netbulge.com/index.php?session=0&action=read&click=open&article=1136832897
   - thank you!
*/

header('Content-type: image/svg+xml');
echo 
'<?xml version="1.0" standalone="no"?>';

?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<?

if ($_GET['titel']){
  
$title $_GET['titel'];
  
reset($_GET);
  for(
$i 1$i <= 10$i++){
    
$e[$i] = next($_GET);
    
$a[$i] = next($_GET);
    
$ez[$i] = next($_GET);
    
$az[$i] = next($_GET);
  }
}
else
  
$title "Test-Text";

$width 500;
$height 315;
$y_axis 50;

/* Einkommensmaximum ermitteln */
$max 1;
for (
$i 2$i <= 10$i++)
  if(
$e[$i] > $e[$max])
    
$max $i;

$faktor 260 / ($e[$max] + $a[$max]);
$x_axis = (10 $faktor $e[$max]);

echo 
'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ' $width ' ' $height '" width="' $width '" height="' $height '" xmlns:xlink="http://www.w3.org/1999/xlink">';

echo 
"\n\n<line x1='" $y_axis "' x2='" $y_axis "' y1='0' y2='" $height "' style='stroke: #000000; stroke-width: 0.5px;'/>\n";
echo 
"<line x1='" $y_axis "' x2='" $width "' y1='280' y2='280' style='stroke: #000000; stroke-width: 0.5px;'/>\n";
echo 
"<line x1='" $y_axis "' x2='" $width "' y1='" $x_axis "' y2='" $x_axis "' style='stroke: #000000; stroke-width: 0.5px;'/>\n\n";

/* Erzeuge Beschriftung der y-Achse und horizontale Linien: */
$bit $e[$max] / 10;
for (
$j 1$j <=10$j++){
  
$step round($j $bit);
  
$sy = ($x_axis $faktor $step);
  echo 
"<text x='" . ($step 10030 24) . "' y='" $sy "' fill='black' font-size='10'>" $step "</text>\n";
  echo 
"<line x1='" $y_axis "' x2='" $width "' y1='" $sy "' y2='" $sy "' style='stroke: #333333; stroke-width: 0.3px;'/>\n";
}
$debt_y 0;
while (
$debt_y < ($a[$max] - $bit)){
  
$debt_y += $bit;
  
$step round($debt_y);
  
$sy = ($x_axis $faktor $step);
  echo 
"<text x='25' y='" $sy "' fill='black' font-size='10'>-" $step "</text>\n";
  echo 
"<line x1='" $y_axis "' x2='" $width "' y1='" $sy "' y2='" $sy "' style='stroke: #333333; stroke-width: 0.3px;'/>\n";
}

echo 
"<text x='17' y='" . ($x_axis 1.5) . "' transform='rotate(270, 17, " . ($x_axis 1.5) . ")' font-size='10'>thousand € per household and year</text>";

/* Beschriftung der X-Achse: */

echo "<text x='" . (($width 20) * 0.33 20) . "' y='" . ($height 5) . "' font-size='10'>household group (decile)</text>";

$b_width = ($width $y_axis) / 10;

/* Erzeuge die Balken: */
for ($i 1$i <= 10$i++){
  
$x_point $y_axis $i $b_width 0.5 $b_width;
  echo 
"<line x1='" $x_point "' x2='" $x_point "' y1='" $x_axis "' y2='" . ($x_axis - ($e[$i] * $faktor)) . "' style='stroke: #00ff00; stroke-width: 30px;'/>\n";
  echo 
"<line x1='" $x_point "' x2='" $x_point "' y1='" $x_axis "' y2='" . ($x_axis - ($ez[$i] * $faktor)) . "' style='stroke: #009900; stroke-width: 30px;'/>\n";
  echo 
"<line x1='" $x_point "' x2='" $x_point "' y1='" $x_axis "' y2='" . ($x_axis + ($a[$i] * $faktor)) . "' style='stroke: #3333ff; stroke-width: 30px;'/>\n";
  echo 
"<line x1='" $x_point "' x2='" $x_point "' y1='" $x_axis "' y2='" . ($x_axis + ($az[$i] * $faktor)) . "' style='stroke: #000066; stroke-width: 30px;'/>\n";
  echo 
"<line x1='" $x_point "' x2='" $x_point "' y1='" $x_axis "' y2='" . ($x_axis + ($az[$i] - $ez[$i]) * $faktor) . "' style='stroke: #ff0000; stroke-width: 10px;'/>\n";
  echo 
"<text x='" . ($i == 10$x_point $x_point 1) . "' y='295' fill='black' font-size='10'>" $i "</text>\n";
}  

/* Debug: */
/*  echo "<text x='60' y='20' fill='black' font-size='10'>" . $max . " : " . $e[$max] . "</text>\n"; */

?>

<line x1='58' y1='17' x2='180' y2='17' style='stroke: #00ff00; stroke-width: 20px;'/>
<line x1='100' y1='17' x2='210' y2='17' style='stroke: #009900; stroke-width: 20px;'/>
  <text x='60' y='20' fill='black' font-size='10'>income / interest included</text>

<line x1='58' y1='47' x2='130' y2='47' style='stroke: #3333ff; stroke-width: 20px;'/>
<line x1='110' y1='47' x2='210' y2='47' style='stroke: #000066; stroke-width: 20px;'/>
<text x='60' y='50' fill='white' font-size='10'>expenses / interest burden</text>

<line x1='58' y1='77' x2='150' y2='77' style='stroke: #ff0000; stroke-width: 12px;'/>
<text x='60' y='80' fill='black' font-size='10'>interest balance</text>

</svg>