Source for file xml2pdf.graph.hbar.php

Documentation is available at xml2pdf.graph.hbar.php

  1. <?php
  2. /**
  3.  * Xml2Pdf horizontal bar graph plugin file.
  4.  * @filesource
  5.  *
  6.  * @author guillaume l. <guillaume@geelweb.org>
  7.  * @link http://www.geelweb.org geelweb-dot-org
  8.  * @license http://opensource.org/licenses/bsd-license.php BSD License
  9.  * @copyright copytight © 2006, guillaume luchet
  10.  * @version 0.6.10.8
  11.  * @package Xml2Pdf
  12.  * @subpackage Graph
  13.  */
  14.  
  15. /**
  16.  * Plugin class xml2pdf_graph_hbar
  17.  * 
  18.  * Draw an horizontal bar graph .
  19.  *
  20.  * <code>
  21.  * <graph type='hbar' width='100' height='30' left='80' top='-30' legend='%l : %v (%p)' max='190'>
  22.  *   <value legend='valeur' data='150'/>
  23.  *   <value legend='moins' data='42'/>
  24.  *   <value legend='plus' data='180'/>
  25.  * </graph>
  26.  * </code>
  27.  *
  28.  * @author guillaume l. <guillaume@geelweb.org>
  29.  * @link http://www.geelweb.org geelweb-dot-org
  30.  * @license http://opensource.org/licenses/bsd-license.php BSD License
  31.  * @copyright copytight © 2006, guillaume luchet
  32.  * @version 0.6.10.8
  33.  * @package Xml2Pdf
  34.  * @subpackage Graph
  35.  * @tutorial Xml2Pdf/Xml2Pdf.Graph.hbar.pkg
  36.  */
  37. class xml2pdf_graph_hbar { // {{{
  38.     
  39.     // xml2pdf_graph_hbar::__construct() {{{
  40.     
  41.         
  42.     /**
  43.      * Constructor.
  44.      *
  45.      * Draw an horizontal bar graph.
  46.      *
  47.      * @param Object $graph object Xml2Pdf_Tag_graph
  48.      * @return void 
  49.      */
  50.     public function __construct($graph) {
  51.         $graph->pdf->SetFont('Courier', '', $graph->fontSize);
  52.         $graph->setLegends();
  53.  
  54.         $XPage = $graph->pdf->GetX();
  55.         $YPage = $graph->pdf->GetY();
  56.         $marge = 2;
  57.         $YDiag = $YPage + $marge;
  58.         $hDiag = floor($graph->height - $marge * 2);
  59.         $XDiag = $XPage + $marge * 2 + $graph->legendWidth;
  60.         $lDiag = floor($graph->width - $marge * 3 - $graph->legendWidth);
  61.         if($graph->color == null) {
  62.             $graph->color = Xml2Pdf::getColor();
  63.         }
  64.         if ($graph->maxValRepere == 0) {
  65.             $graph->maxValRepere = max($graph->data);
  66.         }
  67.         $valIndRepere = ceil($graph->maxValRepere / $graph->nbIndRepere);
  68.         $graph->maxValRepere = $valIndRepere * $graph->nbIndRepere;
  69.         $lRepere = floor($lDiag / $graph->nbIndRepere);
  70.         $lDiag = $lRepere * $graph->nbIndRepere;
  71.         $unite = $lDiag / $graph->maxValRepere;
  72.         $hBaton = floor($hDiag / ($graph->nbVal + 1));
  73.         $hDiag = $hBaton * ($graph->nbVal + 1);
  74.         $eBaton = floor($hBaton * 80 / 100);
  75.  
  76.         $graph->pdf->SetLineWidth(0.2);
  77.         $graph->pdf->Rect($XDiag, $YDiag, $lDiag, $hDiag);
  78.  
  79.         //Echelles
  80.         $tab = Xml2Pdf::ConvertColor('#dcdcdc');
  81.         $graph->pdf->SetDrawColor($tab['r'],$tab['g'],$tab['b']);
  82.         for ($i=0 ; $i<=$graph->nbIndRepere ; $i++) {
  83.             $xpos = $XDiag + $lRepere * $i;
  84.             if($i>0 && $i<$graph->nbIndRepere) {
  85.                 $graph->pdf->Line($xpos, $YDiag, $xpos, $YDiag + $hDiag);
  86.             }
  87.             $val = $i * $valIndRepere;
  88.             $xpos = $XDiag + $lRepere * $i - $graph->pdf->GetStringWidth($val) / 2;
  89.             $ypos = $YDiag + $hDiag - $marge;
  90.             $graph->pdf->Text($xpos, $ypos, $val);
  91.         }
  92.  
  93.         $tab = Xml2Pdf::ConvertColor('#000000');
  94.         $graph->pdf->SetDrawColor($tab['r'],$tab['g'],$tab['b']);
  95.         $graph->pdf->SetFont('Courier', '', $graph->fontSize);
  96.         $tab = Xml2Pdf::ConvertColor($graph->color);
  97.         $graph->pdf->SetFillColor($tab['r'], $tab['g'], $tab['b']);
  98.         $i=0;
  99.         foreach($graph->data as $val) {
  100.             //Barre
  101.             $xval = $XDiag;
  102.             $lval = (int)($val * $unite);
  103.             $yval = $YDiag + ($i + 1) * $hBaton - $eBaton / 2;
  104.             $hval = $eBaton;
  105.             $graph->pdf->Rect($xval, $yval, $lval, $hval, 'DF');
  106.             //Légende
  107.             $graph->pdf->SetXY(0, $yval);
  108.             $graph->pdf->Cell($xval - $marge, $hval, $graph->legends[$i],0,0,'R');
  109.             $i++;
  110.         }
  111.     }
  112.     
  113.     // }}}
  114. } // }}}
  115.  
  116. ?>

Documentation generated on Wed, 11 Oct 2006 22:27:14 +0200 by phpDocumentor 1.3.0