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

Source for file Volume.php

Documentation is available at Volume.php

  1. <?php
  2.  
  3.  
  4. /**
  5.  * Volume class
  6.  *
  7.  * Description: Volume Series
  8.  *
  9.  * Example:
  10.  * $volumeSeries = new Volume($myChart->getChart());
  11.  * $volumeSeries->getMarks()->setVisible(false);
  12.  * $volumeSeries->setColor(Color::getRed());
  13.  * $volumeSeries->fillSampleValues(50);
  14.  * $volumeSeries->setUseOrigin(true);
  15.  *
  16.  * @author
  17.  * @copyright (c) 1995-2010 by Steema Software SL. All Rights Reserved. <info@steema.com>
  18.  * @version 1.0
  19.  * @package TeeChartPHP
  20.  * @subpackage styles
  21.  * @link http://www.steema.com
  22.  */
  23.  
  24.  class Volume extends Custom {
  25.  
  26.     private $useYOrigin false;
  27.     private $origin;
  28.     private $iColor;
  29.  
  30.     // Interceptors
  31.     function __get$property {
  32.       $method ="get{$property}";
  33.       if method_exists$this$method ) ) {
  34.         return $this->$method();
  35.       }
  36.     }
  37.  
  38.     function __set $property,$value {
  39.       $method ="set{$property}";
  40.       if method_exists$this$method ) ) {
  41.         return $this->$method($value);
  42.       }
  43.     }
  44.  
  45.     public function Volume($c=null{
  46.         parent::Custom($c);
  47.  
  48.         $this->drawArea = false;
  49.         $this->drawBetweenPoints = false;
  50.         $this->setClickableLine(false);
  51.         $this->getPointer()->setDefaultVisible(false);
  52.     }
  53.  
  54.     private function prepareCanvas($g$forced$aColor{
  55.         if ($forced || ($aColor != $this->iColor)) {
  56.             $g->setPen($this->getLinePen());
  57.             $g->getPen()->setColor($aColor);
  58.         }
  59.     }
  60.  
  61.         /**
  62.           * Enables/Disables the Y value that defines the bottom position for Volume
  63.           * points.<br>
  64.           * Default value: false
  65.           *
  66.           * @return boolean 
  67.           */
  68.     public function getUseOrigin({
  69.         return $this->useYOrigin;
  70.     }
  71.  
  72.         /**
  73.           * Enables/Disables the Y value that defines the bottom position for Volume
  74.           * points.<br>
  75.           * Default value: false
  76.           *
  77.           * @param value boolean
  78.           */
  79.     public function setUseOrigin($value{
  80.         $this->useYOrigin $this->setBooleanProperty($this->useYOrigin$value);
  81.     }
  82.  
  83.         /**
  84.           * Defines the YValue used as the origin for the specified Volume Series.
  85.           * <br>
  86.           * Default value: 0
  87.           *
  88.           * @return double 
  89.           */
  90.     public function getOrigin({
  91.         return $this->origin;
  92.     }
  93.  
  94.         /**
  95.           * Defines the YValue used as the origin for the specified Volume Series.
  96.           * <br>
  97.           * Default value: 0
  98.           *
  99.           * @param value double
  100.           */
  101.     public function setOrigin($value{
  102.         $this->origin $this->setDoubleProperty($this->origin$value);
  103.     }
  104.  
  105.     protected function addSampleValues($numValues{
  106.          $r $this->randomBounds($numValues);
  107.  
  108.         for $t 1$t <= $numValues$t++{
  109.             $this->addXY($r->tmpXMathUtils::round($r->DifY 15$r->Random());
  110.             $r->tmpX += $r->StepX;
  111.         }
  112.     }
  113.  
  114.     public function createSubGallery($addSubChart{
  115.         parent::createSubGallery($addSubChart);
  116.         $addSubChart->createSubChart(Language::getString("Dotted"));
  117.         $addSubChart->createSubChart(Language::getString("Colors"));
  118.         $addSubChart->createSubChart(Language::getString("Origin"))// 5.02
  119.     }
  120.  
  121.     public function setSubGallery($index{
  122.         switch ($index{
  123.         case 1:
  124.             $tmpDashStyle new DashStyle();
  125.             $this->getLinePen()->setStyle($tmpDashStyle->DOT);
  126.             break;
  127.         case 2:
  128.             $this->setColorEach(true);
  129.             break;
  130.         case 3:
  131.             $this->setUseOrigin(true);
  132.             break;
  133.         default:
  134.             parent::setSubGallery($index);
  135.         }
  136.     }
  137.  
  138.     protected function drawLegendShape($g$valueIndex,$r{
  139.         $this->prepareCanvas($gtrue$this->getValueColor($valueIndex))//$this->CDI
  140.         $g->horizontalLine($r->x$r->getRight()($r->$r->getBottom()) 2);
  141.     }
  142.  
  143.         /**
  144.           * Called internally. Draws the "ValueIndex" point of the Series.
  145.           *
  146.           * @param valueIndex int
  147.           */
  148.     public function drawValue($valueIndex{
  149.          $g $this->chart->getGraphics3D();
  150.         $g->setPen($this->getLinePen());
  151.         $this->prepareCanvas($this->chart->getGraphics3D()$valueIndex == $this->firstVisible$this->getValueColor($valueIndex));
  152.  
  153.         // moves to x,y coordinates and draws a vertical bar to top or bottom,
  154.         // depending on the vertical Axis.Inverted property
  155.  
  156.         if ($this->useYOrigin{
  157.             $tmpY $this->calcYPosValue($this->origin)/* 5.02 */
  158.         else
  159.         if ($this->getVertAxis()->getInverted()) {
  160.             $tmpY $this->getVertAxis()->iStartPos;
  161.         else {
  162.             $tmpY $this->getVertAxis()->iEndPos;
  163.         }
  164.  
  165.         if ($this->chart->getAspect()->getView3D()) {
  166.             $g->verticalLine($this->calcXPos($valueIndex)$this->calcYPos($valueIndex)$tmpY,
  167.                            $this->getMiddleZ());
  168.         else {
  169.             $g->verticalLine($this->calcXPos($valueIndex)$tmpY$this->calcYPos($valueIndex));
  170.             /* 5.02 */
  171.         }
  172.     }
  173.  
  174.                 /**
  175.           * Returns the ValueIndex of the "clicked" point in the Series.
  176.           *
  177.           * @param int
  178.           * @param int
  179.           * @return int 
  180.           */
  181.     public function clicked($x$y{
  182.         if ($this->chart != null{
  183.             $p $this->chart->getGraphics3D()->calculate2DPosition($x$y$this->getStartZ());
  184.             $x $p->getX();
  185.             $y $p->getY();
  186.  
  187.             $tmpOrigin=$this->originPosition();
  188.             $tmpX;
  189.  
  190.             if (($this->firstVisible > -1&& ($this->lastVisible > -1)) {
  191.                 for $t $this->firstVisible$t <= $this->lastVisible$t++{
  192.                     $tmpX=$this->calcXPos($t);
  193.  
  194.                     if (Graphics3D::pointInLineTolerance($p,new TeePoint($tmpX,$tmpOrigin),
  195.                             new TeePoint($tmpX,$this->calcYPos($t)),$this->getLinePen()->getWidth()))
  196.                     {
  197.                         $this->doClickPointer($t$x$y);
  198.                         return $t;
  199.                     }
  200.                 }
  201.             }
  202.         }
  203.         return -1;
  204.     }
  205.  
  206.     public function originPosition()
  207.         {
  208.               if (useYOrigin)
  209.                   return calcYPosValue(this.getOrigin());
  210.             else
  211.               if (getVertAxis().getInverted())
  212.                   return (int)Math.round(getVertAxis().iStartPos);
  213.               else return (int)Math.round(getVertAxis().iEndPos);
  214.         }
  215.  
  216.     public function prepareForGallery($isEnabled{
  217.         parent::prepareForGallery($isEnabled);
  218.         $this->fillSampleValues(26);
  219.         $this->point->setInflateMargins(true);
  220.     }
  221.  
  222.     public function setColor($color{
  223.         parent::setColor($color);
  224.         $this->getLinePen()->setColor($color);
  225.     }
  226.  
  227.     protected function numSampleValues({
  228.         return 40;
  229.     }
  230.  
  231.         /**
  232.           * Gets descriptive text.
  233.           *
  234.           * @return String 
  235.           */
  236.     public function getDescription({
  237.         return Language::getString("GalleryVolume");
  238.     }
  239. }
  240.  
  241. ?>

Documentation generated on Wed, 16 Jun 2010 12:09:13 +0200 by phpDocumentor 1.4.1