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

Source for file Title.php

Documentation is available at Title.php

  1. <?php
  2.  
  3. /**
  4.  * Title class
  5.  *
  6.  * Description: Underlying Title characteristics
  7.  *
  8.  * @author
  9.  * @copyright (c) 1995-2010 by Steema Software SL. All Rights Reserved. <info@steema.com>
  10.  * @version 1.0
  11.  * @package TeeChartPHP
  12.  * @link http://www.steema.com
  13.  */
  14.  
  15. class Title extends TextShapePosition {
  16.  
  17.     private static $TITLEFOOTDISTANCE 5;
  18.     private $adjustFrame true;
  19.     private $alignment;
  20.     private $fontH;
  21.     private $tmpXPosTitle;
  22.     private $tmpFrameWidth;
  23.     private $tmpMargin;
  24.  
  25.     protected $onTop = true;
  26.  
  27.     // Interceptors
  28.     function __get$property {
  29.       $method ="get{$property}";
  30.       if method_exists$this$method ) ) {
  31.         return $this->$method();
  32.       }
  33.     }
  34.  
  35.     function __set $property,$value {
  36.       $method ="set{$property}";
  37.       if method_exists$this$method ) ) {
  38.         return $this->$method($value);
  39.       }
  40.     }
  41.  
  42.     public function Title($c{
  43.         $this->alignment=Array(StringAlignment::$CENTER);
  44.         parent::TextShapePosition($c);
  45.                       
  46.         $this->getBrush()->setDefaultColor(new Color(220,220,220));
  47.         $this->drawText = false;
  48.         $this->bTransparent = true;
  49.     }
  50.  
  51.     protected function readResolve({
  52.         $this->onTop=true;
  53.         return $this;
  54.     }
  55.  
  56.     /**
  57.      * Resizes Header and Footer frames to full Chart dimensions when true.<br>
  58.      * When false it resizes to the Title text width. It only has effect when
  59.      * Chart.Header or Chart.Footer.Visible is true.<br>
  60.      * Default value: true
  61.      *
  62.      * @return boolean 
  63.      */
  64.     public function getAdjustFrame({
  65.         return $this->adjustFrame;
  66.     }
  67.  
  68.     /**
  69.      * Resizes Header and Footer frames to full Chart dimensions when true.<br>
  70.      * When false it resizes to the Title text width. It only has effect when
  71.      * Chart.Header or Chart.Footer.Visible is true.<br>
  72.      * Default value: true
  73.      *
  74.      * @param value boolean
  75.      */
  76.     public function setAdjustFrame($value{
  77.         $this->adjustFrame setBooleanProperty($this->adjustFrame$value);
  78.     }
  79.  
  80.     /**
  81.      * Determines how tChart Header and Footer text will be aligned within the
  82.      * Chart rectangle. <br>
  83.      * The Header or Footer can optionally be surrounded by a Frame. <br>
  84.      * Default value: Center
  85.      *
  86.      * @return StringAlignment 
  87.      */
  88.     public function getAlignment({
  89.         return $this->alignment;
  90.     }
  91.  
  92.     /**
  93.      * Sets how tChart Header and Footer text will be aligned within the
  94.      * Chart rectangle. <br>
  95.      * The Header or Footer can optionally be surrounded by a Frame. <br>
  96.      * Default value: Center
  97.      *
  98.      * @param value StringAlignment
  99.      */
  100.     public function setAlignment($value{
  101.         /*
  102.           if ($this->alignment != $value) {
  103.             $this->alignment = $value;
  104.             $this->invalidate();
  105.         }
  106.         */
  107.         
  108.         if (is_array($value)){
  109.           $this->alignment=$value;
  110.         }
  111.         else
  112.         {
  113.           $this->alignment=Array($value);
  114.         }
  115.         $this->invalidate();
  116.     }
  117.  
  118.     /* draw a title text line */
  119.     private function drawTitleLine($aIndex$gd{
  120.         $xst $this->getLines();
  121.         $st=$xst[$aIndex];
  122.  
  123.         if ($st != null{
  124.             $aPos ($aIndex+1$this->fontH $this->tmpFrameWidth 2;
  125.  
  126.             if ($this->onTop{
  127.                 $aPos += $this->getShapeBounds()->getTop();
  128.             else {
  129.                 $aPos $this->getShapeBounds()->getBottom(($this->fontH $aPos);
  130.             }
  131.  
  132.             if (in_array(StringAlignment::$FAR,$this->alignment)) {
  133.                 $this->tmpXPosTitle $this->shapeBounds->getRight(-
  134.                                MathUtils::round($gd->textWidth($st)) -
  135.                                ($this->tmpMargin 2);
  136.             else
  137.               if (in_array(StringAlignment::$CENTER,$this->alignment)) {
  138.                 $this->tmpXPosTitle round((($this->shapeBounds->x
  139.                                +   $this->shapeBounds->getRight()) 2-
  140.                                ($gd->textWidth($st/2));
  141.             }
  142.  
  143.             $oldAlign=$gd->getTextAlign();
  144.             $gd->setTextAlign($this->getAlignment());
  145.  
  146.             $gd->textOut($this->tmpXPosTitle$aPos0$st);
  147.             $gd->setTextAlign($oldAlign);
  148.         }
  149.     }
  150.  
  151.     /**
  152.      * Returns if mouse cursor is inside TChartTitle bound rectangle.<br><br>
  153.      * The Title.Visible property must be true. <br>
  154.      * The Title rectangle size depends on Title.Pen.Visible and
  155.      * Title.AdjustFrame.
  156.      *
  157.      * @param Point
  158.      * @return boolean 
  159.      */
  160.     public function clicked($p{
  161.         return $this->visible && $this->getShapeBounds()->contains($p->x$p->y);
  162.     }
  163.  
  164.     /**
  165.      * Returns if mouse cursor is inside TChartTitle bound rectangle.<br><br>
  166.      * The Title.Visible property must be true. <br>
  167.      * The Title rectangle size depends on Title.Pen.Visible and
  168.      * Title.AdjustFrame.
  169.      *
  170.      * @param int
  171.      * @param int
  172.      * @return boolean 
  173.      */
  174.     public function _clicked($x$y{
  175.         return $this->visible && $this->getShapeBounds()->contains($x$y);
  176.     }
  177.  
  178.     function doDraw($gd$rect$customOnly{
  179.        if ($this->bCustomPosition == $customOnly{
  180.             return $this->draw($gd$rect);
  181.         else {
  182.             return $rect;
  183.         }
  184.     }
  185.  
  186.     protected function draw($gd$rect{
  187.  
  188.         TChart::$controlName .= 'Title_';
  189.         $linesCount $this->getLinesLength();
  190.  
  191.         if ($this->visible && ($linesCount 0)) {
  192.             // calculate title shape margin
  193.             $tmpFrameVisible $this->getPen()->getVisible();
  194.  
  195.             if ($tmpFrameVisible{
  196.                 $this->tmpFrameWidth $this->getPen()->getWidth();
  197.             else {
  198.                 $this->tmpFrameWidth 0;
  199.             }
  200.  
  201.             if ($this->getBevel()->getInner(!= BevelStyle::$NONE{
  202.                 $this->tmpFrameWidth += $this->getBevel()->getWidth();
  203.             }
  204.  
  205.             // apply title margins
  206.             if (!$this->bCustomPosition{
  207.                 $this->setShapeBounds($rect);
  208.                 if ($this->onTop{
  209.                     $this->shapeBounds->+= $this->tmpFrameWidth;
  210.                 }
  211.             }
  212.  
  213.             // prepare title font
  214.             $gd->setFont($this->getFont());
  215.             $gd->setTextAlign(StringAlignment::$NEAR);
  216.  
  217.             $oldAlign=$gd->getTextAlign();
  218.  
  219.             $this->fontH $gd->getFontHeight();
  220.  
  221.             // autosize title height on number of text lines
  222.             if ($this->onTop || $this->bCustomPosition{
  223.                 $this->shapeBounds->height $linesCount $this->fontH $this->tmpFrameWidth;
  224.             else {
  225.                 $old $this->shapeBounds->getBottom();
  226.                 $this->shapeBounds->height$linesCount $this->fontH $this->tmpFrameWidth;
  227.                 $this->shapeBounds->$old $this->shapeBounds->height;
  228.             }
  229.  
  230.             $this->tmpMargin MathUtils::round($gd->textWidth("W"));
  231.  
  232.             $tmp 0;
  233.  
  234.             // resize Title to maximum Chart width
  235.             if ($this->adjustFrame{
  236.  
  237.                 $tmpMaxWidth 0;
  238.  
  239.                 for ($t 0$t $linesCount$t++{
  240.                     $tmpx array();
  241.                     $tmpx $this->getLines();
  242.                     $tmp MathUtils::round($gd->textWidth($tmpx[$t]));
  243.  
  244.                     if ($tmp $tmpMaxWidth{
  245.                         $tmpMaxWidth $tmp;
  246.                     }
  247.                 }
  248.  
  249.                 $tmpMaxWidth += $this->tmpMargin $this->tmpFrameWidth;
  250.  
  251.                 if (in_array(StringAlignment::$NEAR,$this->alignment)) {
  252.                     $this->shapeBounds->width $tmpMaxWidth;
  253.                 else
  254.                 if (in_array(StringAlignment::$FAR,$this->alignment)) {
  255.                     $this->shapeBounds->$this->shapeBounds->getRight($tmpMaxWidth;
  256.                 else {
  257.                     if ($this->bCustomPosition{
  258.                         $this->shapeBounds->width $tmpMaxWidth;
  259.                     }
  260.                     $tmp ($this->shapeBounds->$this->shapeBounds->getRight()) 2;
  261.                     $this->shapeBounds->$tmp ($tmpMaxWidth 2);
  262.                     $this->shapeBounds->width $tmpMaxWidth;
  263.                 }
  264.             }
  265.  
  266.             // draw title shape
  267.             parent::paint($gd$this->getShapeBounds());
  268.  
  269.             if (in_array(StringAlignment::$NEAR,$this->alignment)) {
  270.                 $this->tmpXPosTitle $this->getShapeBounds()->getLeft(($this->tmpMargin 2);
  271.             }
  272.  
  273.             // draw all Title text lines
  274.             for ($t 0$t $linesCount$t++{
  275.                 $this->drawTitleLine($t$gd);
  276.             }
  277.  
  278.             $gd->setTextAlign($oldAlign);
  279.  
  280.             // calculate Chart positions after drawing the titles / footers
  281.             if (!$this->bCustomPosition{
  282.                 $tmp self::$TITLEFOOTDISTANCE $this->tmpFrameWidth;
  283.  
  284.                 if ((!$this->getTransparent()) && $this->getShadow()->getVisible()) {
  285.                     $tmp += $this->getShadow()->getHeight();
  286.                 }
  287.  
  288.                 if ($this->onTop{
  289.                     $tmpY $rect->y;
  290.                     $rect->$this->shapeBounds->getBottom($tmp;
  291.                     $rect->height -= ($rect->$tmpY);
  292.                 else {
  293.                     $rect->height -= ($tmp $linesCount $this->fontH);
  294.                 }
  295.             }
  296.         }
  297.  
  298.         return $this->chart->recalcWidthHeight($rect)// DB
  299.     }
  300. }
  301.  
  302. ?>

Documentation generated on Wed, 16 Jun 2010 12:08:59 +0200 by phpDocumentor 1.4.1