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

Source for file Annotation.php

Documentation is available at Annotation.php

  1. <?php
  2.  
  3. /**
  4.  * Annotation class
  5.  *
  6.  * Description: Annotation tool
  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 Annotation extends Tool
  17. {
  18.  
  19.    private $position;
  20.    private $shape;
  21.    private $textAlign;
  22.    private $cursor;
  23.    private $callout;
  24.    private $customSize;
  25.  
  26.     // Interceptors
  27.     function __get$property {
  28.       $method ="get{$property}";
  29.       if method_exists$this$method ) ) {
  30.         return $this->$method();
  31.       }
  32.     }
  33.  
  34.     function __set $property,$value {
  35.       $method ="set{$property}";
  36.       if method_exists$this$method ) ) {
  37.         return $this->$method($value);
  38.       }
  39.     }
  40.  
  41.    public function Annotation($c null $text "")
  42.    {
  43.       $this->position AnnotationPosition::$LEFTTOP;
  44.       $this->textAlign Array(StringAlignment::$HORIZONTAL_LEFT_ALIGN);
  45.       // TODO $this->cursor = Cursors::$DEFAULT;
  46.       parent::Tool($c);
  47.       $this->setText($text);
  48.       $this->getShape()->setDrawText(false);
  49.       $this->shape->getShadow()->setVisible(true);
  50.       $this->getCallout()->setChart($this->chart);
  51.    }
  52.  
  53.    public function addToolMouseListener($l)
  54.    {
  55.       $this->listenerList->add($this->ToolMouseListener->class $l);
  56.    }
  57.  
  58.    public function removeToolMouseListener($l)
  59.    {
  60.       $this->listenerList->remove($this->ToolMouseListener->class $l);
  61.    }
  62.  
  63.    public function getCallout()
  64.    {
  65.       if($this->callout == null)
  66.       {
  67.          $this->callout new AnnotationCallout(null);
  68.       }
  69.       return $this->callout;
  70.    }
  71.  
  72.    /**
  73.    * The Cursor type for when the user moves the mouse over the
  74.    * Annotation bounds. <br>
  75.    * Default value: Default
  76.    *
  77.    * @return Cursor 
  78.    */
  79.    public function getCursor()
  80.    {
  81.       return $this->cursor;
  82.    }
  83.  
  84.    /**
  85.    * Selects the Cursor type for when the user moves the mouse over the
  86.    * Annotation bounds. <br>
  87.    * Default value: Default
  88.    *
  89.    * @param value Cursor
  90.    */
  91.    public function setCursor($value)
  92.    {
  93.       $this->cursor $value;
  94.    }
  95.  
  96.    public function setChart($c)
  97.    {
  98.       parent::setChart($c);
  99.       $this->getShape()->setChart($this->chart);
  100.       $this->getCallout()->setChart($this->chart);
  101.    }
  102.  
  103.    /**
  104.    * Horizontal alignment of displayed text.<br>
  105.    * Default value: StringAlignment.Near
  106.    *
  107.    * @return StringAlignment 
  108.    */
  109.    public function getTextAlign()
  110.    {
  111.       return $this->textAlign;
  112.    }
  113.  
  114.    /**
  115.    * Sets the horizontal alignment of displayed text.<br>
  116.    * Default value: StringAlignment.Near
  117.    *
  118.    * @param value StringAlignment
  119.    */
  120.    public function setTextAlign($value)
  121.    {
  122.       if($this->textAlign != $value)
  123.       {
  124.          $this->textAlign $value;
  125.          $this->invalidate();
  126.       }
  127.    }
  128.  
  129.    //private boolean ShouldSerializeLeft() {
  130.    //    return shape.getCustomPosition();
  131.    //}
  132.  
  133.    /**
  134.    * The horizontal displacement in pixels of text box from Chart's left
  135.    * edge.
  136.    *
  137.    * @return int 
  138.    */
  139.    public function getLeft()
  140.    {
  141.       return $this->shape->getLeft();
  142.    }
  143.  
  144.    /**
  145.    * Sets horizontal displacement in pixels of text box from Chart's left
  146.    * edge.
  147.    *
  148.    * @param value int
  149.    */
  150.    public function setLeft($value)
  151.    {
  152.       $this->shape->setLeft($value);
  153.       $this->shape->setCustomPosition(true);
  154.    }
  155.  
  156.    /**
  157.    * The vertical displacement in pixels of text box from Chart's top edge.
  158.    *
  159.    * @return int 
  160.    */
  161.    public function getTop()
  162.    {
  163.       return $this->shape->getTop();
  164.    }
  165.  
  166.    /**
  167.    * Sets vertical displacement in pixels of text box from Chart's top edge.
  168.    *
  169.    * @param value int
  170.    */
  171.    public function setTop($value)
  172.    {
  173.       $this->shape->setTop($value);
  174.       $this->shape->setCustomPosition(true);
  175.    }
  176.  
  177.    /**
  178.    * The default position for the Annotation Tool text box and text.
  179.    * <br>
  180.    * Default value: AnnotationPosition.LeftTop
  181.    *
  182.    *
  183.    * @return AnnotationPosition 
  184.    */
  185.    public function getPosition()
  186.    {
  187.       return $this->position;
  188.    }
  189.  
  190.    /**
  191.    * Defines a default position for the Annotation Tool text box and text.
  192.    * <br>
  193.    * Default value: AnnotationPosition.LeftTop
  194.    *
  195.    *
  196.    * @param value AnnotationPosition
  197.    */
  198.    public function setPosition($value)
  199.    {
  200.       if($this->position != $value)
  201.       {
  202.          $this->position $value;
  203.          $this->shape->setCustomPosition(false);
  204.          $this->invalidate();
  205.       }
  206.    }
  207.  
  208.    /**
  209.    * The characteristics of the Annotation Tool text and text box Shape.
  210.    *
  211.    * @return TextShapePosition 
  212.    */
  213.    public function getShape()
  214.    {
  215.       if($this->shape == null)
  216.       {
  217.          $this->shape new TextShapePosition($this->chart);
  218.       }
  219.       return $this->shape;
  220.    }
  221.  
  222.    protected function getInnerText()
  223.    {
  224.       return $this->shape->getText();
  225.    }
  226.  
  227.    /**
  228.    * The text for the Annotation Tool.<br>
  229.    * Default value: ""
  230.    *
  231.    * @return String 
  232.    */
  233.    public function getText()
  234.    {
  235.       return $this->getInnerText();
  236.    }
  237.  
  238.    /**
  239.    * Defines the text for the Annotation Tool.<br>
  240.    * Default value: ""
  241.    *
  242.    * @param value String
  243.    */
  244.    public function setText($value)
  245.    {
  246.       $this->getShape()->setText($value);
  247.    }
  248.  
  249.    /**
  250.    * Gets descriptive text.
  251.    *
  252.    * @return String 
  253.    */
  254.    public function getDescription()
  255.    {
  256.       return Language::getString("AnnotationTool");
  257.    }
  258.  
  259.    /**
  260.    * Gets detailed descriptive text.
  261.    *
  262.    * @return String 
  263.    */
  264.    public function getSummary()
  265.    {
  266.       return Language::getString("AnnotationSummary");
  267.    }
  268.  
  269.    /**
  270.    * Returns the annotation height in pixels
  271.    * @return int 
  272.    */
  273.    public function getHeight()
  274.    {
  275.       return $this->shape->getHeight();
  276.    }
  277.  
  278.    /**
  279.    * Sets the annotation height in pixels
  280.    * @param value int
  281.    */
  282.    public function setHeight($value)
  283.    {
  284.       $this->shape->setHeight($value);
  285.    }
  286.  
  287.    /**
  288.    * Returns the annotation width in pixels
  289.    * @return int 
  290.    */
  291.    public function getWidth()
  292.    {
  293.       return $this->shape->getWidth();
  294.    }
  295.  
  296.    /**
  297.    * Sets the annotation width in pixels
  298.    * @param value int
  299.    */
  300.    public function setWidth($value)
  301.    {
  302.       $this->shape->setWidth($value);
  303.    }
  304.  
  305.    /// Set to true to permit custom sizing of TextShape.
  306.    public function getCustomSize()
  307.    {
  308.       return $this->customSize;
  309.    }
  310.  
  311.    public function setCustomSize($value)
  312.    {
  313.       $this->customSize $value;
  314.    }
  315.  
  316.    private function drawText()
  317.    {
  318.       $tmp $this->getText();
  319.  
  320.       if(strlen($tmp== 0)
  321.          $tmp " ";
  322.  
  323.       $g $this->chart->getGraphics3D();
  324.  
  325.       $g->setFont($this->shape->getFont());
  326.       $tmpHeight =$this->shape->getFont()->getSize();
  327.  
  328.       $m $this->chart->multiLineTextWidth($tmp);
  329.       $tmpW $m->width-$tmpHeight;
  330.       $tmpN $m->count;
  331.       $tmpH $tmpN $tmpHeight;
  332.  
  333.       $x 0;
  334.       $y 0;
  335.  
  336.       if($this->shape->getCustomPosition())
  337.       {
  338.          $x $this->shape->getShapeBounds()->getLeft(4;
  339.          $y $this->shape->getShapeBounds()->getTop(4;
  340.       }
  341.       else
  342.       {
  343.          $tmpX $this->chart->getWidth($tmpW 8;
  344.          $tmpY $this->chart->getHeight($tmpH 8;
  345.  
  346.          if($this->position == AnnotationPosition::$LEFTTOP)
  347.          {
  348.             $x 10;
  349.             $y 10;
  350.          }
  351.          else
  352.             if($this->position == AnnotationPosition::$LEFTBOTTOM)
  353.             {
  354.                $x 10;
  355.                $y $tmpY;
  356.             }
  357.             else
  358.                if($this->position == AnnotationPosition::$RIGHTTOP)
  359.                {
  360.                   $x $tmpX;
  361.                   $y 10;
  362.                }
  363.                else
  364.                {
  365.                   $x $tmpX;
  366.                   $y $tmpY;
  367.                }
  368.       }
  369.  
  370.       $this->shape->setShapeBounds(new Rectangle($x 4$y 4$tmpW 4,
  371.       ($tmpHeight 1.204));
  372.  
  373.       if($this->shape->getVisible())
  374.       {
  375.          $oldname TChart::$controlName;
  376.          TChart::$controlName 'Annotation'
  377.          $this->shape->paint();
  378.          TChart::$controlName=$oldname;
  379.       }
  380.  
  381.       $g->getBrush()->setVisible(false);
  382.       $g->setTextAlign($this->textAlign);
  383.  
  384. /* TODO
  385.  
  386.       if($this->textAlign == StringAlignment::$CENTER)
  387.       {
  388.          $x = 2 +
  389.          (($this->shape->getShapeBounds()->x + $this->shape->getShapeBounds()->getRight()) /
  390.          2);
  391.       }
  392.       else
  393.          if($this->textAlign == StringAlignment::$FAR)
  394.          {
  395.             $x = $this->shape->getShapeBounds()->getRight() - 2;
  396.          }
  397.     */
  398.       $s Array();// Array of String
  399.       $s StringFormat::split($tmpLanguage::getString("LineSeparator"));
  400.  
  401.       for($t 1$t <= $tmpN$t++)
  402.       {
  403.          $g->textOut($x$y ($t $tmpHeight),0$s[$t 1]);
  404.       }
  405.  
  406.       // Draw callout
  407.       if($this->getCallout()->getVisible(|| $this->callout->getArrow()->getVisible())
  408.       {
  409.          $tmpTo new TeePoint($this->callout->getXPosition(),
  410.          $this->callout->getYPosition());
  411.          $tmpFrom $this->callout->closerPoint($this->shape->getShapeBounds()$tmpTo);
  412.  
  413.          if($this->callout->getDistance(!= 0)
  414.          {
  415.             $tmpTo MathUtils::pointAtDistance($tmpFrom$tmpTo,
  416.             $this->callout->getDistance());
  417.          }
  418.  
  419.          $this->callout->draw(Color::EMPTYCOLOR($tmpTo$tmpFrom$this->callout->getZPosition());
  420.       }
  421.    }
  422.  
  423.    public function chartEvent($e)
  424.    {
  425.       parent::chartEvent($e);
  426.       //$tmpChartDrawEvent = new ChartDrawEvent();
  427.       if(/*($e->getID() == ChartDrawEvent::$PAINTED) &&*/ ($e->getDrawPart(== ChartDrawEvent::$CHART))
  428.       {
  429.          $this->drawText();
  430.       }
  431.    }
  432.  
  433.    /**
  434.    * Returns true is point parameter is inside annotation bounds
  435.    * @param Point
  436.    * @return boolean 
  437.    */
  438.    public function clicked($p)
  439.    {
  440.       return $this->getShape()->getShapeBounds()->contains($p);
  441.    }
  442.  
  443.    public function mouseEvent($e$c)
  444.    {
  445.       $tmpMouseEvent new MouseEvent();
  446.       if($e->getID(== $tmpMouseEvent->MOUSE_PRESSED)
  447.       {
  448.          if($this->clicked($e->getPoint()))
  449.          {
  450.             $e->setSource($this);
  451.             $this->fireClicked($e);
  452.          }
  453.       }
  454.       else
  455.       {
  456.          if(($e->getID(== $tmpMouseEvent->MOUSE_MOVED&&
  457.          ($this->cursor != $this->Cursor->getDefaultCursor()))
  458.          {
  459.             if($this->clicked($e->getPoint()))
  460.             {
  461.                $c $this->cursor;
  462.             }
  463.          }
  464.       }
  465.  
  466.       return $c;
  467.    }
  468. }
  469.  
  470. ?>

Documentation generated on Wed, 16 Jun 2010 12:02:30 +0200 by phpDocumentor 1.4.1