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

Source for file ColorLine.php

Documentation is available at ColorLine.php

  1. <?php
  2.  
  3. /**
  4.  * ColorLine class
  5.  *
  6.  * Description: Color Line tool. To draw custom lines at a axis value
  7.  *
  8.  * @author
  9.  * @copyright (c) 1995-2008 by Steema Software SL. All Rights Reserved. <info@steema.com>
  10.  * @version 1.0
  11.  * @package TeeChartPHP
  12.  * @subpackage tools
  13.  * @link http://www.steema.com
  14.  */
  15.  
  16. class ColorLine extends ToolAxis
  17. {
  18.  
  19.    private $allowDrag true;
  20.    private $dragRepaint false;
  21.    private $noLimitDrag false;
  22.    private $draw3D true;
  23.    private $drawBehind false;
  24.    private $style;
  25.    private $lineValue 0;
  26.    private $dragging false;
  27.  
  28.     // Interceptors
  29.     function __get$property {
  30.       $method ="get{$property}";
  31.       if method_exists$this$method ) ) {
  32.         return $this->$method();
  33.       }
  34.     }
  35.  
  36.     function __set $property,$value {
  37.       $method ="set{$property}";
  38.       if method_exists$this$method ) ) {
  39.         return $this->$method($value);
  40.       }
  41.     }
  42.  
  43.    public function ColorLine($c null)
  44.    {
  45.       $this->style ColorLineStyle::$CUSTOM;
  46.       parent::ToolAxis($c);
  47.    }
  48.  
  49.    public function addDragListener($l)
  50.    {
  51.       $this->listenerList->add($this->DragListener->class $l);
  52.    }
  53.  
  54.    public function removeDragListener($l)
  55.    {
  56.       $this->listenerList->remove($this->DragListener->class $l);
  57.    }
  58.  
  59.    /**
  60.    *
  61.    * Default value: ColorLineStyle.CUSTOM
  62.    *
  63.    * @return ColorLineStyle 
  64.    */
  65.    public function getStyle()
  66.    {
  67.       return $this->style;
  68.    }
  69.  
  70.    /**
  71.    *
  72.    * Default value: ColorLine.CUSTOM
  73.    *
  74.    * @param value ColorLineStyle
  75.    */
  76.    public function setStyle($value)
  77.    {
  78.       if($this->style != $value)
  79.       {
  80.          $this->style $value;
  81.          $this->invalidate();
  82.       }
  83.    }
  84.  
  85.    protected function calcValue()
  86.    {
  87.       if($this->style == ColorLineStyle::$MAXIMUM)
  88.       {
  89.          return $this->iAxis->getMaximum();
  90.       }
  91.       else
  92.          if($this->style == ColorLineStyle::$CENTER)
  93.          {
  94.             return($this->iAxis->getMaximum($this->iAxis->getMinimum()) 5;
  95.          }
  96.          else
  97.             if($this->style == ColorLineStyle::$MINIMUM)
  98.             {
  99.                return $this->iAxis->getMinimum();
  100.             }
  101.       ;
  102.       return $this->lineValue;
  103.    }
  104.  
  105.    private function drawColorLine($back)
  106.    {
  107.       $g $this->chart->getGraphics3D();
  108.       $r $this->chart->getChartRect();
  109.  
  110.       if(!$g->getPen()->getVisible())
  111.       {
  112.          $tmpColor new Color(000);
  113.          $tmpColor->setEmpty(true);
  114.          $g->getPen()->color $tmpColor;
  115.       }
  116.  
  117.       $w $this->chart->getAspect()->getWidth3D();
  118.  
  119.       $tmp $this->iAxis->calcPosValue($this->calcValue());
  120.  
  121.       if($back)
  122.       {
  123.          if($this->iAxis->getHorizontal())
  124.          {
  125.             if($this->draw3D)
  126.             {
  127.                $g->zLine($tmp$r->getBottom()0$w);
  128.             }
  129.             if($this->draw3D || $this->drawBehind)
  130.             {
  131.                $g->verticalLine($tmp$r->y$r->getBottom()$w);
  132.             }
  133.          }
  134.          else
  135.          {
  136.             if($this->draw3D)
  137.             {
  138.                $g->zLine($r->x$tmp0$w);
  139.             }
  140.             if($this->draw3D || $this->drawBehind)
  141.             {
  142.                $g->horizontalLine($r->x$r->getRight()$tmp$w);
  143.             }
  144.          }
  145.       }
  146.       else
  147.          if($this->chart->getAspect()->getView3D(|| ((!$this->dragging|| $this->dragRepaint))
  148.          {
  149.             if($this->iAxis->getHorizontal())
  150.             {
  151.                if($this->draw3D)
  152.                {
  153.                   $g->zLine($tmp$r->y0$w);
  154.                }
  155.                if(!$this->drawBehind)
  156.                {
  157.                   $g->verticalLine($tmp$r->y$r->getBottom()0);
  158.                }
  159.             }
  160.             else
  161.             {
  162.                if($this->draw3D)
  163.                {
  164.                   $g->zLine($r->getRight()$tmp0$w);
  165.                }
  166.                if(!$this->drawBehind)
  167.                {
  168.                   $g->horizontalLine($r->x$r->getRight()$tmp0);
  169.                }
  170.             }
  171.          }
  172.    }
  173.  
  174.    public function chartEvent($e)
  175.    {
  176.       parent::chartEvent($e);
  177.       if(($this->iAxis != null&&
  178.       ((/* TODO ($e->getID() == ChartDrawEvent::$PAINTING) &&*/
  179.       ($e->getDrawPart(== ChartDrawEvent::$SERIES)) ||
  180.       (/* TODO ($e->getID() == ChartDrawEvent::$PAINTED) &&*/
  181.       ($e->getDrawPart(== ChartDrawEvent::$CHART))))
  182.       {
  183.          $this->chart->getGraphics3D()->setPen($this->getPen());
  184.          $this->drawColorLine(/* TODO ($e->getID() == ChartDrawEvent::$PAINTING) &&*/
  185.          ($e->getDrawPart(== ChartDrawEvent::$SERIES));
  186.       }
  187.    }
  188.  
  189.    public function mouseEvent($e$c)
  190.    {
  191.       $tmpLimit;
  192.  
  193.       $tmpDoDraw false;
  194.  
  195.       if($this->allowDrag && ($this->iAxis != null))
  196.       {
  197.          $tmpMouseEvent new MouseEvent();
  198.          if($e->getID(== $tmpMouseEvent->MOUSE_RELEASED)
  199.          {
  200.             $this->dragging false;
  201.             // force repaint
  202.             if(!$this->dragRepaint)
  203.             {
  204.                $this->invalidate();
  205.             }
  206.             // call event
  207.             $this->doEndDragLine();
  208.          }
  209.          else
  210.             if($e->getID(== $tmpMouseEvent->MOUSE_MOVED || $e->getID(== $tmpMouseEvent->MOUSE_DRAGGED)
  211.             {
  212.                if($this->dragging)
  213.                {
  214.                   //MM force repaint could vary
  215.                   if(!$this->dragRepaint)
  216.                   {
  217.                      $this->invalidate();
  218.                   }
  219.  
  220.                   $tmp $this->iAxis->getHorizontal($e->getX($e->getY();
  221.  
  222.                   // calculate new position
  223.                   $tmpNew $this->getAxis()->calcPosPoint($tmp);
  224.  
  225.                   // check inside axis limits
  226.                   if(!$this->noLimitDrag)
  227.                   {
  228.                      // do not use Axis Minimum & Maximum, we need the "real" min && max
  229.                      if($this->iAxis->getHorizontal())
  230.                      {
  231.                         $tmpLimit $this->iAxis->calcPosPoint($this->iAxis->iStartPos);
  232.                         if($tmpNew $tmpLimit)
  233.                         {
  234.                            $tmpNew $tmpLimit;
  235.                         }
  236.                         else
  237.                         {
  238.                            $tmpLimit $this->iAxis->calcPosPoint($this->iAxis->iEndPos);
  239.                            if($tmpNew $tmpLimit)
  240.                            {
  241.                               $tmpNew $tmpLimit;
  242.                            }
  243.                         }
  244.                      }
  245.                      else
  246.                      {
  247.                         $tmpLimit $this->iAxis->calcPosPoint($this->iAxis->iEndPos);
  248.                         if($tmpNew $tmpLimit)
  249.                         {
  250.                            $tmpNew $tmpLimit;
  251.                         }
  252.                         else
  253.                         {
  254.                            $tmpLimit $this->iAxis->calcPosPoint($this->iAxis->iStartPos);
  255.                            if($tmpNew $tmpLimit)
  256.                            {
  257.                               $tmpNew $tmpLimit;
  258.                            }
  259.                         }
  260.                      }
  261.                   }
  262.  
  263.                   if($this->dragRepaint)
  264.                   {
  265.                      // call set_Value to force repaint whole chart
  266.                      $this->setValue($tmpNew);
  267.                   }
  268.                   else
  269.                   {
  270.  
  271.                      $tmpDoDraw $this->lineValue != $tmpNew;
  272.                      if($tmpDoDraw)
  273.                      {
  274.                         // draw line in xor mode, to avoid repaint the whole chart
  275.  
  276.                         $this->chart->getGraphics3D()->setPen($this->getPen());
  277.                         //Pen.Mode=pmNotXor;
  278.  
  279.                         /* hide previous line */
  280.                         $this->drawColorLine(true);
  281.                         $this->drawColorLine(false);
  282.  
  283.                         /* set new value */
  284.                         $this->lineValue $tmpNew;
  285.                      }
  286.                   }
  287.  
  288.                   $this->chart->setCancelMouse(true);
  289.  
  290.                   /* call event, allow event to change Value */
  291.                   $this->doDragLine();
  292.  
  293.                   if($tmpDoDraw)
  294.                   {
  295.                      /* draw at new position */
  296.                      $this->drawColorLine(true);
  297.                      $this->drawColorLine(false);
  298.                      /* reset pen mode */
  299.                      //chart.graphics3D.getPen().Mode=pmCopy;
  300.                   }
  301.                }
  302.                else
  303.                {
  304.                   /* is mouse on line? */
  305.                   if($this->clicked($e->getX()$e->getY()))
  306.                   {
  307.                      /* 5.02 */
  308.                      /* show appropiate cursor */
  309.                      $tmpCursor $this->iAxis->getHorizontal(?
  310.                      "VSPLIT" "HSPLIT";
  311.                      try
  312.                      {
  313.                         $c $this->Cursor->getSystemCustomCursor($tmpCursor);
  314.                      }
  315.                      catch(Exception $exception)
  316.                      {
  317.                         /** @todo DO NOTHING? */
  318.                      }
  319.  
  320.                      $this->chart->setCancelMouse(true);
  321.                   }
  322.                }
  323.             }
  324.             else
  325.                if($e->getID(== $tmpMouseEvent->MOUSE_PRESSED)
  326.                {
  327.                   // is mouse over line ?
  328.                   $this->dragging $this->clicked($e->getX()$e->getY());
  329.                   $this->chart->setCancelMouse($this->dragging);
  330.                }
  331.       }
  332.  
  333.       return $c;
  334.    }
  335.  
  336.    /**
  337.    * Gets descriptive text.
  338.    *
  339.    * @return String 
  340.    */
  341.    public function getDescription()
  342.    {
  343.       return Language::getString("ColorLineTool");
  344.    }
  345.  
  346.    /**
  347.    * Gets detailed descriptive text.
  348.    *
  349.    * @return String 
  350.    */
  351.    public function getSummary()
  352.    {
  353.       return Language::getString("ColorLineSummary");
  354.    }
  355.  
  356.    protected function doEndDragLine()
  357.    {
  358.       $this->fireDragged(new ChangeEvent($this));
  359.    }
  360.  
  361.    protected function doDragLine()
  362.    {
  363.       $this->fireDragging(new ChangeEvent($this));
  364.    }
  365.  
  366.    private function clicked($x$y)
  367.    {
  368.       $tmp $this->iAxis->getHorizontal($x $y;
  369.       if(abs($tmp $this->iAxis->calcPosValue($this->calcValue())) $this->clickTolerance)
  370.       {
  371.          $r $this->chart->getChartRect();
  372.          return $this->iAxis->getHorizontal(($y >= $r->y&& ($y <= $r->getBottom()) :
  373.          ($this->>= $r->x&& ($x <= $r->getRight());
  374.       }
  375.       else
  376.       {
  377.          return false;
  378.       }
  379.    }
  380.  
  381.    /**
  382.    * Allows mousedrag of Line when true. <br>
  383.    * Default value: true
  384.    *
  385.    * @return boolean 
  386.    */
  387.    public function getAllowDrag()
  388.    {
  389.       return $this->allowDrag;
  390.    }
  391.  
  392.    /**
  393.    * Allows mousedrag of Line when true. <br>
  394.    * Default value: true
  395.    *
  396.    * @param value boolean
  397.    */
  398.    public function setAllowDrag($value)
  399.    {
  400.       $this->allowDrag $this->setBooleanProperty($this->allowDrag$value);
  401.    }
  402.  
  403.    /**
  404.    * Repaints the Chart while moving the ColorLine when true.<br>
  405.    * Set to true to repaint the Chart while moving the ColorLine. <br>
  406.    * Default value: false
  407.    *
  408.    * @return boolean 
  409.    */
  410.    public function getDragRepaint()
  411.    {
  412.       return $this->dragRepaint;
  413.    }
  414.  
  415.    /**
  416.    * Set to true to repaint the Chart while moving the ColorLine. <br>
  417.    * Default value: false
  418.    *
  419.    * @param value boolean
  420.    */
  421.    public function setDragRepaint($value)
  422.    {
  423.       $this->dragRepaint $this->setBooleanProperty($this->dragRepaint$value);
  424.    }
  425.  
  426.    /**
  427.    * Draws ColorLine in 3D when true.<br>
  428.    * Default value: true
  429.    *
  430.    * @return boolean 
  431.    */
  432.    public function getDraw3D()
  433.    {
  434.       return $this->draw3D;
  435.    }
  436.  
  437.    /**
  438.    * Draws ColorLine in 3D when true.<br>
  439.    * Default value: true
  440.    *
  441.    * @param value boolean
  442.    */
  443.    public function setDraw3D($value)
  444.    {
  445.       $this->draw3D $this->setBooleanProperty($this->draw3D$value);
  446.    }
  447.  
  448.    /**
  449.    * Draws the ColorLine behind the series values.<br>
  450.    * Default value: false
  451.    *
  452.    * @return boolean 
  453.    */
  454.    public function getDrawBehind()
  455.    {
  456.       return $this->drawBehind;
  457.    }
  458.  
  459.    /**
  460.    * Draws the ColorLine behind the series values.<br>
  461.    * Default value: false
  462.    *
  463.    * @param value boolean
  464.    */
  465.    public function setDrawBehind($value)
  466.    {
  467.       $this->drawBehind $this->setBooleanProperty($this->drawBehind$value);
  468.    }
  469.  
  470.    /**
  471.    * Allows drag of ColorLine outside of the Chart rectangle.<br>
  472.    * Default value: false
  473.    *
  474.    * @return boolean 
  475.    */
  476.    public function getNoLimitDrag()
  477.    {
  478.       return $this->noLimitDrag;
  479.    }
  480.  
  481.    /**
  482.    * Allows drag of ColorLine outside of the Chart rectangle.<br>
  483.    * Default value: false
  484.    *
  485.    * @param value boolean
  486.    */
  487.    public function setNoLimitDrag($value)
  488.    {
  489.       $this->noLimitDrag $this->setBooleanProperty($this->noLimitDrag$value);
  490.    }
  491.  
  492.    /**
  493.    * Determines Axis position where the ColorLine has to be drawn.<br>
  494.    * Default value: 0
  495.    *
  496.    * @return double 
  497.    */
  498.    public function getValue()
  499.    {
  500.       return $this->lineValue;
  501.    }
  502.  
  503.    /**
  504.    * Sets the Axis position where the ColorLine has to be drawn.<br>
  505.    * Default value: 0
  506.    *
  507.    * @param value double
  508.    */
  509.    public function setValue($value)
  510.    {
  511.       $this->lineValue $this->setDoubleProperty($this->lineValue$value);
  512.    }
  513. }
  514.  
  515. ?>

Documentation generated on Wed, 16 Jun 2010 12:04:35 +0200 by phpDocumentor 1.4.1