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

Source for file Gantt.php

Documentation is available at Gantt.php

  1. <?php
  2.  
  3. /**
  4.  * Gantt Class
  5.  *
  6.  * Description: Gantt 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 Gantt extends Points
  17. {
  18.  
  19.    private static $NUMGANTTSAMPLES 10;
  20.  
  21.    private $endValues;
  22.    private $nextTask;
  23.  
  24.    // Interceptors
  25.    function __get$property {
  26.      $method ="get{$property}";
  27.      if method_exists$this$method ) ) {
  28.        return $this->$method();
  29.      }
  30.    }
  31.  
  32.    function __set $property,$value {
  33.      $method ="set{$property}";
  34.      if method_exists$this$method ) ) {
  35.        return $this->$method($value);
  36.      }
  37.    }
  38.  
  39.    /**
  40.    * Creates a new Gantt series.
  41.    */
  42.    public function Gantt($c null)
  43.    {
  44.       parent::Points($c);
  45.  
  46.       $this->setHorizontal();
  47.       $this->calcVisiblePoints = false;
  48.  
  49.       $this->vxValues->setName("ValuesGanttStart");// TODO  $this->Language->getString("ValuesGanttStart");
  50.       $this->vxValues->setDateTime(true);
  51.       $this->vxValues->setOrder(ValueListOrder::$NONE);
  52.       $this->bColorEach = true;
  53.  
  54.       $tmpColor new Color(000);// Black
  55.       $this->getLinePen()->setColor($tmpColor);
  56.  
  57.       $this->endValues new ValueList($this"ValuesGanttEnd"/*$this->Language->getString("ValuesGanttEnd")*/);
  58.       $this->endValues->setDateTime(true);
  59.  
  60.       $this->nextTask new ValueList($this"ValuesGanttNextTask"/*$this->Language->getString("ValuesGanttNextTask")*/);
  61.       $this->point->setStyle(PointerStyle::$RECTANGLE);// <--    $Bar ( default)
  62.    }
  63.  
  64.    /**
  65.    * Defines the starting Gantt bar date values.<br>
  66.    * The ending Gantt bar point date is stored at TGanttSeries.EndValues.<br>
  67.    * StartValues and EndValues can be specified both as DateTime or double
  68.    * values. <br>
  69.    * Both are standard TChartValueList components. That means you can access
  70.    * their values with same methods as you can access X or Y values.<br>
  71.    * The TGanttSeries.Add method must be used to add Gantt bar points. <br>
  72.    *
  73.    * @return ValueList 
  74.    */
  75.    public function getStartValues()
  76.    {
  77.       return $vxValues;
  78.    }
  79.  
  80.    /**
  81.    * Defines the ending Gantt bar date value.<br>
  82.    * The starting Gantt bar point is stored at TGanttSeries.StartValues<br>
  83.    * StartValues and EndValues can be specified both as DateTime or double
  84.    * values. <br>
  85.    * Both are standard TChartValueList components. That means you can access
  86.    * their values with same methods as you can access X or Y values. <br>
  87.    * The TGanttSeries.Add  method must be used to add Gantt bar points. <br>
  88.    *
  89.    * @return ValueList 
  90.    */
  91.    public function getEndValues()
  92.    {
  93.       return $this->endValues;
  94.    }
  95.  
  96.    /**
  97.    * Holds the Gantt bar index each Gantt bar is connected to. <br>
  98.    * When a Gantt bar is added to TGanttSeries, it's NextTask value is
  99.    * assigned to -1 by default. That means the Gantt bar is NOT connected
  100.    * to any other Gantt Bar. <br>
  101.    * You need to set a valid bar index to NextTask. <br>
  102.    *
  103.    * @return ValueList 
  104.    */
  105.    public function getNextTasks()
  106.    {
  107.       return $this->nextTask;
  108.    }
  109.  
  110.    private function ganttSampleStr($index)
  111.    {
  112.       switch($index)
  113.       {
  114.          case 0:
  115.             return "GanttSample1";//$this->Language->getString("GanttSample1");
  116.          case 1:
  117.             return "GanttSample2";//$this->Language->getString("GanttSample2");
  118.          case 2:
  119.             return "GanttSample3";//$this->Language->getString("GanttSample3");
  120.          case 3:
  121.             return "GanttSample4";//$this->Language->getString("GanttSample4");
  122.          case 4:
  123.             return "GanttSample5";//$this->Language->getString("GanttSample5");
  124.          case 5:
  125.             return "GanttSample6";//$this->Language->getString("GanttSample6");
  126.          case 6:
  127.             return "GanttSample7";//$this->Language->getString("GanttSample7");
  128.          case 7:
  129.             return "GanttSample8";//$this->Language->getString("GanttSample8");
  130.          case 8:
  131.             return "GanttSample9";//$this->Language->getString("GanttSample9");
  132.          default:
  133.             return "GanttSample1";//$this->Language->getString("GanttSample1");
  134.       }
  135.    }
  136.  
  137.    /**
  138.    * Adds random values to series.
  139.    * @param numValues int
  140.    */
  141.    protected function addSampleValues($numValues)
  142.    {
  143.  
  144.       $r $this->randomBounds($numValues);
  145.  
  146.       // some sample values to see something at design mode
  147.       for($t 0$t <= min($numValues,  self::$NUMGANTTSAMPLES MathUtils::round(20 $r->Random()))$t++)
  148.       {
  149.          $tmpStartTask =  gettimeofday(true$t $r->Random();
  150.          $tmpEndTask $tmpStartTask 16 $r->Random();
  151.          $tmpY ($t 10);
  152.  
  153.          $addedGantt $this->addGantt($tmpStartTask,
  154.          $tmpEndTask,
  155.          $tmpY,
  156.          $this->ganttSampleStr($tmpY)
  157.          );
  158.  
  159.          // Connect Gantt points
  160.          for($tt 0$tt $addedGantt$tt++)
  161.          {
  162.             if(($this->nextTask->value[$tt== - 1&& ($tmpStartTask $this->endValues->value[$tt]))
  163.             {
  164.                $this->nextTask->value[$tt$addedGantt;
  165.                break;
  166.             }
  167.          }
  168.       }
  169.    }
  170.  
  171.    /**
  172.    * Determines the pen to draw the optional lines that connect Gantt
  173.    * Bars. <br>
  174.    *
  175.    * @return ChartPen 
  176.    */
  177.    public function getConnectingPen()
  178.    {
  179.       return $this->linePen;
  180.    }
  181.  
  182.    /**
  183.    * Called internally. Draws the "ValueIndex" point of the Series.
  184.    *
  185.    * @param valueIndex int
  186.    */
  187.    public function drawValue($valueIndex)
  188.    {
  189.       // This overrided method is the main paint method for Gantt bar points.
  190.       if($this->point->getVisible())
  191.       {
  192.          $c $this->getValueColor($valueIndex);
  193.          $this->point->prepareCanvas($this->chart->getGraphics3D()$c);
  194.  
  195.          $x1 $this->calcXPos($valueIndex);
  196.          $x2 $this->calcXPosValue($this->endValues->value[$valueIndex]);
  197.          $tmpHalfHorizSize ($x2 $x12;
  198.          $y $this->calcYPos($valueIndex);
  199.  
  200.          $tmpStyle $this->onGetPointerStyle($valueIndex$this->point->getStyle());
  201.  
  202.          $g $this->chart->getGraphics3D();
  203.  
  204.          $this->point->intDraw($g,
  205.          $this->chart->getAspect()->getView3D(),
  206.          $x1 $tmpHalfHorizSize,
  207.          $y,
  208.          $tmpHalfHorizSize,
  209.          $this->point->getVertSize(),
  210.          $c$tmpStyle);
  211.  
  212.          if($this->getConnectingPen()->getVisible())
  213.          {
  214.             $tmpNextTask round($this->nextTask->value[$valueIndex]);
  215.  
  216.             if(($tmpNextTask >= 0&& ($tmpNextTask $this->getCount()))
  217.             {
  218.                $g->setPen($this->getConnectingPen());
  219.                $g->getBrush()->setVisible(false);
  220.  
  221.                $xNext $this->calcXPos($tmpNextTask);
  222.                $halfWay $x2 (($xNext $x22);
  223.                $yNext $this->calcYPos($tmpNextTask);
  224.                $g->_line($x2$y$halfWay$y$this->getMiddleZ());
  225.                $g->___lineTo($halfWay$yNext$this->getMiddleZ());
  226.                $g->___lineTo($xNext$yNext$this->getMiddleZ());
  227.             }
  228.          }
  229.       }
  230.    }
  231.  
  232.    /**
  233.    * For internal use.
  234.    *
  235.    * @param valueIndex int
  236.    * @param tmpX int
  237.    * @param tmpY int
  238.    * @param int
  239.    * @param int
  240.    * @return boolean 
  241.    */
  242.    public function clickedPointer($valueIndex$tmpX$tmpY$x$y)
  243.    {
  244.       return($x >= $tmpX&& ($x <= $this->calcXPosValue($this->getEndValues()->value[$valueIndex])) &&
  245.       (abs($tmpY $y$this->getPointer()->getVertSize());
  246.    }
  247.  
  248.    protected function drawMark($valueIndex$s$aPosition)
  249.    {
  250.       $aPosition->leftTop->+=
  251.       ($this->calcXPosValue($this->endValues->value[$valueIndex]-
  252.       $aPosition->arrowFrom->x2;
  253.       $aPosition->leftTop->+= $aPosition->height 2;
  254.       parent::drawMark($valueIndex$s$aPosition);
  255.    }
  256.  
  257.    public function prepareForGallery($isEnabled)
  258.    {
  259.       parent::prepareForGallery($isEnabled);
  260.       $this->setColorEach($isEnabled);
  261.       $this->point->setVertSize(3);
  262.    }
  263.  
  264.    /*
  265.    public function Add($view) {
  266.    $labelField = -1;
  267.    $colorField = -1;
  268.    $tmpColor = new Color();
  269.    $tmpColor = $tmpColor->EMPTY;
  270.    $tmpLabel = "";
  271.  
  272.    $this->int[] $this->fields = new int[$this->ValuesLists->Count];
  273.  
  274.    $fieldCount = 0;
  275.    $this->foreach(   $ValuesLists)
  276.    if ($this->v->DataMember->length() != 0) {
  277.    $this->fields[$ValuesLists->IndexOf($this->v)] = $view->Table->Columns->IndexOf($this->v->DataMember);
  278.    $fieldCount++;
  279.    }
  280.  
  281.    if ($this->labelMember->length() != 0) {
  282.    $labelField = $view->Table->Columns->IndexOf($this->labelMember);
  283.    }
  284.    if ($this->colorMember->length() != 0) {
  285.    $colorField = $view->Table->Columns->IndexOf($this->colorMember);
  286.    }
  287.  
  288.    if ($fieldCount == $ValuesLists->Count - 1) {
  289.    $this->foreach(   $view) {
  290.    $r = $this->rv->Row;
  291.    if ($colorField != -1) {
  292.    $tmpColor = ($tmpColor) ($r[$colorField]);
  293.    }
  294.    if ($labelField != -1) {
  295.    $tmpLabel = $this->Convert->ToString($r[$labelField]);
  296.    }
  297.  
  298.    $this->foreach(   $ValuesLists) {
  299.    $fieldIndex = $this->fields[$ValuesLists->IndexOf($this->v)];
  300.    if ($r[$fieldIndex]  $DateTime) {
  301.    $this->v->TempValue = $this->misc->Utils->DateTime(($this->System->DateTime) $r[
  302.    $fieldIndex]);
  303.    } else {
  304.    $this->v->TempValue = $this->Convert->ToDouble($r[$fieldIndex]);
  305.    }
  306.    }
  307.  
  308.    $this->Add($this->XValues->TempValue, $this->endValues->TempValue, $this->YValues->TempValue,
  309.    $tmpLabel, $tmpColor);
  310.    }
  311.    }
  312.    }
  313.    */
  314.    /* TODO datetime
  315.    public function add($start, $endDate, $y, $text="", $color=null) {
  316.    if ($color == null) {
  317.    $tmpColor = new Color(0,0,0);  //  // EMPTY COLOR BLACK
  318.    }
  319.    return $this->add($start->toDouble(), $endDate->toDouble(), $y, $text,
  320.    $color);
  321.    }
  322.    */
  323.  
  324.    /**
  325.    * Adds a new Gantt bar with start and end coordinates, label and color.
  326.    *
  327.    * @param start double
  328.    * @param endDate double
  329.    * @param double
  330.    * @param text String
  331.    * @param color Color
  332.    * @return int 
  333.    */
  334.    public function addGantt($start$endDate$y$text=""$color=null)
  335.    {
  336.       if($color == null)
  337.       {
  338.          $color new Color(0000true);// Black empty
  339.       }
  340.  
  341.       $this->endValues->tempValue $endDate;
  342.       $this->nextTask->tempValue = -1;
  343.  
  344.       // TODO review temp or correct   ****  ****
  345. //      $this->endValues->addChartValue($endDate);
  346. //      $this->nextTask->addChartValue(-1);
  347. //      ***** ****  TODO reivew
  348.  
  349.       return $this->addXYTextColor($start$y$text$color);
  350.    }
  351.  
  352.    /**
  353.    * True if Series source is Gantt.<br>
  354.    * It returns false if the Value parameter is the same as Self. <br>
  355.    * It's used to validate DataSource both at design and run-time. <br>
  356.    *
  357.    * @param value Series
  358.    * @return boolean 
  359.    */
  360.    public function isValidSourceOf($value)
  361.    {
  362.       return $value instanceof Gantt;
  363.    }
  364.  
  365.    /**
  366.    * Returns the Maximum Value of the Series X Values List.
  367.    *
  368.    * @return double 
  369.    */
  370.    public function getMaxXValue()
  371.    {
  372.       return max(parent::getMaxXValue()$this->endValues->getMaximum());
  373.    }
  374.  
  375.    /**
  376.    * Gets descriptive text.
  377.    *
  378.    * @return String 
  379.    */
  380.    public function getDescription()
  381.    {
  382.       return $this->Language->getString("GalleryGantt");
  383.    }
  384. }
  385.  
  386. ?>

Documentation generated on Wed, 16 Jun 2010 12:05:29 +0200 by phpDocumentor 1.4.1