Source for file xml2pdf.graph.line.php

Documentation is available at xml2pdf.graph.line.php

  1. <?php
  2. /**
  3.  * Xml2Pdf curve 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_line
  17.  * 
  18.  * Draw a curve graph.
  19.  *
  20.  * <code>
  21.  * <graph type='line' width='120' height='50' left='60' top='220' position='absolute' color='#0197cb' legend='' repere='10'>
  22.  *   <line legend='courbe1'>
  23.  *     <point x='0' y='10'/>
  24.  *     <point x='5' y='15'/>
  25.  *     <point x='10' y='22'/>
  26.  *     <point x='15' y='1'/>
  27.  *     <point x='20' y='12'/>
  28.  *     <point x='25' y='15'/>
  29.  *   </line>
  30.  *   <line legend='courbe2' color='#0197cb'>
  31.  *     <point x='0' y='17'/>
  32.  *     <point x='8' y='15'/>
  33.  *     <point x='12' y='5'/>
  34.  *     <point x='15' y='6'/>
  35.  *     <point x='20' y='12'/>
  36.  *     <point x='25' y='8'/>
  37.  *   </line>
  38.  * </graph>
  39.  * </code>
  40.  *
  41.  * @author guillaume l. <guillaume@geelweb.org>
  42.  * @link http://www.geelweb.org geelweb-dot-org
  43.  * @license http://opensource.org/licenses/bsd-license.php BSD License
  44.  * @copyright copytight © 2006, guillaume luchet
  45.  * @version 0.6.10.8
  46.  * @package Xml2Pdf
  47.  * @subpackage Graph
  48.  * @tutorial Xml2Pdf/Xml2Pdf.Graph.line.pkg
  49.  */
  50. class xml2pdf_graph_line // {{{
  51.     
  52.     // xml2pdf_graph_line::__construct() {{{
  53.     
  54.         
  55.     /**
  56.      * Constructor
  57.      *
  58.      * Draw a curve type graph
  59.      *
  60.      * @param Object $graph Object Xml2Pdf_Tag_graph
  61.      * @return void 
  62.      */
  63.     public function __construct($graph{
  64.         $graph->pdf->SetFont('Courier'''$graph->fontSize);
  65.         $graph->setLegends();
  66.  
  67.         $XPage $graph->pdf->GetX();
  68.         $YPage $graph->pdf->GetY();
  69.         $marge 2;
  70.         $hDiag $graph->height;
  71.         $lDiag $graph->width $graph->legendWidth $marge-5;
  72.         $XDiag $XPage $marge;
  73.         $YDiag $YPage $marge;
  74.  
  75.         $xMax=0;
  76.         $yMax=0;
  77.         foreach($graph->data as $line{
  78.             if($xMax max($line['x'])) {
  79.                 $xMax max($line['x']);
  80.             }
  81.             if($yMax max($line['y'])) {
  82.                 $yMax max($line['y']);
  83.             }
  84.         }
  85.  
  86.         $uniteX $lDiag /$xMax;
  87.         $uniteY ($hDiag($yMax+5);
  88.         $graph->pdf->SetLineWidth(0.2);
  89.         $graph->pdf->Rect($XDiag$YDiag$lDiag$hDiag);
  90.  
  91.         //reperes
  92.         $tab Xml2Pdf::ConvertColor('#dcdcdc');
  93.         $graph->pdf->SetDrawColor($tab['r'],$tab['g'],$tab['b']);
  94.  
  95.         $deltaX $lDiag ($graph->nbIndRepere);
  96.         $deltaY $hDiag ($graph->nbIndRepere);
  97.         $graph->pdf->SetLineWidth(0.2);
  98.  
  99.         for($i=$i<=$graph->nbIndRepere $i++{
  100.             if($i>&& $i<$graph->nbIndRepere{
  101.                 $graph->pdf->Line($XDiag$YDiag+($i*$deltaY)
  102.                                   $XDiag+$lDiag$YDiag+($i*$deltaY));
  103.                 $graph->pdf->Line($XDiag+($i*$deltaX)$YDiag
  104.                                   $XDiag+($i*$deltaX)$YDiag+$hDiag);
  105.             }
  106.             $valY floor(($hDiag-($i*$deltaY))/$uniteY);
  107.             $valX floor(($i*$deltaX)/$uniteX);
  108.             $lenY $graph->pdf->GetStringWidth($valY);
  109.             $lenX $graph->pdf->GetStringWidth($valX);
  110.             $graph->pdf->Text($XDiag-$lenY-2$YDiag+($i*$deltaY)$valY);
  111.             $graph->pdf->Text($XDiag+($i*$deltaX)-$lenX/2$YDiag+$hDiag+5$valX);
  112.         }
  113.         //lignes
  114.         $nbPoint=0;
  115.         $ligne=0;
  116.         $graph->pdf->SetLineWidth(0.5);
  117.         foreach($graph->data as $key=>$line{
  118.             if ($graph->colors[$key== null{
  119.                 $graph->colors[$keyXml2Pdf::getColor();
  120.             }
  121.             $tab Xml2Pdf::ConvertColor($graph->colors[$key]);
  122.             $graph->pdf->SetDrawColor($tab['r'],$tab['g'],$tab['b']);
  123.             $nbPoint=min(count($line['x'])count($line['y']));
  124.             for($i=$i<$nbPoint-$i++{
  125.                 $xd $XDiag $line['x'][$i]*$uniteX;
  126.                 $yd $YDiag$hDiag-$line['y'][$i]*$uniteY;
  127.                 $xf $XDiag $line['x'][$i+1]*$uniteX;
  128.                 $yf $YDiag$hDiag-$line['y'][$i+1]*$uniteY;
  129.                 $graph->pdf->Line($xd$yd$xf$yf);
  130.             }
  131.             $ligne++;
  132.         }
  133.         //Légende
  134.         $graph->pdf->SetLineWidth(0.2);
  135.         $tab Xml2Pdf::ConvertColor('#000000');
  136.         $graph->pdf->SetDrawColor($tab['r'],$tab['g'],$tab['b']);
  137.  
  138.         $graph->pdf->SetFont('Courier'''$graph->fontSize);
  139.         $x1 $XPage $lDiag $marge;
  140.         $x2 $x1 $marge;
  141.         $y1 $YDiag +3*$marge;
  142.         for($i=0$i<$graph->nbVal$i++{
  143.             $tab Xml2Pdf::ConvertColor($graph->colors[$graph->legends[$i]]);
  144.             $graph->pdf->SetFillColor($tab['r'],$tab['g'],$tab['b']);
  145.             $graph->pdf->Rect($x1$y1+$i*$marge*25,5'DF');
  146.             $graph->pdf->SetXY($x2,$y1+$i*$marge*2);
  147.             $graph->pdf->Cell(0,5,$graph->legends[$i]);
  148.             $y1+= $marge;
  149.         }
  150.     }
  151.     
  152.     // }}}
  153.     
  154. // }}}
  155. ?>

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