linea21-externals
[ class tree: linea21-externals ] [ index: linea21-externals ] [ all elements ]

Source for file Grid.class.php

Documentation is available at Grid.class.php

  1. <?php
  2. /*
  3.  * This work is hereby released into the Public Domain.
  4.  * To view a copy of the public domain dedication,
  5.  * visit http://creativecommons.org/licenses/publicdomain/ or send a letter to
  6.  * Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
  7.  *
  8.  */
  9.  
  10. require_once dirname(__FILE__)."/../Graph.class.php";
  11.  
  12. /**
  13.  * Grid
  14.  *
  15.  * @package linea21.externals
  16.  * @subpackage artichow
  17.  */
  18. class awGrid {
  19.  
  20.   /**
  21.    * Vertical lines of the grid
  22.    *
  23.    * @var array 
  24.    */
  25.   var $xgrid array();
  26.  
  27.   /**
  28.    * Horizontal lines of the grid
  29.    *
  30.    * @var array 
  31.    */
  32.   var $ygrid array();
  33.  
  34.   /**
  35.    * Is the component grid hidden ?
  36.    *
  37.    * @var bool 
  38.    */
  39.   var $hide FALSE;
  40.  
  41.   /**
  42.    * Are horizontal lines hidden ?
  43.    *
  44.    * @var bool 
  45.    */
  46.   var $hideHorizontal FALSE;
  47.  
  48.   /**
  49.    * Are vertical lines hidden ?
  50.    *
  51.    * @var bool 
  52.    */
  53.   var $hideVertical FALSE;
  54.  
  55.   /**
  56.    * Grid color
  57.    *
  58.    * @var Color 
  59.    */
  60.   var $color;
  61.  
  62.   /**
  63.    * Grid space
  64.    *
  65.    * @var int 
  66.    */
  67.   var $space;
  68.  
  69.   /**
  70.    * Line type
  71.    *
  72.    * @var int 
  73.    */
  74.   var $type LINE_SOLID;
  75.  
  76.   /**
  77.    * Grid interval
  78.    *
  79.    * @var int 
  80.    */
  81.   var $interval array(11);
  82.  
  83.   /**
  84.    * Grid background color
  85.    *
  86.    * @var Color 
  87.    */
  88.   var $background;
  89.  
  90.   /**
  91.    * Build the factory
  92.    */
  93.   function awGrid({
  94.  
  95.     // Set a grid default color
  96.     $this->color new awColor(210210210);
  97.     $this->background new awColor(255255255100);
  98.  
  99.   }
  100.  
  101.   /**
  102.    * Hide grid ?
  103.    *
  104.    * @param bool $hide 
  105.    */
  106.   function hide($hide TRUE{
  107.     $this->hide = (bool)$hide;
  108.   }
  109.  
  110.   /**
  111.    * Hide horizontal lines ?
  112.    *
  113.    * @param bool $hideHorizontal 
  114.    */
  115.   function hideHorizontal($hide TRUE{
  116.     $this->hideHorizontal = (bool)$hide;
  117.   }
  118.  
  119.   /**
  120.    * Hide vertical lines ?
  121.    *
  122.    * @param bool $hideVertical 
  123.    */
  124.   function hideVertical($hide TRUE{
  125.     $this->hideVertical = (bool)$hide;
  126.   }
  127.  
  128.   /**
  129.    * Change grid color
  130.    *
  131.    * @param $color 
  132.    */
  133.   function setColor($color{
  134.     $this->color $color;
  135.   }
  136.  
  137.   /**
  138.    * Remove grid background
  139.    */
  140.   function setNoBackground({
  141.     $this->background NULL;
  142.   }
  143.  
  144.   /**
  145.    * Change grid background color
  146.    *
  147.    * @param $color 
  148.    */
  149.   function setBackgroundColor($color{
  150.     $this->background $color;
  151.   }
  152.  
  153.   /**
  154.    * Change line type
  155.    *
  156.    * @param int $type 
  157.    */
  158.   function setType($type{
  159.     $this->type = (int)$type;
  160.   }
  161.  
  162.   /**
  163.    * Change grid interval
  164.    *
  165.    * @param int $hInterval 
  166.    * @param int $vInterval 
  167.    */
  168.   function setInterval($hInterval$vInterval{
  169.     $this->interval array((int)$hInterval(int)$vInterval);
  170.   }
  171.  
  172.   /**
  173.    * Set grid space
  174.    *
  175.    * @param int $left Left space in pixels
  176.    * @param int $right Right space in pixels
  177.    * @param int $top Top space in pixels
  178.    * @param int $bottom Bottom space in pixels
  179.    */
  180.   function setSpace($left$right$top$bottom{
  181.     $this->space array((int)$left(int)$right(int)$top(int)$bottom);
  182.   }
  183.  
  184.   /**
  185.    * Change the current grid
  186.    *
  187.    * @param array $xgrid Vertical lines
  188.    * @param array $ygrid Horizontal lines
  189.    */
  190.   function setGrid($xgrid$ygrid{
  191.  
  192.     if(empty($this->xgrid)) {
  193.       $this->xgrid $xgrid;
  194.     }
  195.     if(empty($this->ygrid)) {
  196.       $this->ygrid $ygrid;
  197.     }
  198.  
  199.   }
  200.  
  201.   /**
  202.    * Draw grids
  203.    *
  204.    * @param $driver A driver object
  205.    * @param int $x1 
  206.    * @param int $y1 
  207.    * @param int $x2 
  208.    * @param int $y2 
  209.    */
  210.   function draw($driver$x1$y1$x2$y2{
  211.  
  212.     if(is_a($this->background'awColor')) {
  213.  
  214.       // Draw background color
  215.       $driver->filledRectangle(
  216.       $this->background,
  217.       awLine::build($x1$y1$x2$y2)
  218.       );
  219.           
  220.     }
  221.  
  222.     if($this->hide === FALSE{
  223.           
  224.       $this->drawGrid(
  225.       $driver,
  226.       $this->color,
  227.       $this->hideVertical array($this->xgrid,
  228.       $this->hideHorizontal array($this->ygrid,
  229.       $x1$y1$x2$y2,
  230.       $this->type,
  231.       $this->space,
  232.       $this->interval[0],
  233.       $this->interval[1]
  234.       );
  235.           
  236.     }
  237.  
  238.   }
  239.  
  240.   function drawGrid(
  241.   $driver$color,
  242.   $nx$ny$x1$y1$x2$y2,
  243.   $type$space$hInterval$vInterval
  244.   {
  245.  
  246.     list($left$right$top$bottom$space;
  247.  
  248.     $width $x2 $x1 $left $right;
  249.     $height $y2 $y1 $top $bottom;
  250.  
  251.     foreach($nx as $key => $n{
  252.  
  253.       if(($key $vInterval=== 0{
  254.  
  255.         $pos = (int)round($x1 $left $n $width);
  256.         $driver->line(
  257.         $color,
  258.         new awLine(
  259.         new awPoint($pos$y1),
  260.         new awPoint($pos$y2),
  261.         $type
  262.         )
  263.         );
  264.  
  265.       }
  266.  
  267.     }
  268.  
  269.     foreach($ny as $key => $n{
  270.  
  271.       if(($key $hInterval=== 0{
  272.  
  273.         $pos = (int)round($y1 $top $n $height);
  274.         $driver->line(
  275.         $color,
  276.         new awLine(
  277.         new awPoint($x1$pos),
  278.         new awPoint($x2$pos),
  279.         $type
  280.         )
  281.         );
  282.  
  283.       }
  284.  
  285.     }
  286.  
  287.   }
  288.  
  289. }
  290.  
  291. registerClass('Grid');
  292. ?>

Documentation generated on Thu, 03 May 2012 15:04:59 +0200 by phpDocumentor 1.4.1