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

Source for file Bar.php

Documentation is available at Bar.php

  1. <?php
  2.  
  3. /**
  4.  * Bar Class
  5.  *
  6.  * Description: The Bar Series component outputs all points as vertical
  7.  * bars
  8.  *
  9.  * @author
  10.  * @copyright Copyright (c) 1995-2008 by Steema Software SL. All Rights Reserved. <info@steema.com>
  11.  * @version 1.0
  12.  * @package TeeChartPHP
  13.  * @subpackage styles
  14.  * @link http://www.steema.com
  15.  */
  16.  
  17. class Bar extends CustomBar
  18. {
  19.  
  20.     // Interceptors
  21.     function __get$property {
  22.       $method ="get{$property}";
  23.       if method_exists$this$method ) ) {
  24.         return $this->$method();
  25.       }
  26.     }
  27.  
  28.     function __set $property,$value {
  29.       $method ="set{$property}";
  30.       if method_exists$this$method ) ) {
  31.         return $this->$method($value);
  32.       }
  33.     }
  34.  
  35.    public function Bar($c null)
  36.    {
  37.       parent::CustomBar($c);      
  38.    }
  39.  
  40.    /**
  41.    * Gets descriptive text.
  42.    *
  43.    * @return String 
  44.    */
  45.    public function getDescription()
  46.    {
  47.       return Language::getString("GalleryBar");
  48.    }
  49.  
  50.    /**
  51.    * Determines the percent of total Bar width used.<br>
  52.    * Setting BarWidthPercent = 100 makes joined Bars.<br>
  53.    * You can control how many Bars appear at the same time by using
  54.    * Page.MaxPointsPerPage.<br>
  55.    * Default value: 70
  56.    *
  57.    * @return int 
  58.    */
  59.    public function getBarWidthPercent()
  60.    {
  61.       return $this->barSizePercent;
  62.    }
  63.  
  64.    /**
  65.    * Sets the percent of total Bar width used.<br>
  66.    * Default value: 70
  67.    *
  68.    * @see #getBarWidthPercent
  69.    * @param value int
  70.    */
  71.    public function setBarWidthPercent($value)
  72.    {
  73.       $this->setBarSizePercent($value);
  74.    }
  75.  
  76.    protected function internalCalcMarkLength($valueIndex)
  77.    {
  78.       return $this->chart->getGraphics3D()->getFontHeight();
  79.    }
  80.  
  81.    protected function internalClicked($valueIndex$point)
  82.    {
  83.       $tmpResult false;
  84.  
  85.       $tmpX $this->calcXPos($valueIndex);
  86.  
  87.       if(($point->>= $tmpX&& ($point-><= ($tmpX $this->iBarSize)))
  88.       {
  89.          $tmpY $this->calcYPos($valueIndex);
  90.          $endY $this->getOriginPos($valueIndex);
  91.          if($endY $tmpY)
  92.          {
  93.             $tmpSwap $endY;
  94.             $endY $tmpY;
  95.             $tmpY $tmpSwap;
  96.          }
  97.  
  98.          $tmpStyle $this->getBarStyle();
  99.          if($tmpStyle == BarStyle::$INVPYRAMID)
  100.          {
  101.             $tmpResult GraphicsGD::pointInTriangle($point$tmpX,
  102.             $tmpX $this->iBarSize$tmpY$endY);
  103.          }
  104.          else
  105.             if(($tmpStyle == BarStyle::$PYRAMID)|($tmpStyle == BarStyle::$CONE))
  106.             {
  107.                $tmpResult GraphicsGD::pointInTriangle($point$tmpX,
  108.                $tmpX $this->iBarSize$endY$tmpY);
  109.             }
  110.             else
  111.                if($tmpStyle == BarStyle::$ELLIPSE)
  112.                {
  113.                   $tmpResult GraphicsGD::pointInEllipse($point,
  114.                   new Rectangle($tmpX$tmpY$tmpX $this->iBarSize$endY));
  115.                }
  116.                else
  117.                {
  118.                   $tmpResult ($point->>= $tmpY&& ($point-><= $endY);
  119.                }
  120.       }
  121.       return $tmpResult;
  122.    }
  123.  
  124.    public function calcHorizMargins($margins)
  125.    {
  126.       parent::calcHorizMargins($margins);
  127.       $this->internalApplyBarMargin($margins);
  128.    }
  129.  
  130.    public function calcVerticalMargins($margins)
  131.    {
  132.  
  133.       parent::calcVerticalMargins($margins);
  134.  
  135.       $tmp $this->calcMarkLength(0);
  136.  
  137.       if($tmp 0)
  138.       {
  139.          $tmp++;
  140.          if($this->bUseOrigin && (parent::getMinYValue($this->dOrigin))
  141.          {
  142.             if($this->getVertAxis()->getInverted())
  143.             {
  144.                $margins->min += $tmp;
  145.             }
  146.             else
  147.             {
  148.                $margins->max += $tmp;
  149.             }
  150.          }
  151.  
  152.          if((!$this->bUseOrigin|| (parent::getMaxYValue($this->dOrigin))
  153.          {
  154.             if($this->getVertAxis()->getInverted())
  155.             {
  156.                $margins->max += $tmp;
  157.             }
  158.             else
  159.             {
  160.                $margins->min += $tmp;
  161.             }
  162.          }
  163.       }
  164.    }
  165.  
  166.    /**
  167.    * Called internally. Draws the "ValueIndex" point of the Series.
  168.    *
  169.    * @param valueIndex int
  170.    */
  171.    public function drawValue($valueIndex)
  172.    {
  173.  
  174.       parent::drawValue($valueIndex);
  175.       $this->normalBarColor = $this->getValueColor($valueIndex);
  176.  
  177.       // if not null...
  178.       $tmpColor new Color(0000true);
  179.       if($this->normalBarColor != $tmpColor)
  180.       {
  181.          $r new Rectangle();
  182.          $r->$this->calcXPos($valueIndex);
  183.  
  184.          if(($this->barSizePercent == 100&& ($valueIndex $this->getCount(1))
  185.          {// 5.02
  186.             $r->width $this->calcXPos($valueIndex 1$r->x;
  187.          }
  188.          else
  189.          {
  190.             $r->width $this->iBarSize + 1;// 5.02
  191.          }
  192.  
  193.          $r->$this->calcYPos($valueIndex);
  194.          $r->height $this->getOriginPos($valueIndex$r->y;
  195.  
  196.          if(!$this->getPen()->getVisible())
  197.          {
  198.             if($r->getBottom($r->y)
  199.             {
  200.                $r->height++;
  201.             }
  202.             else
  203.             {
  204.                $r->y++;
  205.             }
  206.             $r->width++;
  207.          }
  208.  
  209.          $this->iBarBounds = $r;
  210.  
  211.          if($r->getBottom($r->y)
  212.          {
  213.             $this->drawBar($valueIndex$r->y$r->getBottom());
  214.          }
  215.          else
  216.          {
  217.             $this->drawBar($valueIndex$r->getBottom()$r->y);
  218.          }
  219.  
  220.       }
  221.    }
  222.  
  223.    /**
  224.    * Internal use
  225.    *
  226.    * @param barIndex int
  227.    * @param startPos int
  228.    * @param endPos int
  229.    */
  230.    public function drawBar($barIndex$startPos$endPos)
  231.    {
  232.       $this->setPenBrushBar($this->normalBarColor);
  233.  
  234.       $tmpMidX $this->getBarBoundsMidX();
  235.       $tmp $this->doGetBarStyle($barIndex);
  236.  
  237.       $g $this->chart->getGraphics3D();
  238.       $r $this->iBarBounds;   
  239.  
  240.       if($this->chart->getAspect()->getView3D())
  241.       {
  242.          if($tmp == BarStyle::$RECTANGLE)
  243.          {
  244.             $g->cube($r->x$startPos$r->getRight()$endPos$this->getStartZ(),
  245.             $this->getEndZ(),
  246.             $this->bDark3D);
  247.          }
  248.          else
  249.             if($tmp == BarStyle::$PYRAMID)
  250.             {
  251.                $g->pyramid(true$r->x$startPos$r->getRight()$endPos$this->getStartZ(),
  252.                $this->getEndZ(),
  253.                $this->bDark3D);
  254.             }
  255.             else
  256.                if($tmp == BarStyle::$INVPYRAMID)
  257.                {
  258.                   $g->pyramid(true$r->x$endPos$r->getRight()$startPos$this->getStartZ(),
  259.                   $this->getEndZ(),
  260.                   $this->bDark3D);
  261.                }
  262.                else
  263.                   if($tmp == BarStyle::$CYLINDER)
  264.                   {
  265.                      $g->cylinder(true$this->iBarBounds$this->getStartZ()$this->getEndZ()$this->bDark3D);
  266.                   }
  267.                   else
  268.                      if($tmp == BarStyle::$ELLIPSE)
  269.                      {  
  270.                         $g->ellipseRectZ($this->iBarBounds$this->getMiddleZ());
  271.                      }
  272.                      else
  273.                         if($tmp == BarStyle::$ARROW)
  274.                         {
  275.                            $g->arrow(truenew TeePoint($tmpMidX$endPos),
  276.                            new TeePoint($tmpMidX$startPos),
  277.                            $r->width$r->width 2$this->getMiddleZ());
  278.                         }
  279.                         else
  280.                           if($tmp == BarStyle::$INVARROW)
  281.                           {
  282.                              $g->arrow(truenew TeePoint($tmpMidX$startPos),
  283.                              new TeePoint($tmpMidX$endPos),
  284.                              $r->width$r->width 2,$this->getMiddleZ());                            
  285.                           }
  286.                           /* TODO else
  287.                            if($tmp == BarStyle::$RECTGRADIENT)
  288.                            {
  289.                               $g->cube($r->x, $startPos, $r->getRight(), $endPos, $this->getStartZ(),
  290.                               $this->getEndZ(),
  291.                               $this->bDark3D);
  292.                               if($g->getSupportsFullRotation() ||
  293.                               $this->chart->getAspect()->getOrthogonal())
  294.                               {
  295.                                  $this->doGradient3D($barIndex,
  296.                                  $g->calc3DPoint($r->x, $startPos, $this->getStartZ()),
  297.                                  $g->calc3DPoint($r->getRight(), $endPos, $this->getStartZ()));
  298.                               }
  299.                            }
  300.                            */
  301.                            else
  302.                               if($tmp == BarStyle::$CONE)
  303.                               {
  304.                                  $g->cone(true$this->iBarBounds$this->getStartZ()$this->getEndZ()$this->bDark3D,
  305.                                  $this->conePercent);
  306.                               }
  307.       }
  308.       else
  309.       {
  310.          if(($tmp == BarStyle::$RECTANGLE)|
  311.          ($tmp == BarStyle::$CYLINDER))
  312.          {
  313.             $this->barRectangle($this->normalBarColor$this->iBarBounds);
  314.          }
  315.          else
  316.             if(($tmp == BarStyle::$PYRAMID)|
  317.             ($tmp == BarStyle::$CONE))
  318.             {
  319.                $p array(new TeePoint($r->x$endPos),
  320.                                      new TeePoint($tmpMidX$startPos),
  321.                                      new TeePoint($r->getRight()$endPos));
  322.                $g->polygon($p);
  323.             }
  324.             else
  325.                if($tmp == BarStyle::$INVPYRAMID)
  326.                {
  327.                   $p array(new TeePoint($r->x$startPos),
  328.                                         new TeePoint($tmpMidX$endPos),
  329.                                         new TeePoint($r->getRight()$startPos));
  330.                   $g->polygon($this->p);
  331.                }
  332.                else
  333.                   if($tmp == BarStyle::$ELLIPSE)
  334.                   {
  335.                      $g->ellipseRect($this->iBarBounds);
  336.                   }
  337.                   else
  338.                      if($tmp == BarStyle::$ARROW)
  339.                      {
  340.                         $g->arrow(truenew TeePoint($tmpMidX$endPos),
  341.                         new TeePoint($tmpMidX$startPos),
  342.                         $r->width$r->width 2$this->getMiddleZ());
  343.                      }
  344.                      else
  345.                       if($tmp == BarStyle::$INVARROW)
  346.                       {                       
  347.                           $g->arrow(truenew TeePoint($tmpMidX$startPos),
  348.                             new TeePoint($tmpMidX$endPos),
  349.                             $r->width$r->width 2,$this->getMiddleZ());
  350.                       }
  351.                       /* TODO else                                   
  352.                         if($tmp == BarStyle::$RECTGRADIENT)
  353.                         {
  354.                            $this->doBarGradient($barIndex,
  355.                            new Rectangle($r->x, $startPos, $r->getRight() - $r->x,
  356.                            $endPos - $startPos));
  357.                         }
  358.                         */
  359.       }
  360.    }
  361.  
  362.    protected function moreSameZOrder()
  363.    {
  364.       return($this->iMultiBar == MultiBars::$SIDEALLfalse parent::moreSameZOrder();
  365.    }
  366.  
  367.    /**
  368.    * The Screen X pixel coordinate of the ValueIndex Series
  369.    * value.<br>
  370.    * The horizontal Bar position is the "real" X pos + the BarWidth by our
  371.    * BarSeries order.
  372.    *
  373.    * @param valueIndex int
  374.    * @return int 
  375.    */
  376.    public function calcXPos($valueIndex)
  377.    {
  378.  
  379.       $result 0;
  380.  
  381.       if($this->iMultiBar == MultiBars::$SIDEALL)
  382.       {
  383.          $result $this->getHorizAxis()->calcXPosValue($this->iPreviousCount + $valueIndex-
  384.          ($this->iBarSize / 2);
  385.       }
  386.       else
  387.          if($this->iMultiBar == MultiBars::$SELFSTACK)
  388.          {
  389.             $result (parent::calcXPosValue($this->getMinXValue())) ($this->iBarSize / 2);
  390.          }
  391.          else
  392.          {
  393.             $result parent::calcXPos($valueIndex);
  394.  
  395.             if($this->iMultiBar != MultiBars::$NONE)
  396.             {
  397.                $result += MathUtils::round($this->iBarSize *
  398.                (($this->iOrderPos - ($this->iNumBars * 0.5)) 1.0));
  399.             }
  400.             else
  401.             {
  402.                $result -= ($this->iBarSize / 2);
  403.             }
  404.          }
  405.  
  406.       return $this->applyBarOffset($result);
  407.    }
  408.  
  409.    /**
  410.    * The  Screen Y pixel coordinate of the ValueIndex Series value.
  411.    *
  412.    * @param valueIndex int
  413.    * @return int 
  414.    */
  415.    public function calcYPos($valueIndex)
  416.    {
  417.       $result 0;
  418.  
  419.       if(($this->iMultiBar == MultiBars::$NONE)|
  420.       ($this->iMultiBar == MultiBars::$SIDE)|
  421.       ($this->iMultiBar == MultiBars::$SIDEALL))
  422.       {
  423.          $result parent::calcYPos($valueIndex);
  424.       }
  425.       else
  426.       {
  427.          $tmpValue $this->vyValues->value[$valueIndex+
  428.          $this->pointOrigin($valueIndexfalse);
  429.          if(($this->iMultiBar == MultiBars::$STACKED||
  430.          ($this->iMultiBar == MultiBars::$SELFSTACK))
  431.          {
  432.             $result $this->calcYPosValue($tmpValue);
  433.          }
  434.          else
  435.          {
  436.             $tmp $this->pointOrigin($valueIndextrue);
  437.             $result ($tmp != 0$this->calcYPosValue($tmpValue 100.0 $tmp0;
  438.          }
  439.       }
  440.  
  441.       return $result;
  442.    }
  443.  
  444.    protected function drawMark($valueIndex$s$p)
  445.    {
  446.       $difW $this->iBarSize / 2;
  447.       $tmpDistance $this->getMarks()->getCallout()->getDistance();
  448.       $difH $this->getMarks()->getCallout()->getLength($tmpDistance;
  449.  
  450.       if($p->arrowFrom->getY($this->getOriginPos($valueIndex))
  451.       {
  452.          $difH = -$difH $p->height;
  453.          $p->arrowFrom->setY($p->arrowFrom->getY($tmpDistance);
  454.       }
  455.       else
  456.       {
  457.          $p->arrowFrom->setY($p->arrowFrom->getY($tmpDistance);
  458.       }
  459.  
  460.       $p->leftTop->setX($p->leftTop->getX($difW);
  461.       $p->leftTop->setY($p->leftTop->getY($difH);
  462.       $p->arrowTo->setX($p->arrowTo->getX($difW);
  463.       $p->arrowTo->setY($p->arrowTo->getY($difH);
  464.       $p->arrowFrom->setX($p->arrowFrom->getX($difW);
  465.  
  466.       if($this->getAutoMarkPosition())
  467.       {
  468.          $this->getMarks()->antiOverlap($this->firstVisible$valueIndex$p);
  469.       }
  470.  
  471.       parent::drawMark($valueIndex$s$p);
  472.    }
  473.  
  474.    protected function drawSeriesForward($valueIndex)
  475.    {
  476.       if(($this->iMultiBar == MultiBars::$NONE)|
  477.       ($this->iMultiBar == MultiBars::$SIDE)|
  478.       ($this->iMultiBar == MultiBars::$SIDEALL))
  479.       {
  480.          return true;
  481.       }
  482.       else
  483.          if(($this->iMultiBar == MultiBars::$STACKED)|
  484.          ($this->iMultiBar == MultiBars::$SELFSTACK))
  485.          {
  486.             $result $this->vyValues->value[$valueIndex>= $this->dOrigin;
  487.             if($this->getVertAxis()->getInverted())
  488.             {
  489.                $result !$result;
  490.             }
  491.             return $result;
  492.          }
  493.          else
  494.          {
  495.             return !$this->getVertAxis()->getInverted();
  496.          }
  497.    }
  498.  
  499.    /**
  500.    * The corresponding screen pixels coordinate of the leftmost
  501.    * horizontal bar edge.
  502.    *
  503.    * @param valueIndex int
  504.    * @return int 
  505.    */
  506.    public function getOriginPos($valueIndex)
  507.    {
  508.       return $this->internalGetOriginPos($valueIndex$this->getVertAxis()->iEndPos);
  509.    }
  510.  
  511.    /**
  512.    * The Maximum Value of the Series X Values List.
  513.    *
  514.    * @return double 
  515.    */
  516.    public function getMaxXValue()
  517.    {
  518.       if($this->iMultiBar == MultiBars::$SELFSTACK)
  519.       {
  520.          return $this->getMinXValue();
  521.       }
  522.       else
  523.       {
  524.          return($this->iMultiBar == MultiBars::$SIDEALL?
  525.          $this->iPreviousCount + $this->getCount(:
  526.          parent::getMaxXValue();
  527.       }
  528.    }
  529.  
  530.    /**
  531.    * The Minimum Value of the Series X Values List.
  532.    *
  533.    * @return double 
  534.    */
  535.    public function getMinXValue()
  536.    {
  537.  
  538.       if($this->iMultiBar == MultiBars::$SELFSTACK)
  539.       {
  540.          return $this->getChart()->getSeriesIndexOf($this);
  541.       }
  542.       else
  543.       {
  544.          return parent::getMinXValue();
  545.       }
  546.    }
  547.  
  548.    /**
  549.    * The Maximum Value of the Series Y Values List.
  550.    *
  551.    * @return double 
  552.    */
  553.    public function getMaxYValue()
  554.    {
  555.       return $this->maxMandatoryValue(parent::getMaxYValue());
  556.    }
  557.  
  558.    /**
  559.    * The Minimum Value of the Series Y Values List.
  560.    *
  561.    * @return double 
  562.    */
  563.    public function getMinYValue()
  564.    {
  565.       return $this->minMandatoryValue(parent::getMinYValue());
  566.    }
  567. }
  568.  
  569. ?>

Documentation generated on Wed, 16 Jun 2010 12:03:21 +0200 by phpDocumentor 1.4.1