TeeChartPHP
[ class tree: TeeChartPHP ] [ index: TeeChartPHP ] [ all elements ]

Source for file Zoom.php

Documentation is available at Zoom.php

  1. <?php
  2.  
  3. /**
  4.   *
  5.   * <p>Title: Zoom class</p>
  6.   *
  7.   * <p>Description: Used at tChart1.Zoom property, determines mouse
  8.   * zoom attributes.</p>
  9.   *
  10.   * <p>Copyright (c) 2005-2010 by Steema Software SL. All Rights Reserved.</p>
  11.   *
  12.   * <p>Company: Steema Software</p>
  13.   *
  14.   */
  15.  class Zoom extends ZoomScroll {
  16.  
  17.     private $allow true;
  18.     private $animated;
  19.     private $animatedSteps 8;
  20.     private $bBrush;
  21.     private $direction 2// ZoomDirections::$BOTH;
  22.     private $mouseButton 0// MouseEvent::$UTTON1;
  23.     private $keyShift 0;
  24.     private $minPixels 16;
  25.     protected $pen;
  26.     protected $zoomed;
  27.  
  28.     /**
  29.     * Controls the animated zoom "speed" (inertia)
  30.     */
  31.     public $animatedFactor = 3.0;
  32.  
  33.     /**
  34.     * Creates a new Zoom instance.
  35.     *
  36.     * @param IBaseChart
  37.     */
  38.     public function Zoom($c{
  39.         parent::ZoomScroll($c);
  40.     }
  41.  
  42.     /**
  43.     * Allows runtime Zoom by dragging the mouse when true.<br>
  44.     * Default value: true
  45.     *
  46.     * @return boolean 
  47.     */
  48.     public function getAllow({
  49.         return $this->allow;
  50.     }
  51.  
  52.     /**
  53.     * Allows runtime Zoom by dragging the mouse when true.<br>
  54.     * Default value: true
  55.     *
  56.     * @param value boolean
  57.     */
  58.     public function setAllow($value{
  59.         $this->allow $value;
  60.     }
  61.  
  62.     /**
  63.     * Animates Zoom in sequenced steps when true.<br>
  64.     * Default value: false
  65.     *
  66.     * @return boolean 
  67.     */
  68.     public function getAnimated()
  69.     {
  70.         return $this->animated;
  71.     }
  72.  
  73.     /**
  74.     * Animates Zoom in sequenced steps when true.<br>
  75.     * Default value: false
  76.     *
  77.     * @param value boolean
  78.     */
  79.     public function setAnimated($value{
  80.         $this->animated $value;
  81.     }
  82.  
  83.     /**
  84.     * Brush used to fill mousedragged zoom area.
  85.     *
  86.     * @return ChartBrush 
  87.     */
  88.     public function getBrush({
  89.         if ($this->bBrush == null{
  90.             $this->bBrush new ChartBrush($this->chartColor::WHITE()false);
  91.         }
  92.         return $this->bBrush;
  93.     }
  94.  
  95.     /**
  96.     * The direction of the zoom on a selected area.<br><br>
  97.     * Example. Horizontal will zoom only on a horizontal plane although the
  98.     * mouse is dragged across a vertical and horizontal plane.<br>
  99.     * Default value: Both
  100.     *
  101.     * @return ZoomDirections 
  102.     */
  103.     public function getDirection({
  104.         return $this->direction;
  105.     }
  106.  
  107.     /**
  108.     * Sets the direction of the zoom on a selected area.<br><br>
  109.     * Default value: Both
  110.     *
  111.     * @param value ZoomDirections
  112.     */
  113.     public function setDirection($value{
  114.         $this->direction $value;
  115.     }
  116.  
  117.     /**
  118.     * Determines the number of steps of the animated zooming sequence.<br>
  119.     * Large number of steps can delay zooming. The Animated property should be
  120.     * true.<br>
  121.     * Default value: 8
  122.     *
  123.     * @return int 
  124.     */
  125.     public function getAnimatedSteps({
  126.         return $this->animatedSteps;
  127.     }
  128.  
  129.     /**
  130.     * Sets the number of steps of the animated zooming sequence.<br>
  131.     * Large number of steps can delay zooming. The Animated property should be
  132.     * true.<br>
  133.     * Default value: 8
  134.     *
  135.     * @param value int
  136.     */
  137.     public function setAnimatedSteps($value{
  138.         $this->animatedSteps $value;
  139.     }
  140.  
  141.     /**
  142.     * The keyboard button as an extra condition to initiate the zoom.<br>
  143.     * Default value: None
  144.     *
  145.     * @return int 
  146.     */
  147.     public function getKeyMask({
  148.         return $this->keyShift;
  149.     }
  150.  
  151.     /**
  152.     * Sets a keyboard button as an extra condition to initiate the zoom.<br>
  153.     * Default value: None
  154.     *
  155.     * @param value int
  156.     */
  157.     public function setKeyMask($value{
  158.         $this->keyShift $value;
  159.     }
  160.  
  161.     /**
  162.     * The minimum number of pixels to actuate zoom action.<br>
  163.     * Default value: 16
  164.     *
  165.     * @return int 
  166.     */
  167.     public function getMinPixels({
  168.         return $this->minPixels;
  169.     }
  170.  
  171.     /**
  172.     * Sets minimum number of pixels to actuate zoom action.<br>
  173.     * Default value: 16
  174.     *
  175.     * @param value int
  176.     */
  177.     public function setMinPixels($value{
  178.         $this->minPixels $value;
  179.     }
  180.  
  181.     /**
  182.     * The mousebutton to use for the zoom action.<br>
  183.     * Note that Scroll action uses the right (Right) mousebutton as
  184.     * default.<br>
  185.     * Default value: Left
  186.     *
  187.     * @return int 
  188.     */
  189.     public function getMouseButton({
  190.         return $this->mouseButton;
  191.     }
  192.  
  193.     /**
  194.     * Sets the mousebutton to use for the zoom action.<br>
  195.     * Default value: Left
  196.     *
  197.     * @param value int
  198.     */
  199.     public function setMouseButton($value{
  200.         $this->mouseButton $value;
  201.     }
  202.  
  203.     /**
  204.     * Pen used to draw surrounding rectangle of zoom area.
  205.     *
  206.     * @return ChartPen 
  207.     */
  208.     public function getPen({
  209.         if ($this->pen == null{
  210.             $tmpColor new Color();
  211.             $tmpLineCap new LineCap();
  212.             $tmpDashStyle new DashStyle();
  213.             $this->pen = new ChartPen($this->chart$tmpColor->BLACKfalse1$tmpLineCap->BEVEL$tmpDashStyle->SOLID);
  214.         }
  215.         return $this->pen;
  216.     }
  217.  
  218.     /**
  219.     * Zooms the Chart rectangle. Units pixels.
  220.     *
  221.     * @param Rectangle
  222.     */
  223.     public function zoomRect($r{
  224.         $this->x0 = $r->getLeft();
  225.         $this->y0 = $r->getTop();
  226.         $this->x1 = $r->getRight();
  227.         $this->y1 = $r->getBottom();
  228.         $this->calcZoomPoints();
  229.     }
  230.  
  231.     protected function calcZoomPoints({
  232.         $this->check();
  233.         $this->chart->getAxes()->doZoom($this->x0$this->y0$this->x1$this->y1);
  234.     }
  235.  
  236.     /**
  237.     * Displays rectangle while dragging Chart for zoom operation.
  238.     */
  239.     public function draw({
  240.         $g $this->chart->getGraphics3D();
  241.         $e $g->getGraphics();
  242.  
  243.         $r new Rectangle($this->x0,$this->y0,$this->x1-$this->x0,$this->y1-$this->y0);
  244.  
  245.         if($this->chart->getParent()!=null{
  246.             if ($this->bBrush != null && $this->bBrush->getVisible()) {
  247.                 $brushXOR = -$this->bBrush->getColor()->getRGB();
  248.                 $e->setXORMode($this->Color->fromArgb($brushXOR));
  249.                 $e->fillRect($this->x0$this->y0$this->x1 - $this->x0$this->y1 - $this->y0);
  250.  
  251.                 if ($this->pen!= null && $this->pen->getVisible()) {
  252.                       $penXOR = -$this->pen->getColor()->getRGB();
  253.                      $e->setXORMode($this->Color->fromArgb($penXOR));
  254.                      $e->drawRect($this->x0-1,$this->y0-1,$this->x1+1-$this->x0,$this->y1+1-$this->y0);
  255.                 }
  256.             }
  257.             else if($this->pen!= null && $this->pen->getVisible()) {
  258.                 $this->chart->invalidate();
  259.                 $g->setPen($this->getPen());
  260.                 $g->getBrush()->setVisible(false);
  261.                 $g->rectangle($r);
  262.                 $g->getBrush()->setVisible(true);
  263.             }
  264.             else {
  265.                 $this->chart->invalidate();
  266.                 $tmpColor new Color();
  267.                 $tmpLineCap new LineCap();
  268.                 $tmpDashStyle new DashStyle();
  269.                 $g->setPen(new ChartPen($this->chart$tmpColor->BLACKtrue1$tmpLineCap->BEVEL$tmpDashStyle->DASH));
  270.                 $g->getBrush()->setVisible(false);
  271.                 $g->rectangle($r);
  272.                 $g->getBrush()->setVisible(true);
  273.             }
  274.         }
  275.     }
  276.  
  277.     /**
  278.     * Overrides base SetChart method to adjust pen and brush chart properties.
  279.     *
  280.     * @param IBaseChart
  281.     */
  282.     public function setChart($c{
  283.         parent::setChart($c);
  284.         if ($this->pen != null{
  285.             $this->pen->setChart($c);
  286.         }
  287.         if ($this->bBrush != null{
  288.             $this->bBrush->setChart($c);
  289.         }
  290.     }
  291.  
  292.     /**
  293.     * Rescales the Chart Axis to their Maximum and Minimum values.
  294.     */
  295.     public function undo({
  296.         $this->chart->restoreAxisScales();
  297.         $this->setZoomed(false);
  298.     }
  299.  
  300.     /**
  301.     * Determines if Chart axis scales fit all Chart points or not.<br>
  302.     * Run-time only. <br>
  303.     * It is set to true when users's apply zoom or scroll to the Chart using
  304.     * the mouse at run-time. <br>
  305.     * The Zoom.Undo method sets the Zoomed property to false and resets the
  306.     * axis scales to fit all Series points. <br>
  307.     * The default value is true, meaning no zoom or scroll has been applied
  308.     * to the chart after it has been displayed for first time. <br><br>
  309.     * Default value: false
  310.     *
  311.     * @return boolean 
  312.     */
  313.     public function getZoomed({
  314.         return $this->zoomed;
  315.     }
  316.  
  317.     /**
  318.     * Set the Chart axis scales to fit all Chart points when true.<br>
  319.     * Default value: false
  320.     *
  321.     * @param value boolean
  322.     */
  323.     public function setZoomed($value{
  324.         $this->zoomed = $value;
  325.         if (($this->chart->getParent(!= null&& (!$this->zoomed)) {
  326.             $this->chart->getParent()->doUnZoomed($this);
  327.         }
  328.         $this->invalidate();
  329.     }
  330.  
  331.     private function calcAxisScale($axis$percentZoom{
  332.         $minmax new FloatRange();
  333.         $axis->calcMinMax($minmax);
  334.         $tmpDelta ($minmax->min $minmax->max$percentZoom;
  335.         return new PointDouble($minmax->min $tmpDelta$minmax->max $tmpDelta);
  336.     }
  337.  
  338.     /**
  339.     * Applies the specified PercentZoom Zoom In/Out to the current Axis
  340.     * scales.<br>
  341.     * When PercentZoom is greater than 100%, Zoom Out is performed. <br>
  342.     * When PercentZoom is lower than 100%, Zoom In is performed.<br>
  343.     * The Animated property controls if Zoom is done directly in only o
  344.     * ne step or by multiple zooms thus giving an animation effect.
  345.     *
  346.     * @param percentZoom double
  347.     */
  348.     public function zoomPercent($percentZoom{
  349.         $percentZoom ($percentZoom 100.00.01;
  350.  
  351.         $left $this->calcAxisScale($this->chart->getAxes()->getLeft()$percentZoom);
  352.         $right $this->calcAxisScale($this->chart->getAxes()->getRight()$percentZoom);
  353.         $top $this->calcAxisScale($this->chart->getAxes()->getTop()$percentZoom);
  354.         $bottom $this->calcAxisScale($this->chart->getAxes()->getBottom()$percentZoom);
  355.         $this->chart->doZoom($top$bottom$left$right);
  356.         $this->invalidate();
  357.     }
  358. }
  359. ?>

Documentation generated on Wed, 16 Jun 2010 12:09:28 +0200 by phpDocumentor 1.4.1