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

Source for file Tick.class.php

Documentation is available at Tick.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. /* <php4> */
  13.  
  14. define("TICK_IN"0);
  15. define("TICK_OUT"1);
  16. define("TICK_IN_OUT"2);
  17.  
  18. /* </php4> */
  19.  
  20. /**
  21.  * Handle ticks
  22.  *
  23.  * @package linea21.externals
  24.  * @subpackage artichow
  25.  */
  26. class awTick {
  27.  
  28.     /**
  29.      * Ticks style
  30.      *
  31.      * @var int 
  32.      */
  33.     var $style = TICK_IN;
  34.  
  35.     /**
  36.      * Ticks size
  37.      *
  38.      * @var int 
  39.      */
  40.     var $size;
  41.  
  42.     /**
  43.      * Ticks color
  44.      *
  45.      * @var Color 
  46.      */
  47.     var $color;
  48.  
  49.     /**
  50.      * Ticks number
  51.      *
  52.      * @var int 
  53.      */
  54.     var $number;
  55.  
  56.     /**
  57.      * Ticks number by other tick
  58.      *
  59.      * @var array 
  60.      */
  61.     var $numberByTick;
  62.  
  63.     /**
  64.      * Ticks interval
  65.      *
  66.      * @var int 
  67.      */
  68.     var $interval = 1;
  69.  
  70.     /**
  71.      * Hide ticks
  72.      *
  73.      * @var bool 
  74.      */
  75.     var $hide = FALSE;
  76.  
  77.     /**
  78.      * Hide first tick
  79.      *
  80.      * @var bool 
  81.      */
  82.     var $hideFirst = FALSE;
  83.  
  84.     /**
  85.      * Hide last tick
  86.      *
  87.      * @var bool 
  88.      */
  89.     var $hideLast = FALSE;
  90.     
  91.     /**
  92.      * In mode
  93.      *
  94.      * @param int 
  95.      */
  96.     
  97.     
  98.     /**
  99.      * Out mode
  100.      *
  101.      * @param int 
  102.      */
  103.     
  104.     
  105.     /**
  106.      * In and out mode
  107.      *
  108.      * @param int 
  109.      */
  110.     
  111.     
  112.     /**
  113.      * Build the ticks
  114.      *
  115.      * @param int $number Number of ticks
  116.      * @param int $size Ticks size
  117.      */
  118.      function awTick($number$size{
  119.         
  120.         $this->setSize($size);
  121.         $this->setNumber($number);
  122.         $this->setColor(new awBlack);
  123.         $this->style = TICK_IN;
  124.     
  125.     }
  126.     
  127.     /**
  128.      * Change ticks style
  129.      *
  130.      * @param int $style 
  131.      */
  132.      function setStyle($style{
  133.         $this->style = (int)$style;
  134.     }
  135.     
  136.     /**
  137.      * Get ticks style
  138.      *
  139.      * @return int 
  140.      */
  141.      function getStyle({
  142.         return $this->style;
  143.     }
  144.     
  145.     /**
  146.      * Change ticks color
  147.      *
  148.      * @param $color 
  149.      */
  150.      function setColor($color{
  151.         $this->color = $color;
  152.     }
  153.     
  154.     /**
  155.      * Change ticks size
  156.      *
  157.      * @param int $size 
  158.      */
  159.      function setSize($size{
  160.         $this->size = (int)$size;
  161.     }
  162.     
  163.     /**
  164.      * Change interval of ticks
  165.      *
  166.      * @param int $interval 
  167.      */
  168.      function setInterval($interval{
  169.         $this->interval = (int)$interval;
  170.     }
  171.     
  172.     /**
  173.      * Get interval between each tick
  174.      *
  175.      * @return int 
  176.      */
  177.      function getInterval({
  178.         return $this->interval;
  179.     }
  180.     
  181.     /**
  182.      * Change number of ticks
  183.      *
  184.      * @param int $number 
  185.      */
  186.      function setNumber($number{
  187.         $this->number = (int)$number;
  188.     }
  189.     
  190.     /**
  191.      * Get number of ticks
  192.      *
  193.      * @return int 
  194.      */
  195.      function getNumber({
  196.         return $this->number;
  197.     }
  198.     
  199.     /**
  200.      * Change number of ticks relative to others ticks
  201.      *
  202.      * @param &$tick Ticks reference
  203.      * @param int $number Number of ticks
  204.      */
  205.      function setNumberByTick(&$tick$number{
  206.         
  207.         $this->numberByTick = array(&$tick(int)$number);
  208.         
  209.     }
  210.     
  211.     /**
  212.      * Hide ticks
  213.      *
  214.      * @param bool $hide 
  215.      */
  216.      function hide($hide{
  217.         $this->hide = (bool)$hide;
  218.     }
  219.     
  220.     /**
  221.      * Hide first tick
  222.      *
  223.      * @param bool $hide 
  224.      */
  225.      function hideFirst($hide{
  226.         $this->hideFirst = (bool)$hide;
  227.     }
  228.     
  229.     /**
  230.      * Hide last tick
  231.      *
  232.      * @param bool $hide 
  233.      */
  234.      function hideLast($hide{
  235.         $this->hideLast = (bool)$hide;
  236.     }
  237.     
  238.     /**
  239.      * Draw ticks on a vector
  240.      *
  241.      * @param $driver A driver
  242.      * @param &$vector A vector
  243.      */
  244.      function draw($driver&$vector{
  245.         
  246.         if($this->numberByTick !== NULL{
  247.             list($tick$number$this->numberByTick;
  248.             $this->number = ($tick->getNumber(1($number 1);
  249.             $this->interval = $tick->getInterval();
  250.         }
  251.         
  252.         if($this->number < or $this->hide{
  253.             return;
  254.         }
  255.         
  256.         $angle $vector->getAngle();
  257.     //    echo "INIT:".$angle."<br>";
  258.         switch($this->style{
  259.         
  260.             case TICK_IN :
  261.                 $this->drawTicks($driver$vectorNULL$angle M_PI 2);
  262.                 break;
  263.         
  264.             case TICK_OUT :
  265.                 $this->drawTicks($driver$vector$angle M_PI 2NULL);
  266.                 break;
  267.         
  268.             default :
  269.                 $this->drawTicks($driver$vector$angle M_PI 2$angle M_PI 2);
  270.                 break;
  271.         
  272.         }
  273.     
  274.     }
  275.     
  276.      function drawTicks($driver&$vector$from$to{
  277.     
  278.         // Draw last tick
  279.         if($this->hideLast === FALSE{
  280.         
  281.             //echo '<b>';
  282.             if(($this->number - 1$this->interval === 0{
  283.                 $this->drawTick($driver$vector->p2$from$to);
  284.             }
  285.             //echo '</b>';
  286.             
  287.         }
  288.         
  289.         $number $this->number - 1;
  290.         $size $vector->getSize();
  291.         
  292.         // Get tick increment in pixels
  293.         $inc $size $number;
  294.         
  295.         // Check if we must hide the first tick
  296.         $start $this->hideFirst ? $inc 0;
  297.         $stop $inc $number;
  298.         
  299.         $position 0;
  300.         
  301.         for($i $startround($i6$stop$i += $inc{
  302.         
  303.             if($position $this->interval === 0{
  304.                 $p $vector->p1->move(
  305.                     round($i cos($vector->getAngle())6),
  306.                     round($i sin($vector->getAngle(* -1)6)
  307.                 );
  308.                 $this->drawTick($driver$p$from$to);
  309.             }
  310.             
  311.             $position++;
  312.             
  313.         }
  314.         //echo '<br><br>';
  315.     }
  316.     
  317.      function drawTick($driver$p$from$to{
  318. //    echo $this->size.':'.$angle.'|<b>'.cos($angle).'</b>/';
  319.         // The round avoid some errors in the calcul
  320.         // For example, 12.00000008575245 becomes 12
  321.         $p1 $p;
  322.         $p2 $p;
  323.         
  324.         if($from !== NULL{
  325.             $p1 $p1->move(
  326.                 round($this->size * cos($from)6),
  327.                 round($this->size * sin($from* -16)
  328.             );
  329.         }
  330.         
  331.         if($to !== NULL{
  332.             $p2 $p2->move(
  333.                 round($this->size * cos($to)6),
  334.                 round($this->size * sin($to* -16)
  335.             );
  336.         }
  337.         //echo $p1->x.':'.$p2->x.'('.$p1->y.':'.$p2->y.')'.'/';
  338.         $vector new awVector(
  339.             $p1$p2
  340.         );
  341.         
  342.         $driver->line(
  343.             $this->color,
  344.             $vector
  345.         );
  346.         
  347.     }
  348.  
  349. }
  350.  
  351. registerClass('Tick');
  352. ?>

Documentation generated on Fri, 16 Oct 2009 09:40:02 +0200 by phpDocumentor 1.4.1