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

Source for file CustomBar.php

Documentation is available at CustomBar.php

  1. <?php
  2.  
  3. /**
  4.  * CustomBar Class
  5.  *
  6.  * Description: Custom Bar Series
  7.  *
  8.  * @author
  9.  * @copyright Copyright (c) 1995-2008 by Steema Software SL. All Rights Reserved. <info@steema.com>
  10.  * @version 1.0
  11.  * @package TeeChartPHP
  12.  * @subpackage styles
  13.  * @link http://www.steema.com
  14.  */
  15.  
  16.  class CustomBar extends Series {
  17.  
  18.     //private boolean autoBarSize;
  19.     private $autoMarkPosition true;
  20.     private $barStyle;
  21.     private $gradientRelative;
  22.     private $depthPercent 100;
  23.     private $offsetPercent;
  24.     private $sideMargins true;
  25.     private $stackGroup;
  26.     private $iMaxBarPoints;
  27.     private $groups;
  28.     private $numGroups;
  29.     private $styleResolver;
  30.  
  31.     protected $iBarBounds;
  32.     protected $iNumBars;
  33.     protected $iOrderPos;
  34.     protected $iPreviousCount;
  35.     protected $barSizePercent = 70;
  36.     protected $conePercent;
  37.     protected $bDark3D = true;
  38.     protected $iMultiBar;
  39.     protected $bUseOrigin = true;
  40.     protected $dOrigin;
  41.     protected $pPen;
  42.     protected $iBarSize;
  43.     protected $customBarSize;
  44.     protected $normalBarColor;
  45.  
  46.     // Class Definition
  47.  
  48.     // Interceptors
  49.     function __get$property {
  50.       $method ="get{$property}";
  51.       if method_exists$this$method ) ) {
  52.         return $this->$method();
  53.       }
  54.     }
  55.  
  56.     function __set $property,$value {
  57.       $method ="set{$property}";
  58.       if method_exists$this$method ) ) {
  59.         return $this->$method($value);
  60.       }
  61.     }
  62.  
  63.     public function CustomBar($c=null{
  64.  
  65.         $this->iMultiBar = MultiBars::$SIDE;
  66.         $this->barStyle BarStyle::$RECTANGLE;
  67.         $this->iBarBounds = new Rectangle();
  68.  
  69.         $this->groups array();  // TODO review before int[100];
  70.  
  71.         parent::Series($c);
  72.         
  73.         $this->getMarks()->setDefaultVisible(true);
  74.         $this->getMarks()->getCallout()->setDefaultLength(20);
  75.     }
  76.  
  77.     public function setBarStyleResolver($resolver{
  78.         $this->styleResolver $resolver;
  79.     }
  80.  
  81.     public function removeBarStyleResolver({
  82.         $this->styleResolver null;
  83.     }
  84.  
  85.         /**
  86.           * Defines the color Gradient used to fill the Bars.<br>
  87.           * These can be filled with these three colors: StartColor, MidColor,
  88.           * EndColor. You can control the drawing output by setting the Direction
  89.           * method.<br> Use the Visible property to show / hide filling. <br>
  90.           *
  91.           * <p>Example:
  92.           * <pre><font face="Courier" size="4">
  93.           *  $barSeries = new Bar(myChart->getChart());
  94.           *  $barSeries->getMarks()->setVisible(true);
  95.           *  $barSeries->fillSampleValues(6);
  96.           *  $barSeries->setColor(new Color(255,0,0));
  97.           *  $barSeries->setBarStyle(BarStyle::$RECTGRADIENT);
  98.           *  $barSeries->getGradient()->setDirection(GradientDirection::$VERTICAL);
  99.           *  $barSeries->getGradient()->setStartColor(Color.GREEN);
  100.           *  $barSeries->getGradient()->setUseMiddle(false);
  101.           *  $barSeries->getGradient()->setMiddleColor(Color.YELLOW);
  102.           * </font></pre></p>
  103.           *
  104.           * @return Gradient 
  105.           */
  106.     public function getGradient({
  107.         return $this->getBrush()->getGradient();
  108.     }
  109.  
  110.         /**
  111.           * Calculates Colors based on highest bar when Gradient is Visible.<br>
  112.           * Default value: false
  113.           *
  114.           * @return boolean 
  115.           */
  116.     public function getGradientRelative({
  117.         return $this->gradientRelative;
  118.     }
  119.  
  120.         /**
  121.           * Calculates Colors based on highest bar when Gradient is Visible.<br>
  122.           * Default value: false
  123.           *
  124.           * @param value boolean
  125.           */
  126.     public function setGradientRelative($value{
  127.         $this->gradientRelative $this->setBooleanProperty($this->gradientRelative$value);
  128.     }
  129.  
  130.         /**
  131.           * Allows stacking independent Series within the same Chart, in
  132.           * series groups.<br>
  133.           * Default value: 0
  134.           *
  135.           * @return int 
  136.           */
  137.     public function getStackGroup({
  138.         return $this->stackGroup;
  139.     }
  140.  
  141.         /**
  142.           * Allows stacking independent Series within the same Chart, in
  143.           * series groups.<br>
  144.           * Default value: 0 <br>
  145.           *
  146.           * <p>Example:
  147.           * <pre><font face="Courier" size="4">
  148.           * bar1Series.setStackGroup(0);
  149.           * bar2Series.setStackGroup(1);
  150.           * </font></pre></p>
  151.           *
  152.           * @param value int
  153.           */
  154.     public function setStackGroup($value{
  155.         $this->stackGroup $this->setIntegerProperty($this->stackGroup$value);
  156.     }
  157.  
  158.     public function setZPositions({
  159.         parent::setZPositions();
  160.  
  161.         if ($this->depthPercent != 0{
  162.              $tmp (($this->getEndZ($this->getStartZ()) (100 $this->depthPercent*
  163.                              0.005);
  164.             $this->setStartZ($this->getStartZ($tmp);
  165.             $this->setEndZ($this->getEndZ($tmp);
  166.         }
  167.     }
  168.  
  169.         /**
  170.           * Determines the percent amount of bar size in "z" depth direction.
  171.           * Default value: 100%
  172.           *
  173.           * @return int 
  174.           */
  175.     public function getDepthPercent({
  176.         return $this->depthPercent;
  177.     }
  178.  
  179.         /**
  180.           * Determines the percent amount of bar size in "z" depth direction.
  181.           * Default value: 100%
  182.           *
  183.           * <p>Example:
  184.           * <pre><font face="Courier" size="4">
  185.           * series.setDepthPercent(50) ; // % of 3D depth
  186.           * </font></pre></p>
  187.           *
  188.           * @param value int
  189.           */
  190.     public function setDepthPercent($value{
  191.         $this->depthPercent $this->setIntegerProperty($this->depthPercent$value);
  192.     }
  193.  
  194.         /**
  195.           * Darkens sides of bars to enhance 3D effect.<br>
  196.           * This has effect only when Chart.Aspect.View3D is true.
  197.           * High color video modes (greater than 256 colors) will show dark colors
  198.           * much better than 256 or 16 color modes. <br>
  199.           * Default value: true
  200.           *
  201.           * @return boolean 
  202.           */
  203.     public function getDark3D({
  204.         return $this->bDark3D;
  205.     }
  206.  
  207.         /**
  208.           * Darkens sides of bars to enhance 3D effect.<br>
  209.           * Default value: true
  210.           *
  211.           * @param value boolean
  212.           */
  213.     public function setDark3D($value{
  214.         $this->bDark3D = $this->setBooleanProperty($this->bDark3D$value);
  215.     }
  216.  
  217.     public function prepareForGallery($isEnabled{
  218.         parent::prepareForGallery($isEnabled);
  219.         $this->barSizePercent = 85;
  220.         $this->setMultiBar(MultiBars::$NONE);
  221.     }
  222.  
  223.     protected function setBarSizePercent($value{
  224.         $this->barSizePercent = $this->setIntegerProperty($this->barSizePercent$value);
  225.     }
  226.  
  227.     private function setOtherBars($setOthers{
  228.         if ($this->chart != null{
  229.             for $t 0$t $this->chart->getSeriesCount()$t++{
  230.  
  231.                  $s $this->chart->getSeries($t);
  232.  
  233.                 if ($this->sameClass($s)) {
  234.                      $tmpBar $s;
  235.  
  236.                     if ($setOthers{
  237.                         $tmpBar->iMultiBar $this->iMultiBar;
  238.                         $tmpBar->sideMargins $this->sideMargins;
  239.                     else {
  240.                         $this->iMultiBar = $tmpBar->iMultiBar;
  241.                         $this->sideMargins $tmpBar->sideMargins;
  242.                         break;
  243.                     }
  244.  
  245.                     $tmpBar->calcVisiblePoints $this->iMultiBar != MultiBars::$SELFSTACK;
  246.                 }
  247.             }
  248.         }
  249.     }
  250.  
  251.         /**
  252.           * Margin between Chart rectangle and Bars.<br>
  253.           * Default value: true
  254.           *
  255.           * @return boolean 
  256.           */
  257.     public function getSideMargins({
  258.         return $this->sideMargins;
  259.     }
  260.  
  261.         /**
  262.           * Sets a margin between Chart rectangle and Bars.<br>
  263.           * Default value: true
  264.           *
  265.           * @param value boolean
  266.           */
  267.     public function setSideMargins($value{
  268.         $this->sideMargins $this->setBooleanProperty($this->sideMargins$value);
  269.         $this->setOtherBars(true);
  270.     }
  271.  
  272.     protected function shouldSerializeYOrigin({
  273.         return false;
  274.     }
  275.  
  276.         /**
  277.           * Obsolete.&nbsp;Please use CustomBar.<!-- -->Origin instead.
  278.           *
  279.           * @return double 
  280.           */
  281.     public function getYOrigin({
  282.         return $this->dOrigin;
  283.     }
  284.  
  285.         /**
  286.           * Obsolete.&nbsp;Please use CustomBar.<!-- -->Origin instead.
  287.           *
  288.           * @param value double
  289.           */
  290.     public function setYOrigin($value{
  291.         $this->setOrigin($value);
  292.     }
  293.  
  294.         /**
  295.           * Bars to be bottom aligned at the Origin method value. <br>
  296.           * When false, the minimum of all Bar values is used as the Bar origins
  297.           * value. <br>
  298.           * When true, the Origin property is used as the start point for Bars. <br>
  299.           * Default value: true
  300.           *
  301.           * @return boolean 
  302.           */
  303.     public function getUseOrigin({
  304.         return $this->bUseOrigin;
  305.     }
  306.  
  307.         /**
  308.           * Allows Bars to be bottom aligned at the Origin method value. <br>
  309.           * Default value: true
  310.           *
  311.           * @param value boolean
  312.           */
  313.     public function setUseOrigin($value{
  314.         $this->bUseOrigin = $this->setBooleanProperty($this->bUseOrigin$value);
  315.     }
  316.  
  317.         /**
  318.           * The common bottom value used for all Bar points.<br>
  319.           * UseOrigin must be true (the default) to use the Origin property. <br>
  320.           * Bars with a value bigger than Origin are drawn in one direction and
  321.           * Bars with a lower value are drawn in the opposite direction.
  322.           * This applies both to Bar series and HorizBar series classes.<br>
  323.           * Default value: 0
  324.           *
  325.           * @return double 
  326.           */
  327.     public function getOrigin({
  328.         return $this->dOrigin;
  329.     }
  330.  
  331.         /**
  332.           * Sets the common bottom value used for all Bar points.<br>
  333.           * Default value: 0
  334.           *
  335.           * @param value double
  336.           */
  337.     public function setOrigin($value{
  338.         $this->dOrigin = $this->setDoubleProperty($this->dOrigin$value);
  339.     }
  340.  
  341.         /**
  342.           * Repositions Marks on BarSeries to prevent overlapping.<br>
  343.           * Marks are displaced to the top of the Bars to minimize the overlapping
  344.           * effect of Marks with long text or big font sizes.<br>
  345.           * When false, no checking is performed and all Marks are drawn at their
  346.           * Mark.ArrowLength distance to the top of the Bar.<br>
  347.           * Default value: false
  348.           *
  349.           * @return boolean 
  350.           */
  351.     public function getAutoMarkPosition({
  352.         return $this->autoMarkPosition;
  353.     }
  354.  
  355.         /**
  356.           * Repositions Marks on BarSeries to prevent overlapping.<br>
  357.           * Default value: false
  358.           *
  359.           * @param value boolean
  360.           */
  361.     public function setAutoMarkPosition($value{
  362.         $this->autoMarkPosition $this->setBooleanProperty($this->autoMarkPosition$value);
  363.     }
  364.  
  365.         /**
  366.           * The apex size as percentage of the base.<br>
  367.           * Default value: 0
  368.           *
  369.           * @return int 
  370.           */
  371.     public function getConePercent({
  372.         return $this->conePercent;
  373.     }
  374.  
  375.         /**
  376.           * Sets the apex size as a percentage of the base.<br>
  377.           * Default value: 0
  378.           *
  379.           * @param value int
  380.           */
  381.     public function setConePercent($value{
  382.         $this->conePercent = $this->setIntegerProperty($this->conePercent$value);
  383.     }
  384.  
  385.         /**
  386.           * The Bar displacement as percentage of Bar size.<br>
  387.           * Displacement is horizontal for Bar series and vertical for HorizBar
  388.           * series. It can be used to create "overlayed" Bar charts.
  389.           * You can specify positive or negative values. <br>
  390.           * Default value: 0
  391.           *
  392.           * @return int 
  393.           */
  394.     public function getOffsetPercent({
  395.         return $this->offsetPercent;
  396.     }
  397.  
  398.         /**
  399.           * Sets the Bar displacement as percentage of Bar size.<br>
  400.           * Default value: 0
  401.           *
  402.           * @param value int
  403.           */
  404.     public function setOffsetPercent($value{
  405.         $this->offsetPercent $this->setIntegerProperty($this->offsetPercent$value);
  406.     }
  407.  
  408.         /**
  409.           * Defines the Bar shape used to draw Bars.<br>
  410.           * Default value: BarStyle.Rectangle
  411.           *
  412.           *
  413.           * @return BarStyle 
  414.           */
  415.     public function getBarStyle({
  416.         return $this->barStyle;
  417.     }
  418.  
  419.         /**
  420.           * Defines the Bar shape used to draw Bars.<br>
  421.           * Default value: BarStyle.Rectangle
  422.           *
  423.           *
  424.           * @param value BarStyle
  425.           */
  426.     public function setBarStyle($value{
  427.         if ($this->barStyle != $value{
  428.             $this->barStyle $value;
  429.             /* TODO if ($this->barStyle == BarStyle::$RECTGRADIENT) {
  430.                 $this->getGradient()->setVisible(true);
  431.             } else {
  432.                 $this->getGradient()->setVisible(false);
  433.             }
  434.             */            
  435.             $this->invalidate();
  436.         }
  437.     }
  438.  
  439.         /**
  440.           * Defines the Brush used to fill Bars.<br>
  441.           * When BarBrush.Style is different than bsSolid, the Series.Color color
  442.           * is the background bar color.
  443.           *
  444.           * @return ChartBrush 
  445.           */
  446.     public function getBrush({
  447.         return $this->bBrush;
  448.     }
  449.  
  450.     public function setChart($c{
  451.         parent::setChart($c);
  452.         if ($this->pPen != null{
  453.             $this->pPen->setChart($this->chart);
  454.         }
  455.         if ($this->bBrush != null{
  456.             $this->bBrush->setChart($this->chart);
  457.         }
  458.         $this->setOtherBars(false);
  459.     }
  460.  
  461.         /**
  462.           * Determines how multiple BarSeries will be displayed in the same
  463.           * Chart.<br>
  464.           * If you have more than one Bar series in the same Chart, then you can
  465.           * choose if they will be drawn side-by-side, back-to-front or Stacked.<br>
  466.           * Side-by-side means the Bar width will be divided by the number of Bar
  467.           * Series. <br>
  468.           * Default value: MultiBars.Side
  469.           *
  470.           * @return MultiBars 
  471.           */
  472.     public function getMultiBar({
  473.         return $this->iMultiBar;
  474.     }
  475.  
  476.         /**
  477.           * Determines how multiple BarSeries will be displayed in the same
  478.           * Chart.<br>
  479.           * Default value: MultiBars.Side
  480.           *
  481.           * @param value MultiBars
  482.           */
  483.     public function setMultiBar($value{
  484.         if ($this->iMultiBar != $value{
  485.             $this->iMultiBar = $value;
  486.             $this->setOtherBars(true);
  487.             $this->invalidate();
  488.         }
  489.     }
  490.  
  491.         /**
  492.           * Pen used to draw the Bar rectangles.<br>
  493.           * You can set BarPen.Visible = false to hide these lines.
  494.           *
  495.           * @return ChartPen 
  496.           */
  497.     public function getPen({
  498.         if ($this->pPen == null{
  499.             $tmpColor new Color(0,0,0);
  500.             $this->pPen = new ChartPen($this->chart$tmpColor);
  501.         }
  502.         return $this->pPen;
  503.     }
  504.  
  505.         /**
  506.           * Coordinates of current Bar point being displayed.<br>
  507.           * Run-time and read-only. <br>
  508.           * This function returns an internal variable, that is calculated only
  509.           * when the Bar Series DrawValue method is called.<br>
  510.           * You should only use BarBounds in custom-derived series, after
  511.           * calling the "inherited DrawValue" method.
  512.           *
  513.           * @return Rectangle 
  514.           */
  515.     public function getBarBounds({
  516.         return $this->iBarBounds;
  517.     }
  518.  
  519.     protected function getBarBoundsMidX({
  520.         return ($this->iBarBounds->getLeft($this->iBarBounds->getRight()) 2;
  521.     }
  522.  
  523.     private function calcGradientColor($valueIndex{
  524.          $g $this->getGradient();
  525.  
  526.         if ($this->gradientRelative{
  527.              $tmp $this->bUseOrigin ? $this->dOrigin : $this->mandatory->getMinimum();
  528.              $tmpRatio ($this->mandatory->value[$valueIndex$tmp/
  529.                               ($this->mandatory->getMaximum($tmp);
  530.  
  531.              $t0 $g->getStartColor()->getRed();
  532.              $t1 $g->getStartColor()->getGreen();
  533.              $t2 $g->getStartColor()->getBlue();
  534.  
  535. /* TODO            $g->setEndColor($this->Color->fromArgb(
  536.                     $g->getStartColor()->getAlpha(),
  537.                     ($this->t0 +
  538.                      MathUtils::round($tmpRatio * ($this->normalBarColor->getRed() - $t0))),
  539.                     ($this->t1 +
  540.                      MathUtils::round($tmpRatio *
  541.                                      ($this->normalBarColor->getGreen() - $t1))),
  542.                     ($this->t2 +
  543.                      MathUtils::round($tmpRatio * ($this->normalBarColor->getBlue() - $t2))))
  544.                     );*/
  545.  
  546.         else {
  547.             $g->setEndColor($this->normalBarColor);
  548.         }
  549.     }
  550.  
  551.     protected function doGetBarStyle($valueIndex{
  552.          $style $this->barStyle;
  553.         if ($this->styleResolver != null{
  554.             $style $this->styleResolver->getStyle($this$valueIndex$style);
  555.         }
  556.         return $style;
  557.     }
  558.  
  559.     protected function internalCalcMarkLength($valueIndex// abstract
  560.         return 0;
  561.     }
  562.  
  563.     private function internalPointOrigin($valueIndex$sumAll{
  564.          $result 0;
  565.          $tmpValue $this->mandatory->value[$valueIndex];
  566.  
  567.         if ($this->chart != null{
  568.             for $t 0$t $this->chart->getSeriesCount()$t++{
  569.                  $s $this->chart->getSeries($t);
  570.                 if ((!$sumAll&& ($s === $this)) {
  571.                     break;
  572.                 else
  573.                 if ($s->getActive(&& $this->sameClass($s&& ($s->getCount($valueIndex)
  574.                     && ($s->stackGroup == $this->stackGroup)) {
  575.  
  576.                      $tmp $s->getOriginValue($valueIndex);
  577.                     if ($tmpValue 0{
  578.                         if ($tmp 0{
  579.                             $result += $tmp;
  580.                         }
  581.                     else
  582.                     if ($tmp 0{
  583.                         $result += $tmp/* 5.01 */
  584.                     }
  585.                 }
  586.             }
  587.         }
  588.         return $result;
  589.     }
  590.  
  591.     protected function doGradient3D($valueIndex$p0$p1{
  592.         if ($this->pPen->getVisible()) {
  593.             $p0->x++;
  594.             $p0->y++;
  595.              $w MathUtils::round($this->pPen->getWidth()) 1;
  596.             $p1->-= $w;
  597.             $p1->-= $w;
  598.         }
  599.  
  600.         $this->calcGradientColor($valueIndex);
  601.         $this->getGradient()->draw($this->chart->getGraphics3D()$p0->x$p0->y$p1->x$p1->y);
  602.     }
  603.  
  604.         /**
  605.           * For internal use.<br>
  606.           * Displays a Bar or HorizBar point using the parameter coordinates and
  607.           * the BarColor parameter. <br>
  608.           * It is internally called for each point in the Series. <br>
  609.           * The BarStyle property determines the type of graphical representation
  610.           * of every point (ie: Rectangle, Ellipse, Pyramid, etc).
  611.           *
  612.           * @param barColor Color
  613.           * @param Rectangle
  614.           */
  615.     public function barRectangle($barColor$r{
  616.         $this->_barRectangle($barColor$r->x$r->y$r->getRight()$r->getBottom());
  617.     }
  618.  
  619.         /**
  620.           * For internal use.<br>
  621.           * Displays a Bar or HorizBar point using the parameter coordinates and
  622.           * the BarColor parameter. <br>
  623.           * It is internally called for each point in the Series. <br>
  624.           * The BarStyle property determines the type of graphical representation
  625.           * of every point (ie: Rectangle, Ellipse, Pyramid, etc).
  626.           *
  627.           * @param barColor Color
  628.           * @param aLeft int
  629.           * @param aTop int
  630.           * @param aRight int
  631.           * @param aBottom int
  632.           */
  633.     public function _barRectangle($barColor$aLeft$aTop$aRight$aBottom{
  634.          $g $this->chart->getGraphics3D();
  635.         if ($this->bBrush->getSolid()) {
  636.             if (($aRight == $aLeft|| ($aTop == $aBottom)) {
  637.                 $g->getPen()->setColor($g->getBrush()->getColor());
  638.                 $g->getPen()->setVisible(true);
  639.                 $g->line($aLeft$aTop$aRight$aBottom);
  640.             else
  641.             if ((abs($aRight $aLeft$g->getPen()->getWidth()) ||
  642.                 (abs($aBottom $aTop$g->getPen()->getWidth())) {
  643.                 $g->getPen()->setColor($g->getBrush()->getColor());
  644.                 $g->getPen()->setVisible(true);
  645.                 $g->getBrush()->setVisible(false);
  646.             }
  647.         }
  648.         $tmpR new Rectangle();
  649.         $tmpR->x=$aLeft;
  650.         $tmpR->y=$aTop;
  651.         $tmpR->setRight($aRight);
  652.         $tmpR->setBottom($aBottom);
  653.  
  654.         $g->rectangle($tmpR);
  655.     }
  656.  
  657.     protected function doBarGradient($valueIndex$rect{
  658.         $this->calcGradientColor($valueIndex);
  659.         $this->getGradient()->draw($this->chart->getGraphics3D()$rect);
  660.         if ($this->pPen->getVisible()) {
  661.             $this->chart->getGraphics3D()->getBrush()->setVisible(false);
  662.             $this->barRectangle($this->normalBarColor$this->iBarBounds);
  663.         }
  664.     }
  665.  
  666.     public function getCustomBarWidth({
  667.         return $this->customBarSize;
  668.     }
  669.  
  670.     public function setCustomBarWidth($value{
  671.         $this->customBarSize = $value;
  672.         $this->chart->invalidate();
  673.     }
  674.  
  675.     private function doCalcBarWidth({
  676.  
  677.         if ($this->customBarSize != 0{
  678.             $this->iBarSize = $this->customBarSize;
  679.         else
  680.         if ($this->iMaxBarPoints 0{
  681.              $tmpAxis $this->yMandatory ? $this->getHorizAxis($this->getVertAxis();
  682.  
  683.              $tmp 0;
  684.  
  685.             //                if ( autoBarSize )
  686.             //                    tmp=MathUtils.round(tmpAxis.IAxisSize/(2.0+tmpAxis.Maximum-tmpAxis.Minimum));
  687.             //                else
  688.             {
  689.                 if ($this->sideMargins{
  690.                     $this->iMaxBarPoints++;
  691.                 }
  692.                 $tmp $tmpAxis->iAxisSize $this->iMaxBarPoints;
  693.             }
  694.  
  695.             $this->iBarSize = MathUtils::round(($this->barSizePercent * 0.01$tmp/
  696.                        max(1$this->iNumBars);
  697.             if (($this->iBarSize % 2== 1{
  698.                 $this->iBarSize++;
  699.             }
  700.         else {
  701.             $this->iBarSize = 0;
  702.         }
  703.     }
  704.  
  705.         /**
  706.           * Returns side margin amount in pixels.
  707.           *
  708.           * @return int 
  709.           */
  710.     public function barMargin({
  711.         $result $this->iBarSize;
  712.         if ($this->iMultiBar != MultiBars::$SIDEALL{
  713.             $result *= $this->iNumBars;
  714.         }
  715.         if (!$this->sideMargins{
  716.             $result /= 2;
  717.         }
  718.         return $result;
  719.     }
  720.  
  721.     protected function internalApplyBarMargin($margins{
  722.         $this->doCalcBarWidth();
  723.          $tmp $this->barMargin();
  724.         $margins->min += $tmp;
  725.         $margins->max += $tmp;
  726.     }
  727.  
  728.     protected function internalGetOriginPos($valueIndex$defaultOrigin{
  729.          $result 0;
  730.  
  731.          $tmpValue $this->pointOrigin($valueIndexfalse);
  732.  
  733.         if (($this->iMultiBar == MultiBars::$STACKED|
  734.             ($this->iMultiBar == MultiBars::$SELFSTACK)) {
  735.             $result $this->calcPosValue($tmpValue);
  736.         else
  737.         if ($this->iMultiBar == MultiBars::$STACKED100{
  738.              $tmp $this->pointOrigin($valueIndextrue);
  739.             $result ($tmp != 0$this->calcPosValue($tmpValue 100.0 $tmp0;
  740.         else {
  741.             $result $this->bUseOrigin ? $this->calcPosValue($tmpValue$defaultOrigin;
  742.         }
  743.  
  744.         return $result;
  745.     }
  746.  
  747.     protected function maxMandatoryValue($value{
  748.         $result 0;
  749.  
  750.         if ($this->iMultiBar == MultiBars::$STACKED100{
  751.             $result 100;
  752.         else {
  753.             $result $value;
  754.  
  755.             if ($this->iMultiBar == MultiBars::$SELFSTACK{
  756.                 $result $this->mandatory->getTotal();
  757.             else
  758.             if ($this->iMultiBar == MultiBars::$STACKED{
  759.                 for $t 0$t $this->getCount()$t++{
  760.                      $tmp $this->pointOrigin($tfalse$this->mandatory->value[$t];
  761.                     if ($tmp $result{
  762.                         $result $tmp;
  763.                     }
  764.                 }
  765.             }
  766.             if ($this->bUseOrigin && ($result $this->dOrigin)) {
  767.                 $result $this->dOrigin;
  768.             }
  769.         }
  770.         return $result;
  771.     }
  772.  
  773.         /**
  774.           * For Internal Use.<br>
  775.           * The PointOrigin function returns the summed values of more than one
  776.           * Series point.<br>
  777.           * It's only used by Series types with Stacked or Stacked 100% styles such
  778.           * as BarSeries, HorizBar series and Area series.
  779.           *
  780.           * @param valueIndex int
  781.           * @param sumAll boolean
  782.           * @return double 
  783.           */
  784.     public function pointOrigin($valueIndex$sumAll{
  785.         if (($this->iMultiBar == MultiBars::$STACKED||
  786.             ($this->iMultiBar == MultiBars::$STACKED100)) {
  787.             return $this->internalPointOrigin($valueIndex$sumAll);
  788.         else
  789.         if ($this->iMultiBar == MultiBars::$SELFSTACK{
  790.              $result 0;
  791.             for $t 0$t $valueIndex$t++{
  792.                 $result += $this->mandatory->value[$t];
  793.             }
  794.             return $result;
  795.         else {
  796.             return $this->dOrigin;
  797.         }
  798.     }
  799.  
  800.     protected function minMandatoryValue($value{
  801.         $result 0;
  802.  
  803.         if ($this->iMultiBar == MultiBars::$STACKED100{
  804.             $result 0;
  805.         else {
  806.             $result $value;
  807.             if (($this->iMultiBar == MultiBars::$STACKED||
  808.                 ($this->iMultiBar == MultiBars::$SELFSTACK)) {
  809.                 for $t 0$t $this->getCount()$t++{
  810.                      $tmp $this->pointOrigin($tfalse$this->mandatory->value[$t];
  811.                     if ($tmp $result{
  812.                         $result $tmp;
  813.                     }
  814.                 }
  815.             }
  816.             if ($this->bUseOrigin && ($result $this->dOrigin)) {
  817.                 $result $this->dOrigin;
  818.             }
  819.         }
  820.         return $result;
  821.     }
  822.  
  823.     public function calcZOrder({
  824.  
  825.         if ($this->iMultiBar == MultiBars::$NONE{
  826.             parent::calcZOrder();
  827.         else {
  828.              $tmpZOrder = -1;
  829.             for $t 0$t $this->chart->getSeriesCount()$t++{
  830.                  $s $this->chart->getSeries($t);
  831.                 if ($s->getActive()) {
  832.                     if ($s === $this{
  833.                         break;
  834.                     else
  835.                     if ($this->sameClass($s)) {
  836.                         $tmpZOrder $s->getZOrder();
  837.                         break;
  838.                     }
  839.                 }
  840.             }
  841.  
  842.             if ($tmpZOrder == -1{
  843.                 parent::calcZOrder();
  844.             else {
  845.                 $this->iZOrder = $tmpZOrder;
  846.             }
  847.         }
  848.     }
  849.  
  850.     private function newGroup($aGroup{
  851.         for $t 0$t $this->numGroups$t++{
  852.             if ($this->groups[$t== $aGroup{
  853.                 return false;
  854.             }
  855.         }
  856.  
  857.         $this->groups[$this->numGroups$aGroup;
  858.         $this->numGroups++;
  859.         return true;
  860.     }
  861.  
  862.         // if more than one bar series exists in chart,
  863.         // which position are we? the first, the second, the third?
  864.     public function doBeforeDrawChart({
  865.  
  866.         parent::doBeforeDrawChart();
  867.  
  868.         $this->iOrderPos = 1;
  869.         $this->iPreviousCount = 0;
  870.         $this->iNumBars = 0;
  871.         $this->iMaxBarPoints = -1;
  872.         $this->numGroups 0;
  873.  
  874.         $stop false;
  875.  
  876.         for $t 0$t $this->chart->getSeriesCount()$t++{
  877.              $s $this->chart->getSeries($t);
  878.             if ($s->getActive(&& $this->sameClass($s)) {
  879.  
  880.                 $stop |= ($s === $this);
  881.  
  882.                  $tmp $s->getCount();
  883.  
  884.                 if (($this->iMaxBarPoints == -1|| ($tmp $this->iMaxBarPoints)) {
  885.                     $this->iMaxBarPoints $tmp;
  886.                 }
  887.  
  888.                 if ($this->iMultiBar == MultiBars::$NONE{
  889.                     $this->iNumBars = 1;
  890.                 else
  891.                 if (($this->iMultiBar == MultiBars::$SIDE|
  892.                     ($this->iMultiBar == MultiBars::$SIDEALL)) {
  893.                     $this->iNumBars++;
  894.                     if (!$stop{
  895.                         $this->iOrderPos++;
  896.                     }
  897.                 else
  898.                 if (($this->iMultiBar == MultiBars::$STACKED|
  899.                     ($this->iMultiBar == MultiBars::$STACKED100)) {
  900.                     if ($this->newGroup($s->stackGroup)) {
  901.                         $this->iNumBars++;
  902.                         if (!$stop{
  903.                             $this->iOrderPos++;
  904.                         }
  905.                     }
  906.                 else
  907.                 if ($this->iMultiBar == MultiBars::$SELFSTACK{
  908.                     $this->iNumBars = 1;
  909.                 }
  910.  
  911.                 if (!$stop{
  912.                     $this->iPreviousCount += $tmp;
  913.                 }
  914.             }
  915.  
  916.             for $tt 0$tt $this->numGroups$tt++{
  917.                 if ($this->groups[$tt== $this->stackGroup{
  918.                     $this->iOrderPos = $tt 1;
  919.                     break;
  920.                 }
  921.             }
  922.  
  923.             // this should be done after calculating INumBars
  924.             if ($this->chart->getPage()->getMaxPointsPerPage(0{
  925.                 $this->iMaxBarPoints $this->chart->getPage()->getMaxPointsPerPage();
  926.             }
  927.         }
  928.     }
  929.  
  930.     protected function drawLegendShape($g$valueIndex$rect{
  931.         if ($this->getBrush()->getImage(!= null{
  932.             $g->getBrush()->setImage($this->bBrush->getImage());
  933.         }
  934.         parent::drawLegendShape($g$valueIndex$rect);
  935.     }
  936.  
  937.     protected function applyBarOffset($position{
  938.         $result $position;
  939.         if ($this->offsetPercent != 0{
  940.             $result += MathUtils::round($this->offsetPercent $this->iBarSize * 0.01);
  941.         }
  942.         return $result;
  943.     }
  944.  
  945.     protected function calcMarkLength($valueIndex{
  946.         if (($this->getCount(0&& $this->getMarks()->getVisible()) {
  947.              $this->chart->getGraphics3D()->setFont($this->getMarks()->getFont());
  948.              $result $this->getMarks()->getArrowLength(+
  949.                          $this->internalCalcMarkLength($valueIndex);
  950.             if ($this->getMarks()->getPen()->getVisible()) {
  951.                 $result += MathUtils::round($this->getMarks()->getPen()->getWidth());
  952.             }
  953.             return $result;
  954.         else {
  955.             return 0;
  956.         }
  957.     }
  958.  
  959.     protected function internalClicked($valueIndex$point{
  960.         return false;
  961.     }
  962.  
  963.         /**
  964.           * Returns the ValueIndex of the "clicked" point in the Series.<br>
  965.           * Clicked means the X and Y coordinates are in the point screen region
  966.           * bounds. If no point is "touched", Clicked returns -1
  967.           *
  968.           * @param int
  969.           * @param int
  970.           * @return int 
  971.           */
  972.     public function clicked($x$y{
  973.         if ($this->chart != null{
  974.              $p $this->chart->getGraphics3D()->calculate2DPosition($x$y,
  975.                     $this->getStartZ());
  976.             $x $p->x;
  977.             $y $p->y;
  978.         }
  979.  
  980.         if (($this->firstVisible > -1&& ($this->lastVisible > -1)) {
  981.              $p new TeePoint($x$y);
  982.             for $t $this->firstVisible;
  983.                          $t <= min($this->lastVisible$this->getCount(1);
  984.                          $t++{
  985.                 if ($this->internalClicked($t$p)) {
  986.                     return $t;
  987.                 }
  988.             }
  989.         }
  990.         return -1;
  991.     }
  992.  
  993.     protected function numSampleValues({
  994.         if (($this->chart != null&& ($this->chart->getSeriesCount(1)) {
  995.             for $t 0$t $this->chart->getSeriesCount()$t++{
  996.                  $s $this->chart->getSeries($t);
  997.                 if (($s != $this&& ($s instanceof CustomBar&&
  998.                     ($s->getCount(0)) {
  999.                     return $s->getCount();
  1000.                 }
  1001.             }
  1002.         }
  1003.         return 6;
  1004.     }
  1005.  
  1006.     protected function setPenBrushBar($barColor{
  1007.         $this->chart->getGraphics3D()->setPen($this->pPen);
  1008. /* todo change the isnull         if ($barColor->isNull()) {
  1009.             $this->chart->getGraphics3D()->getPen()->setColor($barColor);
  1010.         }                 */
  1011.         if ($this->getBrush()->getColor()->isEmpty()) {
  1012.             $this->getBrush()->setColor($this->getColor());
  1013.         }
  1014.         $this->chart->setBrushCanvas($barColor$this->getBrush()$this->getColor())// $TTrack //#1482
  1015.     }
  1016.  
  1017.     protected function subGalleryStack({
  1018.         return true;
  1019.     }
  1020.  
  1021. /* TODO    public function createSubGallery(
  1022.                                                                   addSubChart) {
  1023.                 super.createSubGallery(addSubChart);
  1024.                 addSubChart.createSubChart(Language.getString("Colors"));
  1025.                 addSubChart.createSubChart(Language.getString("Pyramid"));
  1026.                 addSubChart.createSubChart(Language.getString("Ellipse"));
  1027.                 addSubChart.createSubChart(Language.getString("InvPyramid"));
  1028.                 addSubChart.createSubChart(Language.getString("Gradient"));
  1029.  
  1030.                 if (subGalleryStack()) {
  1031.                         addSubChart.createSubChart(Language.getString("Stack"));
  1032.                         addSubChart.createSubChart(Language.getString("Stack"));
  1033.                         addSubChart.createSubChart(Language.getString("SelfStack"));
  1034.                 }
  1035.  
  1036.                 addSubChart.createSubChart(Language.getString("Sides"));
  1037.                 addSubChart.createSubChart(Language.getString("SideAll"));
  1038.         }
  1039. */
  1040.  
  1041. /*    public function setSubGallery($index) {
  1042.         switch ($index) {
  1043.         case 0:
  1044.             break;
  1045.         case 1:
  1046.             $this->setColorEach(true);
  1047.             break;
  1048.         case 2:
  1049.             $this->setBarStyle(BarStyle::$PYRAMID);
  1050.             break;
  1051.         case 3:
  1052.             $this->setBarStyle(BarStyle::$ELLIPSE);
  1053.             break;
  1054.         case 4:
  1055.             $this->setBarStyle(BarStyle::$INVPYRAMID);
  1056.             break;
  1057.         case 5:
  1058.             $this->setBarStyle(BarStyle::$RECTGRADIENT);
  1059.             break;
  1060.         default: {
  1061.  
  1062.             if (($this->chart != null) &&
  1063.                 ($this->chart->getSeriesCount() == 1)) {
  1064.                 $this->fillSampleValues(2);
  1065.  
  1066.                 try {
  1067.                     try {
  1068.                          $tmp = ($this->Series) $this->getClass()->newInstance();
  1069.                         $this->getChart()->addSeries($tmp);
  1070.                         $tmp->setTitle(""); // <--      $and $this->others
  1071.                         $tmp->fillSampleValues(2);
  1072.                         $tmp->getMarks()->setVisible(false);
  1073.                         (($this->CustomBar) ($tmp))->barSizePercent = $this->barSizePercent;
  1074.                         $this->getMarks()->setVisible(false);
  1075.                         $tmp->setSubGallery($index);
  1076.                     } catch ( $e) {
  1077.                     }
  1078.                 } catch ( $e) {
  1079.                 }
  1080.             }
  1081.  
  1082.             if (!$subGalleryStack()) {
  1083.                 $index += 3;
  1084.             }
  1085.  
  1086.             switch ($index) {
  1087.             case 6:
  1088.                 $this->setMultiBar(MultiBars::$STACKED);
  1089.                 break;
  1090.             case 7:
  1091.                 $this->setMultiBar(MultiBars::$STACKED100);
  1092.                 break;
  1093.             case 8:
  1094.                 $this->setMultiBar(MultiBars::$SELFSTACK);
  1095.                 break;
  1096.             case 9:
  1097.                 $this->setMultiBar(MultiBars::$SIDE);
  1098.                 break;
  1099.             case 10:
  1100.                 $this->setMultiBar(MultiBars::$SIDEALL);
  1101.                 break;
  1102.             default:
  1103.                 parent::setSubGallery($index);
  1104.             }
  1105.             break;
  1106.         }
  1107.         }
  1108.     }
  1109.   */
  1110.     /* tODO public $BarStyleResolver ${
  1111.         public function getStyle($series, $valueIndex, $style);
  1112.         }
  1113.         */
  1114. }
  1115.  
  1116. ?>

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