$b) $b +=360; $b = $b/360*2*M_PI; $a = $a/360*2*M_PI; $d = $b-$a; if ($d == 0 ) $d =2*M_PI; $k = $this->k; $hp = $this->h; if($style=='F') $op='f'; elseif($style=='FD' or $style=='DF') $op='b'; else $op='s'; if (sin($d/2)) $MyArc = 4/3*(1-cos($d/2))/sin($d/2)*$r; //first put the center $this->_out(sprintf('%.2f %.2f m',($xc)*$k,($hp-$yc)*$k)); //put the first point $this->_out(sprintf('%.2f %.2f l',($xc+$r*cos($a))*$k,(($hp-($yc-$r*sin($a)))*$k))); //draw the arc if ($d < M_PI/2){ $this->_Arc($xc+$r*cos($a)+$MyArc*cos(M_PI/2+$a), $yc-$r*sin($a)-$MyArc*sin(M_PI/2+$a), $xc+$r*cos($b)+$MyArc*cos($b-M_PI/2), $yc-$r*sin($b)-$MyArc*sin($b-M_PI/2), $xc+$r*cos($b), $yc-$r*sin($b) ); }else{ $b = $a + $d/4; $MyArc = 4/3*(1-cos($d/8))/sin($d/8)*$r; $this->_Arc($xc+$r*cos($a)+$MyArc*cos(M_PI/2+$a), $yc-$r*sin($a)-$MyArc*sin(M_PI/2+$a), $xc+$r*cos($b)+$MyArc*cos($b-M_PI/2), $yc-$r*sin($b)-$MyArc*sin($b-M_PI/2), $xc+$r*cos($b), $yc-$r*sin($b) ); $a = $b; $b = $a + $d/4; $this->_Arc($xc+$r*cos($a)+$MyArc*cos(M_PI/2+$a), $yc-$r*sin($a)-$MyArc*sin(M_PI/2+$a), $xc+$r*cos($b)+$MyArc*cos($b-M_PI/2), $yc-$r*sin($b)-$MyArc*sin($b-M_PI/2), $xc+$r*cos($b), $yc-$r*sin($b) ); $a = $b; $b = $a + $d/4; $this->_Arc($xc+$r*cos($a)+$MyArc*cos(M_PI/2+$a), $yc-$r*sin($a)-$MyArc*sin(M_PI/2+$a), $xc+$r*cos($b)+$MyArc*cos($b-M_PI/2), $yc-$r*sin($b)-$MyArc*sin($b-M_PI/2), $xc+$r*cos($b), $yc-$r*sin($b) ); $a = $b; $b = $a + $d/4; $this->_Arc($xc+$r*cos($a)+$MyArc*cos(M_PI/2+$a), $yc-$r*sin($a)-$MyArc*sin(M_PI/2+$a), $xc+$r*cos($b)+$MyArc*cos($b-M_PI/2), $yc-$r*sin($b)-$MyArc*sin($b-M_PI/2), $xc+$r*cos($b), $yc-$r*sin($b) ); } //terminate drawing $this->_out($op); } function _Arc($x1, $y1, $x2, $y2, $x3, $y3 ) { $h = $this->h; $this->_out(sprintf('%.2f %.2f %.2f %.2f %.2f %.2f c', $x1*$this->k, ($h-$y1)*$this->k, $x2*$this->k, ($h-$y2)*$this->k, $x3*$this->k, ($h-$y3)*$this->k)); } function SetLegends($data, $format) { $this->legends=array(); $this->wLegend=0; $this->sum=array_sum($data); $this->NbVal=count($data); foreach($data as $l=>$val) { $p=sprintf('%.2f',$val/$this->sum*100).'%'; $legend=str_replace(array('%l','%v','%p'),array($l,$val,$p),$format); $this->legends[]=$legend; $this->wLegend=max($this->GetStringWidth($legend),$this->wLegend); } } function DiagCirculaire($largeur, $hauteur, $data, $format, $couleurs=null) { // $this->SetFont('Courier', '', 10); $this->SetLegends($data,$format); $XPage = $this->GetX(); $YPage = $this->GetY(); $marge = 2; $hLegende = 5; $rayon = min($largeur - $marge * 4 - $hLegende - $this->wLegend, $hauteur - $marge * 2); $rayon = floor($rayon / 2); $XDiag = $XPage + $marge + $rayon; $YDiag = $YPage + $marge + $rayon; if($couleurs == null) { for($i = 0;$i < $this->NbVal; $i++) { $gray = $i * intval(255 / $this->NbVal); $couleurs[$i] = array($gray,$gray,$gray); } } //Secteurs $angleDebut = 0; $angleFin = 0; $i = 0; foreach($data as $val) { $angle = floor(($val * 360) / doubleval($this->sum)); if ($angle != 0) { $angleFin = $angleDebut + $angle; $this->SetFillColor($couleurs[$i][0],$couleurs[$i][1],$couleurs[$i][2]); $this->Sector($XDiag, $YDiag, $rayon, $angleDebut, $angleFin); $angleDebut += $angle; } $i++; } if ($angleFin != 360) { $this->Sector($XDiag, $YDiag, $rayon, $angleDebut - $angle, 360); } //Légendes //$this->SetFont('Courier', '', 10); $x1 = $XPage + 2 * $rayon + 4 * $marge; $x2 = $x1 + $hLegende + $marge; $y1 = $YDiag - $rayon + (2 * $rayon - $this->NbVal*($hLegende + $marge)) / 2; for($i=0; $i<$this->NbVal; $i++) { $this->SetFillColor($couleurs[$i][0],$couleurs[$i][1],$couleurs[$i][2]); $this->Rect($x1, $y1, $hLegende, $hLegende, 'DF'); $this->SetXY($x2,$y1); $this->Cell(0,$hLegende,$this->legends[$i]); $y1+=$hLegende + $marge; } } function DiagBatons($largeur, $hauteur, $data, $format, $couleur=null, $maxValRepere=0, $nbIndRepere=4) { //$this->SetFont('Courier', '', 10); $this->SetLegends($data,$format); $XPage = $this->GetX(); $YPage = $this->GetY(); $marge = 2; $YDiag = $YPage + $marge; $hDiag = floor($hauteur - $marge * 2); $XDiag = $XPage + $marge * 2 + $this->wLegend; $lDiag = floor($largeur - $marge * 3 - $this->wLegend); if($couleur == null) $couleur=array(155,155,155); if ($maxValRepere == 0) { $maxValRepere = max($data); } $valIndRepere = ceil($maxValRepere / $nbIndRepere); $maxValRepere = $valIndRepere * $nbIndRepere; $lRepere = floor($lDiag / $nbIndRepere); $lDiag = $lRepere * $nbIndRepere; $unite = $lDiag / $maxValRepere; $hBaton = floor($hDiag / ($this->NbVal + 1)); $hDiag = $hBaton * ($this->NbVal + 1); $eBaton = floor($hBaton * 80 / 100); $this->SetLineWidth(0.2); $this->Rect($XDiag, $YDiag, $lDiag, $hDiag); // $this->SetFont('Courier', '', 10); $this->SetFillColor($couleur[0],$couleur[1],$couleur[2]); $i=0; foreach($data as $val) { //Barre $xval = $XDiag; $lval = (int)($val * $unite); $yval = $YDiag + ($i + 1) * $hBaton - $eBaton / 2; $hval = $eBaton; $this->Rect($xval, $yval, $lval, $hval, 'DF'); //Légende $this->SetXY(0, $yval); $this->Cell($xval - $marge, $hval, $this->legends[$i],0,0,'R'); $i++; } //Echelles for ($i = 0; $i <= $nbIndRepere; $i++) { $xpos = $XDiag + $lRepere * $i; $this->Line($xpos, $YDiag, $xpos, $YDiag + $hDiag); $val = $i * $valIndRepere; $xpos = $XDiag + $lRepere * $i - $this->GetStringWidth($val) / 2; $ypos = $YDiag + $hDiag - $marge; $this->Text($xpos, $ypos, $val); } } } ?>