<?php
 
$blob_status=5; 
$pies=[1,2,3,4,5,6];
 
function GetColorPieByState($state){    
    switch ($state) {
        case 1:$color="#2afc24";break;  
        case 2:$color="#2afc24";break;  
        case 3:$color="#fc2424";break;  
        case 4:$color="#fc2424";break;  
        case 5:$color="#fc2424";break;  
        case 6:$color="#cccccc";break;  
        default:$color="#7DD8B5";break; 
    }
    return $color;
};
 
function String2Array($st){
    $st=mb_substr($st, 0, -1);
    return explode(",", $st);
};
 
function GetColorBlobByState($state){    
    $station_fill="#D1FFB4";
    if ($state==1) $station_fill="#2afc24";
    if ($state==2) $station_fill="#fc2424";
    if ($state==3) $station_fill="#fc2424";
    if ($state==4) $station_fill="#fc2424";
    if ($state==5) $station_fill="#cccccc";
    return $station_fill;
};
 
function SaveSvgBlobIco($blob_status,$pies,$filename){
    
}
 
Draw($blob_status,$pies);
 
function Draw($blob_status,$pies){
    
    $station_fill=GetColorBlobByState($blob_status);
 
    $svg="";
    $svg=$svg.'<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="200" height="264">';
    $svg=$svg."<defs>";
    $svg=$svg."    <style>";
    $svg=$svg."        .blob_fill {fill:$station_fill;}"; /*Цвет капли*/       
    $svg=$svg.'    </style>';
    $svg=$svg.'</defs>';
    //Рисунок капли
    $svg=$svg.'   <path class="blob_fill" d="m199.10001,101.02451c0,90.53423 -99.52251,161.55548 -99.52251,161.55548s-99.5775,-76.21059 -99.5775,-161.55548a99.55,101.0245 0 0 1 199.10001,0z" id="svg_1"/>';
    //Буква й
    $svg=$svg.'   <text transform="matrix(7.0814, 0, 0, 6.46509, -382.002, -470.036)" xml:space="preserve" text-anchor="start" font-family="Helvetica, Arial, sans-serif" font-size="24" id="svg_3" y="94.56099" x="61.67799" stroke-opacity="null" stroke-width="0" stroke="null" fill="#EDFFFF">й</text>';
 
    $svg=$svg.'<g style="stroke:black;stroke-width:1">';
 
    function pt($x,$y,$rad,$gap,$r,$ang,$mns=-1){ 
      //global $x,$y,$rad,$gap;      
      $a=($ang-90)*$rad-$mns*asin($gap/$r); 
      return sprintf('%0.2f,%0.2f',$x+$r*cos($a),$y+$r*sin($a));
    }
 
    $x=100;
    $y=100;
    $r=60;  // внутренний радиус
    $rc=90; // внешний радиус
    $gap=20; // отступ между кусками
    $a360=360/count($pies); 
    $M_PI=3.14159265358; 
    $rad=$M_PI/180.;
    $out='';
    $ang1=0;      
 
 
    foreach ($pies as $connector) {  
      $dang = 1 * $a360;       
      $laf  = $dang > 180? 1 : 0; 
      $ang2 = $ang1 + $dang;      
      $out.= '<path d="M'.pt($x,$y,$rad,$gap,$rc,$ang1).'L'.pt($x,$y,$rad,$gap,$r, $ang1)."A $r,$r, 0,$laf,1 "  .pt($x,$y,$rad,$gap,$r,$ang2,1).
                      'L'.pt($x,$y,$rad,$gap,$rc,$ang2,1)."A $rc,$rc, 0,$laf,0, ".pt($x,$y,$rad,$gap,$rc,$ang1).'" style="fill:'.GetColorPieByState($connector).'" />'."\n";
      $ang1=$ang2;
    }
    $svg=$svg.$out;
    $svg=$svg.'</g></svg>';
    echo $svg;
};
?>