Source for file xml2pdf.graph.vbar.php

Documentation is available at xml2pdf.graph.vbar.php

  1. <?php
  2. /**
  3.  * Xml2Pdf vertical 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_vbar
  17.  * 
  18.  * Draw a vertical bar graph.
  19.  *
  20.  * <code>
  21.  * <graph type='vbar' width='100' height='100' color='#0197cb' legend='%l' max='190' repere='10'>
  22.  *   <value legend='2003' data='150'/>
  23.  *   <value legend='2004' data='42'/>
  24.  *   <value legend='2005' 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.vbar.pkg
  36.  */
  37. class xml2pdf_graph_vbar { // {{{
  38.     
  39.     // xml2pdf_graph_vbar::__construct() {{{    
  40.     
  41.         
  42.     /**
  43.      * Constructeur
  44.      *
  45.      * Draw a vertical 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;
  60.         $lDiag = floor($graph->width - $marge * 3);
  61.         if($graph->color == null) {
  62.             $graph->color = Xml2Pdf::getColor();
  63.         }
  64.         if (!$graph->maxValRepere) {
  65.             $graph->maxValRepere = max($graph->data);
  66.         }
  67.         $valIndRepere = ceil($graph->maxValRepere / $graph->nbIndRepere);
  68.         $graph->maxValRepere = $valIndRepere * $graph->nbIndRepere;
  69.         $lRepere = floor($hDiag / $graph->nbIndRepere);
  70.         $hDiag = $lRepere * $graph->nbIndRepere;
  71.         $unite = $hDiag / $graph->maxValRepere;
  72.         $hBaton = floor($lDiag / ($graph->nbVal + 1));
  73.         $lDiag = $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.             $ypos = $YDiag+$hDiag - $lRepere * $i;
  84.             if($i>0 && $i<$graph->nbIndRepere) {
  85.                 $graph->pdf->Line($XDiag,$ypos , $XDiag + $lDiag,$ypos);
  86.             }
  87.             $val = $i * $valIndRepere;
  88.             $xpos = $XDiag - $graph->pdf->GetStringWidth($val) -5;
  89.             $graph->pdf->Text($xpos, $ypos, $val);
  90.         }
  91.         //Barre
  92.         $tab = Xml2Pdf::ConvertColor('#000000');
  93.         $graph->pdf->SetDrawColor($tab['r'],$tab['g'],$tab['b']);
  94.         $graph->pdf->SetFont('Courier', '', $graph->fontSize);
  95.         $tab = Xml2Pdf::ConvertColor($graph->color);
  96.         $graph->pdf->SetFillColor($tab['r'], $tab['g'], $tab['b']);
  97.         $i=0;
  98.         foreach($graph->data as $val) {
  99.             $lval = $eBaton;
  100.             $hval = (int)($val * $unite);
  101.             $xval = $XDiag + ($i +1) * $hBaton-$eBaton/2;
  102.             $yval = $YDiag+$hDiag-$hval;
  103.             $graph->pdf->Rect($xval, $yval, $lval, $hval, 'DF');
  104.             //Légende
  105.             $graph->pdf->SetXY($xval, $YDiag+$hDiag);
  106.             $graph->pdf->Cell($graph->pdf->GetStringWidth($graph->legends[$i])+$marge, 5, $graph->legends[$i],0,0,'R');
  107.             $i++;
  108.         }
  109.     }
  110.     
  111.     // }}}
  112.     
  113. } // }}}
  114.  
  115. ?>

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