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

Source for file Histogram.php

Documentation is available at Histogram.php

  1. <?php
  2.  
  3. /**
  4.  * Histogram class
  5.  *
  6.  * Description: Histogram Series
  7.  *
  8.  * Example:
  9.  * $series = new Histogram($myChart->getChart());
  10.  * $series->fillSampleValues(10);
  11.  *
  12.  * @author
  13.  * @copyright (c) 1995-2008 by Steema Software SL. All Rights Reserved. <info@steema.com>
  14.  * @version 1.0
  15.  * @package TeeChartPHP
  16.  * @subpackage styles
  17.  * @link http://www.steema.com
  18.  */
  19.  
  20.  class Histogram extends BaseLine {
  21.  
  22.     private $linesPen;
  23.     private $previous;
  24.  
  25.     public function Histogram($c=null{
  26.         parent::BaseLine($c);
  27.         
  28.         $this->calcVisiblePoints = false;
  29.         $this->getLinePen()->setColor(new Color(0,0,0));
  30.     }
  31.  
  32.     /**
  33.     * Determines the pen to be used for drawing the line connecting all
  34.     * points.
  35.     *
  36.     * @return ChartPen 
  37.     */
  38.     public function getLinesPen({
  39.         if ($this->linesPen == null{
  40.             $this->linesPen new ChartPen($this->chartnew Color(0,0,0));
  41.         }
  42.         return $this->linesPen;
  43.     }
  44.  
  45.     /**
  46.     * Defines the Brush fill for the Histogram series.
  47.     *
  48.     * @return ChartBrush 
  49.     */
  50.     public function getBrush({
  51.         return $this->bBrush;
  52.     }
  53.  
  54.     public function setChart($c{
  55.         parent::setChart($c);
  56.  
  57.         if ($this->linesPen != null{
  58.             $this->linesPen->setChart($c);
  59.         }
  60.  
  61.         if ($this->bBrush != null{
  62.             $this->bBrush->setChart($c);
  63.         }
  64.     }
  65.  
  66.     /**
  67.     * The Transparency level from 0 to 100%.
  68.     * Default value: 0
  69.     *
  70.     * @return int 
  71.     */
  72.     public function getTransparency({
  73.         return $this->bBrush->getTransparency();
  74.     }
  75.  
  76.     /**
  77.     * Sets Transparency level from 0 to 100%.
  78.     * Default value: 0
  79.     *
  80.     * @param int $value 
  81.     */
  82.     public function setTransparency($value{
  83.         $this->bBrush->setTransparency($value);
  84.         $this->repaint();
  85.     }
  86.  
  87.     private function visiblePoints({
  88.         $result $this->chart->getPage()->getMaxPointsPerPage();
  89.         return ($result == 0$this->getCount($result;
  90.     }
  91.  
  92.     public function calcHorizMargins($margins{
  93.         parent::calcHorizMargins($margins);
  94.         $tmp $this->visiblePoints();
  95.         if ($tmp 0{
  96.             $tmp ($this->getHorizAxis()->iAxisSize $this->visiblePoints()) 2;
  97.         }
  98.  
  99.         $margins->min += $tmp;
  100.         $margins->max += $tmp;
  101.  
  102.         if ($this->getLinePen()->getVisible()) {
  103.             $margins->max += $this->getLinePen()->getWidth();
  104.         }
  105.     }
  106.  
  107.     public function calcVerticalMargins($margins{
  108.         parent::calcVerticalMargins($margins);
  109.         if ($this->getLinePen()->getVisible()) {
  110.             $margins->min += $this->getLinePen()->getWidth();
  111.         }
  112.     }
  113.  
  114.     private function verticalLine($x$y0$y1{
  115.         if ($this->chart->getAspect()->getView3D()) {
  116.             $this->chart->getGraphics3D()->verticalLine($x$y0$y1$this->getMiddleZ());
  117.         else {
  118.             $this->chart->getGraphics3D()->verticalLine($x$y0$y1);
  119.         }
  120.     }
  121.  
  122.     private function horizLine($x0$x1$y{
  123.         if ($this->chart->getAspect()->getView3D()) {
  124.             $this->chart->getGraphics3D()->horizontalLine($x0$x1$y$this->getMiddleZ());
  125.         else {
  126.             $this->chart->getGraphics3D()->horizontalLine($x0$x1$y);
  127.         }
  128.     }
  129.  
  130.     /**
  131.     * Called internally. Draws the "ValueIndex" point of the Series.
  132.     *
  133.     * @param int $valueIndex 
  134.     */
  135.     public function drawValue($valueIndex{
  136.         $r new Rectangle();
  137.  
  138.         $tmp ($this->getHorizAxis()->iAxisSize $this->visiblePoints()) 2;
  139.         if ($valueIndex == $this->firstVisible{
  140.             $r->$this->calcXPos($valueIndex$tmp;
  141.             $r->width $tmp;
  142.         else {
  143.             $r->$this->previous;
  144.             $r->width $this->calcXPos($valueIndex$tmp $r->x;
  145.         }
  146.         $this->previous $r->getRight();
  147.         $r->$this->calcYPos($valueIndex);
  148.         $r->height $this->getVertAxis()->getInverted($this->getVertAxis()->iStartPos $r->:
  149.                    $this->getVertAxis()->iEndPos $r->y;
  150.         $g $this->chart->getGraphics3D();
  151.         $g->getPen()->setVisible(false);
  152.  
  153.         if ($this->getBrush()->getVisible()) {
  154.             $g->setBrush($this->getBrush());
  155.             $g->getBrush()->setColor($this->getValueColor($valueIndex));
  156.  
  157.             if ($this->getVertAxis()->getInverted()) {
  158.                 $r->y++;
  159.             }
  160.  
  161.             if ($this->chart->getAspect()->getView3D()) {
  162.                 $g->rectangleWithZ(Rectangle::fromLTRB($r->x$r->y$r->getRight(1$r->getBottom()),
  163.                             $this->getMiddleZ());
  164.  
  165.             else {
  166.                 $g->rectangle($r);
  167.             }
  168.  
  169.             if ($this->getVertAxis()->getInverted()) {
  170.                 $r->y--;
  171.             }
  172.         }
  173.  
  174.         if ($this->getLinePen()->getVisible()) {
  175.             $g->setPen($this->getLinePen());
  176.  
  177.             if ($valueIndex == $this->firstVisible{
  178.                 $this->verticalLine($r->x$r->getBottom()$r->y);
  179.             else {
  180.                 $this->verticalLine($r->x$r->y$this->calcYPos($valueIndex 1));
  181.             }
  182.  
  183.             $this->horizLine($r->x$r->getRight()$r->y);
  184.             if ($valueIndex == $this->lastVisible{
  185.                 $this->verticalLine($r->getRight(1$r->y$r->getBottom());
  186.             }
  187.         }
  188.         if (($valueIndex $this->firstVisible&& ($this->linesPen != null&&
  189.             $this->linesPen->getVisible()) {
  190.             $tmp $this->calcYPos($valueIndex 1);
  191.             $tmp $this->getVertAxis()->getInverted($this->min($r->y$tmp:
  192.                   $this->max($r->y$tmp);
  193.             if (!$this->getLinePen()->getVisible()) {
  194.                 $tmp--;
  195.             }
  196.             $g->setPen($this->linesPen);
  197.             $this->verticalLine($r->x$r->getBottom()$tmp);
  198.         }
  199.     }
  200.  
  201.     public function createSubGallery($addSubChart{
  202.         parent::createSubGallery($addSubChart);
  203.         $addSubChart->createSubChart(Language::getString("Hollow"));
  204.         $addSubChart->createSubChart(Language::getString("NoBorder"));
  205.         $addSubChart->createSubChart(Language::getString("Lines"));
  206.         $addSubChart->createSubChart(Language::getString("Transparency"))// 5.02
  207.     }
  208.  
  209.     public function setSubGallery($index{
  210.         switch ($index{
  211.         case 1:
  212.             $this->getBrush()->setVisible(false);
  213.             break;
  214.         case 2:
  215.             $this->getLinePen()->setVisible(false);
  216.             break;
  217.         case 3:
  218.             $this->getLinesPen()->setVisible(true);
  219.             break;
  220.         case 4:
  221.             $this->setTransparency(30);
  222.             break;
  223.         default:
  224.             parent::setSubGallery($index);
  225.         }
  226.     }
  227.  
  228.     /**
  229.     * Gets descriptive text.
  230.     *
  231.     * @return String 
  232.     */
  233.     public function getDescription({
  234.         return Language::getString("GalleryHistogram");
  235.     }
  236. }
  237.  
  238. ?>

Documentation generated on Wed, 16 Jun 2010 12:06:11 +0200 by phpDocumentor 1.4.1