예제 #1
0
 /**
  * Draw an horizontal bar graph.
  *
  * @param Object $graph object xml2pdf_tag_graph
  * @return void 
  */
 public static function render($graph)
 {
     $graph->pdf->SetFont('Courier', '', $graph->fontSize);
     $graph->setLegends();
     $XPage = $graph->pdf->GetX();
     $YPage = $graph->pdf->GetY();
     $marge = 2;
     $YDiag = $YPage + $marge;
     $hDiag = floor($graph->height - $marge * 2);
     $XDiag = $XPage + $marge * 2 + $graph->legendWidth;
     $lDiag = floor($graph->width - $marge * 3 - $graph->legendWidth);
     if ($graph->color == null) {
         $graph->color = Xml2Pdf::getColor();
     }
     if ($graph->maxValRepere == 0) {
         $graph->maxValRepere = max($graph->data);
     }
     $valIndRepere = ceil($graph->maxValRepere / $graph->nbIndRepere);
     $graph->maxValRepere = $valIndRepere * $graph->nbIndRepere;
     $lRepere = floor($lDiag / $graph->nbIndRepere);
     $lDiag = $lRepere * $graph->nbIndRepere;
     $unite = $lDiag / $graph->maxValRepere;
     $hBaton = floor($hDiag / ($graph->nbVal + 1));
     $hDiag = $hBaton * ($graph->nbVal + 1);
     $eBaton = floor($hBaton * 80 / 100);
     $graph->pdf->SetLineWidth(0.2);
     $graph->pdf->Rect($XDiag, $YDiag, $lDiag, $hDiag);
     //Echelles
     $tab = Xml2Pdf::ConvertColor('#dcdcdc');
     $graph->pdf->SetDrawColor($tab['r'], $tab['g'], $tab['b']);
     for ($i = 0; $i <= $graph->nbIndRepere; $i++) {
         $xpos = $XDiag + $lRepere * $i;
         if ($i > 0 && $i < $graph->nbIndRepere) {
             $graph->pdf->Line($xpos, $YDiag, $xpos, $YDiag + $hDiag);
         }
         $val = $i * $valIndRepere;
         $xpos = $XDiag + $lRepere * $i - $graph->pdf->GetStringWidth($val) / 2;
         $ypos = $YDiag + $hDiag - $marge;
         $graph->pdf->Text($xpos, $ypos, $val);
     }
     $tab = Xml2Pdf::ConvertColor('#000000');
     $graph->pdf->SetDrawColor($tab['r'], $tab['g'], $tab['b']);
     $graph->pdf->SetFont('Courier', '', $graph->fontSize);
     $tab = Xml2Pdf::ConvertColor($graph->color);
     $graph->pdf->SetFillColor($tab['r'], $tab['g'], $tab['b']);
     $i = 0;
     foreach ($graph->data as $val) {
         //Barre
         $xval = $XDiag;
         $lval = (int) ($val * $unite);
         $yval = $YDiag + ($i + 1) * $hBaton - $eBaton / 2;
         $hval = $eBaton;
         $graph->pdf->Rect($xval, $yval, $lval, $hval, 'DF');
         //Légende
         $graph->pdf->SetXY(0, $yval);
         $graph->pdf->Cell($xval - $marge, $hval, $graph->legends[$i], 0, 0, 'R');
         $i++;
     }
 }
예제 #2
0
 /**
  * Draw a curve type graph
  *
  * @param Object $graph Object Xml2Pdf_Tag_graph
  * @return void
  */
 public static function render($graph)
 {
     $graph->pdf->SetFont('Courier', '', $graph->fontSize);
     $graph->setLegends();
     $XPage = $graph->pdf->GetX();
     $YPage = $graph->pdf->GetY();
     $marge = 2;
     $hDiag = $graph->height;
     $lDiag = $graph->width - $graph->legendWidth - 5 * $marge - 5;
     $XDiag = $XPage + $marge;
     $YDiag = $YPage + $marge;
     $xMax = 0;
     $yMax = 0;
     foreach ($graph->data as $line) {
         if ($xMax < max($line['x'])) {
             $xMax = max($line['x']);
         }
         if ($yMax < max($line['y'])) {
             $yMax = max($line['y']);
         }
     }
     $uniteX = $lDiag / $xMax;
     $uniteY = $hDiag / ($yMax + 5);
     $graph->pdf->SetLineWidth(0.2);
     $graph->pdf->Rect($XDiag, $YDiag, $lDiag, $hDiag);
     //reperes
     $tab = Xml2Pdf::ConvertColor('#dcdcdc');
     $graph->pdf->SetDrawColor($tab['r'], $tab['g'], $tab['b']);
     $deltaX = $lDiag / $graph->nbIndRepere;
     $deltaY = $hDiag / $graph->nbIndRepere;
     $graph->pdf->SetLineWidth(0.2);
     for ($i = 0; $i <= $graph->nbIndRepere; $i++) {
         if ($i > 0 && $i < $graph->nbIndRepere) {
             $graph->pdf->Line($XDiag, $YDiag + $i * $deltaY, $XDiag + $lDiag, $YDiag + $i * $deltaY);
             $graph->pdf->Line($XDiag + $i * $deltaX, $YDiag, $XDiag + $i * $deltaX, $YDiag + $hDiag);
         }
         $valY = floor(($hDiag - $i * $deltaY) / $uniteY);
         $valX = floor($i * $deltaX / $uniteX);
         $lenY = $graph->pdf->GetStringWidth($valY);
         $lenX = $graph->pdf->GetStringWidth($valX);
         $graph->pdf->Text($XDiag - $lenY - 2, $YDiag + $i * $deltaY, $valY);
         $graph->pdf->Text($XDiag + $i * $deltaX - $lenX / 2, $YDiag + $hDiag + 5, $valX);
     }
     //lignes
     $nbPoint = 0;
     $ligne = 0;
     $graph->pdf->SetLineWidth(0.5);
     foreach ($graph->data as $key => $line) {
         if ($graph->colors[$key] == null) {
             $graph->colors[$key] = Xml2Pdf::getColor();
         }
         $tab = Xml2Pdf::ConvertColor($graph->colors[$key]);
         $graph->pdf->SetDrawColor($tab['r'], $tab['g'], $tab['b']);
         $nbPoint = min(count($line['x']), count($line['y']));
         for ($i = 0; $i < $nbPoint - 1; $i++) {
             $xd = $XDiag + $line['x'][$i] * $uniteX;
             $yd = $YDiag + $hDiag - $line['y'][$i] * $uniteY;
             $xf = $XDiag + $line['x'][$i + 1] * $uniteX;
             $yf = $YDiag + $hDiag - $line['y'][$i + 1] * $uniteY;
             $graph->pdf->Line($xd, $yd, $xf, $yf);
         }
         $ligne++;
     }
     //Légende
     $graph->pdf->SetLineWidth(0.2);
     $tab = Xml2Pdf::ConvertColor('#000000');
     $graph->pdf->SetDrawColor($tab['r'], $tab['g'], $tab['b']);
     $graph->pdf->SetFont('Courier', '', $graph->fontSize);
     $x1 = $XPage + $lDiag + 4 * $marge;
     $x2 = $x1 + 5 + $marge;
     $y1 = $YDiag + 3 * $marge;
     for ($i = 0; $i < $graph->nbVal; $i++) {
         $tab = Xml2Pdf::ConvertColor($graph->colors[$graph->legends[$i]]);
         $graph->pdf->SetFillColor($tab['r'], $tab['g'], $tab['b']);
         $graph->pdf->Rect($x1, $y1 + $i * $marge * 2, 5, 5, 'DF');
         $graph->pdf->SetXY($x2, $y1 + $i * $marge * 2);
         $graph->pdf->Cell(0, 5, $graph->legends[$i]);
         $y1 += $marge;
     }
 }
예제 #3
0
 /**
  * Draw a circular graph
  *
  * @param Object $graph Object Xml2Pdf_Tag_graph
  * @return void 
  */
 public static function render($graph)
 {
     $graph->pdf->SetFont('Courier', '', $graph->fontSize);
     $graph->setLegends();
     $XPage = $graph->pdf->GetX();
     $YPage = $graph->pdf->GetY();
     $marge = 2;
     $hLegende = 5;
     $rayon = min($graph->width - $marge * 4 - $hLegende - $graph->legendWidth, $graph->height - $marge * 2);
     $rayon = floor($rayon / 2);
     $XDiag = $XPage + $marge + $rayon;
     $YDiag = $YPage + $marge + $rayon;
     //Secteurs
     $graph->pdf->SetLineWidth(0.2);
     $loop = $graph->mode == '3d' ? 4 : 1;
     for ($delta = 0; $delta < $loop; $delta++) {
         $angleDebut = 0;
         $angleFin = 0;
         $i = 0;
         reset($graph->data);
         foreach ($graph->data as $val) {
             $angle = floor($val * 360 / doubleval($graph->sum));
             if ($angle != 0) {
                 $angleFin = $angleDebut + $angle;
                 if ($graph->colors[$i] != null) {
                     $tab = Xml2Pdf::ConvertColor($graph->colors[$i]);
                     $graph->pdf->SetFillColor($tab['r'], $tab['g'], $tab['b']);
                 } else {
                     $tab = Xml2Pdf::getColor();
                     $graph->pdf->SetFillColor($tab['r'], $tab['g'], $tab['b']);
                     $graph->colors[$i] = $tab;
                 }
                 if ($delta > 0 && $delta < $loop - 1) {
                     $graph->pdf->SetDrawColor($tab['r'], $tab['g'], $tab['b']);
                 } else {
                     $graph->pdf->SetDrawColor(0, 0, 0);
                 }
                 //$this->sector($XDiag, $YDiag-$delta, $rayon,
                 xml2pdf_graph_circle::sector($XDiag, $YDiag - $delta, $rayon, $angleDebut, $angleFin, $graph->colors[$i]);
                 $angleDebut += $angle;
             }
             $i++;
         }
         if ($angleFin != 360) {
             //$this->sector($XDiag, $YDiag-$delta, $rayon,
             xml2pdf_graph_circle::sector($XDiag, $YDiag - $delta, $rayon, $angleDebut - $angle, 360, $graph->colors[$i - 1]);
         }
     }
     //Légendes
     $graph->pdf->SetFont('Courier', '', $graph->fontSize);
     $x1 = $XPage + 2 * $rayon + 4 * $marge;
     $x2 = $x1 + $hLegende + $marge;
     $y1 = $YDiag - $rayon + (2 * $rayon - $graph->nbVal * ($hLegende + $marge)) / 2;
     for ($i = 0; $i < $graph->nbVal; $i++) {
         $tab = Xml2Pdf::ConvertColor($graph->colors[$i]);
         $graph->pdf->SetFillColor($tab['r'], $tab['g'], $tab['b']);
         $graph->pdf->Rect($x1, $y1, $hLegende, $hLegende, 'DF');
         $graph->pdf->SetXY($x2, $y1);
         $graph->pdf->Cell(0, $hLegende, $graph->legends[$i]);
         $y1 += $hLegende + $marge;
     }
 }