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

Source for file FastLine.php

Documentation is available at FastLine.php

  1. <?php
  2.  
  3. /**
  4.  * FastLine Class
  5.  *
  6.  * Description: The FastLine Series is an extremely simple Series component
  7.  * that draws its points as fast as possible
  8.  *
  9.  * @author
  10.  * @copyright Copyright (c) 1995-2010 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 FastLine extends BaseLine {
  18.  
  19.     private $autoRepaint true;
  20.     private $drawAll true;
  21.     private $old;
  22.     private $internalG;
  23.     private $internal3D;
  24.     private $invertedStairs=false;
  25.     private $stairs=false;
  26.     private $ignoreNulls true;
  27.  
  28.     // Interceptors
  29.     function __get$property {
  30.       $method ="get{$property}";
  31.       if method_exists$this$method ) ) {
  32.         return $this->$method();
  33.       }
  34.     }
  35.  
  36.     function __set $property,$value {
  37.       $method ="set{$property}";
  38.       if method_exists$this$method ) ) {
  39.         return $this->$method($value);
  40.       }
  41.     }
  42.  
  43.     public function FastLine($c=null{
  44.         $this->old new TeePoint();
  45.  
  46.         parent::BaseLine($c);
  47.         
  48.         $this->allowSinglePoint = false;
  49.         $this->drawBetweenPoints = true;
  50.         $this->getLinePen()->setUsesVisible(false);
  51.     }
  52.  
  53.     public function setChart($value{
  54.         parent::setChart($value);
  55.  
  56.         $this->getLinePen()->setChart($value);
  57.  
  58.         /** @todo FINISH ! */
  59.         //pLinePen.ColorChanged=linePenColorChanged;
  60.     }
  61.  
  62.         /**
  63.           * Repaints Chart after any changes are made.<br>
  64.           * Use AutoRepaint false to disable Chart repainting whilst, for example,
  65.           * adding a large number of points to a FastLine Series. This avoids
  66.           * repainting of the Chart whilst the points are added.<br>
  67.           * AutoRepaint may be re-enabled, followed by a manual Repaint command
  68.           * when all points are added. <br>
  69.           * Default value: true
  70.           *
  71.           * @return boolean 
  72.           */
  73.     public function getAutoRepaint({
  74.         return $this->autoRepaint;
  75.     }
  76.  
  77.         /**
  78.           * Repaints Chart after any changes are made.<br>
  79.           * Default value: true
  80.           *
  81.           * @param value boolean
  82.           */
  83.     public function setAutoRepaint($value{
  84.         $this->autoRepaint $value;
  85.     }
  86.  
  87.         //private void linePenColorChanged(Object o, EventArgs e) {
  88.         //    setColor(pLinePen.getColor());
  89.         //}
  90.  
  91.     private function prepareCanvas($g=null{
  92.         if ($g==null)
  93.            $g=$this->chart->getGraphics3D();
  94.  
  95.         $g->setPen($this->getLinePen());
  96.         $g->getPen()->setColor($this->getColor());
  97.     }
  98.  
  99.         /**
  100.           * The Transparency of the FastLine series as a percentage.
  101.           * Default value: 0
  102.           *
  103.           * @return int 
  104.           */
  105.     public function getTransparency({
  106.         return $this->getLinePen()->getTransparency();
  107.     }
  108.  
  109.         /**
  110.           * Sets the Transparency of the FastLine series as a percentage.
  111.           * Default value: 0
  112.           *
  113.           * @param value int
  114.           */
  115.     public function setTransparency($value{
  116.         $this->getLinePen()->setTransparency($value);
  117.     }
  118.  
  119.         /**
  120.           * When false, it only draws the first point at any X pixel location.
  121.           * The option offers speed gains if large numbers of point repetitions
  122.           * occur at one X location. <br>
  123.           * Default value: true
  124.           *
  125.           * @return boolean 
  126.           */
  127.     public function getDrawAllPoints({
  128.         return $this->drawAll;
  129.     }
  130.  
  131.         /**
  132.           * When false, it only draws the first point at any X pixel location.
  133.           * The option offers speed gains if large numbers of point repetitions
  134.           * occur at one X location. <br>
  135.           * Default value: true<br>
  136.           *
  137.           * <p>Example:
  138.           * <pre><font face="Courier" size="4">
  139.           * lineSeries.setDrawAllPoints( false );
  140.           * </font></pre></p>
  141.           *
  142.           * @param value boolean
  143.           */
  144.     public function setDrawAllPoints($value{
  145.         $this->drawAll $this->setBooleanProperty($this->drawAll$value);
  146.     }
  147.  
  148.     public function setColor($value{
  149.         parent::setColor($value);
  150.         $this->getLinePen()->setColor($value);
  151.     }
  152.  
  153.         /**
  154.           * Returns the ValueIndex of the "clicked" point in the Series.<br>
  155.           * Clicked means the X and Y coordinates are in the point screen region
  156.           * bounds. If no point is "touched", Clicked returns -1 <br>
  157.           *
  158.           * @param int
  159.           * @param int
  160.           * @return int 
  161.           */
  162.     public function clicked($x$y{
  163.  
  164.         if (($this->firstVisible > -1&& ($this->lastVisible > -1)) {
  165.  
  166.              $p new TeePoint($x$y);
  167.  
  168.             if ($this->chart != null{
  169.                 $p $this->chart->getGraphics3D()->calculate2DPosition($x$y$this->getMiddleZ());
  170.             }
  171.  
  172.              $oldX 0;
  173.              $oldY 0;
  174.  
  175.             for $t $this->firstVisible$t <= $this->lastVisible$t++{
  176.  
  177.                  $tmpX $this->calcXPos($t);
  178.                  $tmpY $this->calcYPos($t);
  179.  
  180.                 if (($tmpX == $x&& ($tmpY == $y)) //   $on $this->point
  181.                     return $t;
  182.                 else
  183.                 if (($t $this->firstVisible&&
  184.                     $this->MathUtils->pointInLineTolerance($p$tmpX$tmpY$oldX$oldY,
  185.                         3)) {
  186.                     return $t 1;
  187.                 }
  188.                 $oldX $tmpX;
  189.                 $oldY $tmpY;
  190.             }
  191.         }
  192.         return -1;
  193.     }
  194.  
  195.     private function calcPosition($index{
  196.         return new TeePoint($this->getHorizAxis()->calcXPosValue($this->getXValues()->value[$index]),
  197.                          $this->getVertAxis()->calcYPosValue($this->getYValues()->value[$index]));
  198.     }
  199.  
  200.     protected function draw({
  201.         $this->prepareCanvas();
  202.         $tmp $this->firstVisible;
  203.  
  204.         $this->old $this->calcPosition(($tmp 0$tmp 0);
  205.  
  206.         $this->internalG $this->chart->getGraphics3D();
  207.         $this->internal3D $this->chart->getAspect()->getView3D();
  208.  
  209.         $this->doMove($this->old);
  210.  
  211.         if ($tmp >= 0{
  212.             $this->drawValue($tmp);
  213.         }
  214.  
  215.         for $t $tmp 1$t <= $this->lastVisible$t++{
  216.             $this->drawValue($t);
  217.         }
  218.     }
  219.  
  220.     private function doMove($p{
  221.         if ($this->internal3D{
  222.             $this->internalG->moveToZ($p$this->middleZ);
  223.         else {
  224.             $this->internalG->moveTo($p);
  225.         }
  226.     }
  227.  
  228.         /**
  229.           * Called internally. Draws the "ValueIndex" point of the Series.
  230.           *
  231.           * @param index int
  232.           */
  233.     public function drawValue($index{
  234.          $p $this->calcPosition($index);
  235.  
  236.         if ($this->internalG == null{
  237.             $this->internalG $this->chart->getGraphics3D();
  238.         }
  239.  
  240.         if ($p->getX(== $this->old->getX()) {
  241.             if ((!$this->drawAll|| ($p->getY(== $this->old->getY())) {
  242.                 $tmpColor new Color(0,0,0,255);  // TODO check transparent
  243.                 if ($this->getValueColor($index!= $tmpColor/*->TRANSPARENT*/{
  244.                     return// $FastLine $this->Nulls
  245.                 }
  246.             }
  247.         }
  248.  
  249.         if ($this->ignoreNulls || ($this->getValueColor($index!= new Color(0,0,0,255))) // $FastLine $Nulls
  250.             if ($this->bColorEach{
  251.                 $this->internalG->getPen()->setColor($this->getValueColor($index));
  252.             }
  253.  
  254.             if ($this->internal3D{
  255.                 if ($this->stairs{
  256.                     if ($this->invertedStairs{
  257.                         $this->internalG->___lineTo($this->old->getX()$p->getY()$this->middleZ);
  258.  
  259.                     else {
  260.                         $this->internalG->___lineTo($p->getX()$this->old->getY()$this->middleZ);
  261.                     }
  262.                 }
  263.                 $this->internalG->lineTo($p$this->middleZ);
  264.             else {
  265.                 if ($this->stairs{
  266.                     if ($this->invertedStairs{
  267.                         $this->internalG->_____lineTo($this->old->getX()$p->getY());
  268.  
  269.                     else {
  270.                         $this->internalG->_____lineTo($p->getX()$this->old->getY());
  271.                     }
  272.                 }
  273.  
  274.                 $this->internalG->__lineTo($p);
  275.             }
  276.         else // $FastLine $Nulls
  277.             if ($index $getCount()) {
  278.                 $this->doMove($this->calcPosition($index 1));
  279.             else {
  280.                 return;
  281.             }
  282.         }
  283.  
  284.         //            if (drawAll) {
  285.         //                    if (colorEach) internalG.getPen().Color=getValueColor(index);
  286.         //                    if (internal3D)
  287.         //                        internalG.LineTo(X,Y,middleZ);
  288.         //                    else
  289.         //                        internalG.LineTo(X,Y);
  290.         //            }
  291.         //            else {
  292.         //                if (X != oldX) {
  293.         //                    if (colorEach) internalG.getPen().Color=getValueColor(index);
  294.         //                    if (internal3D)
  295.         //                        internalG.LineTo(X,Y,middleZ);
  296.         //                    else
  297.         //                        internalG.LineTo(X,Y);
  298.         //                }
  299.         //                else
  300.         //                    return;
  301.         //            }
  302.  
  303.         $this->old->setX($p->getX());
  304.         $this->old->setY($p->getY());
  305.     }
  306.  
  307.     protected function drawMark($valueIndex$st$aPosition{
  308.         $this->getMarks()->applyArrowLength($aPosition);
  309.         parent::drawMark($valueIndex$st$aPosition);
  310.     }
  311.  
  312.     protected function drawLegendShape(GraphicsGD $g$valueIndex$rect{
  313.         $this->prepareCanvas($g);
  314.         $g->horizontalLine($rect->x$rect->getRight(),
  315.                          ($rect->$rect->getBottom()) 2);
  316.     }
  317.  
  318.     public function createSubGallery($addSubChart{
  319.         parent::createSubGallery($addSubChart);
  320.         $addSubChart->createSubChart(Language::getString("Marks"));
  321.         $addSubChart->createSubChart(Language::getString("Dotted"));
  322.         $addSubChart->createSubChart(Language::getString("Stairs"));
  323.     }
  324.  
  325.     public function setSubGallery($index{
  326.         switch ($index{
  327.         case 1:
  328.             $this->getMarks()->setVisible(true);
  329.             break;
  330.         case 2:
  331.             $this->getLinePen()->setStyle(DashStyle::$DOT);
  332.             break;
  333.         case 3:
  334.             $this->setStairs(true);
  335.             break;
  336.         default:
  337.             break;
  338.         }
  339.     }
  340.  
  341.         /**
  342.           * Controls the drawing of FastLine series. <br>
  343.           * In most normal situations, a series draws a line between each Line
  344.           * point. This makes the Line appear as a "mountain" shape.  <br>
  345.           * However, setting Stairs to true will make the Series to draw 2 Lines
  346.           * between each pair of points, thus giving a "stairs" appearance.  <br>
  347.           * This is most used in some financial Chart representations. <br>
  348.           * When Stairs is set to true you may set InvertedStairs to true to alter
  349.           * the direction of the step. <br>
  350.           * Default value: false
  351.           *
  352.           * @return boolean 
  353.           */
  354.     public function getStairs({
  355.         return $this->stairs;
  356.     }
  357.  
  358.         /**
  359.           * Controls the drawing of FastLine series. <br>
  360.           * Default value: false<br>
  361.           *
  362.           * <p>Example:
  363.           * <pre><font face="Courier" size="4">
  364.           * lineSeries1.setStairs( true );
  365.           * </font></pre></p>
  366.           *
  367.           * @param value boolean
  368.           */
  369.     public function setStairs($value{
  370.         $this->stairs $this->setBooleanProperty($this->stairs$value);
  371.     }
  372.  
  373.         /**
  374.           * Controls the FastLine series drawing. <br>
  375.           * When Stairs is set to true you may set InvertedStairs to true to alter
  376.           * the direction of the step. <br>
  377.           * In most normal situations, the Series draws a line between each Line
  378.           * point. This makes the Line appear as a "mountain" shape.  <br>
  379.           * However, setting Stairs to true will make the Series draw 2 Lines
  380.           * between each pair of points, thus giving a "stairs" appearance.  <br>
  381.           * This is most used in some financial Chart representations. You may
  382.           * invert the stair by setting InvertedStairs to true. <br>
  383.           * Default value: false
  384.           *
  385.           * @return boolean 
  386.           */
  387.     public function getInvertedStairs({
  388.         return $this->invertedStairs;
  389.     }
  390.  
  391.         /**
  392.           * Controls the FastLine series drawing. <br>
  393.           * Default value: false
  394.           *
  395.           * @param value boolean
  396.           */
  397.     public function setInvertedStairs($value{
  398.         $this->invertedStairs $this->setBooleanProperty($this->invertedStairs$value);
  399.     }
  400.  
  401.         /**
  402.           * Displays null points when false<br>
  403.           * For speed reasons, FastLine series supports null (empty) values only
  404.           * when IgnoreNulls is false. <br>
  405.           * By default all points are displayed (IgnoreNulls is true by default).<br>
  406.           * To enable FastLine series to hide null points, set IgnoreNulls to
  407.           * false. <br>
  408.           * Default value: true
  409.           *
  410.           * @return boolean 
  411.           */
  412.     public function getIgnoreNulls({
  413.         return $this->ignoreNulls;
  414.     }
  415.  
  416.         /**
  417.           * Displays null points when false<br>
  418.           * Default value: true<br>
  419.           *
  420.           * <p>Example:
  421.           * <pre><font face="Courier" size="4">
  422.           * lineSeries1.setNull( 123 ); // -- make null (empty) point index 123
  423.           * lineSeries1.setIgnoreNulls( false ); // -- allow null points
  424.           * lineSeries1.setStairs( true ); // -- set "stairs" mode
  425.           * </font></pre></p>
  426.           *
  427.           * @param value boolean
  428.           */
  429.     public function setIgnoreNulls($value{
  430.         $this->ignoreNulls $this->setBooleanProperty($this->ignoreNulls$value);
  431.     }
  432.  
  433.         /**
  434.           * Gets descriptive text.
  435.           *
  436.           * @return String 
  437.           */
  438.     public function getDescription({
  439.         return Language::getString("GalleryFastLine");
  440.     }
  441. }
  442.  
  443.  
  444. /**
  445.   *
  446.   * <p>Title: BaseLine class</p>
  447.   *
  448.   * <p>Description: Abstract Series class inherited by a number of TeeChart
  449.   * series styles.</p>
  450.   *
  451.   * <p>Copyright (c) 2005-2007 by Steema Software SL. All Rights
  452.   * Reserved.</p>
  453.   *
  454.   * <p>Company: Steema Software SL</p>
  455.   *
  456.   */
  457.  
  458.   /* todo remove ... baseline class done in separate class unit
  459.  class BaseLine extends Series {
  460.  
  461.     protected $linePen;
  462.  
  463.     protected function BaseLine($c=null) {
  464.         parent::FastLine($c);
  465.     }
  466.  
  467.     public function assign($source) {
  468.         if ($source instanceof BaseLine) {
  469.             $tmp = $source;
  470.             if ($this->tmp->linePen != null) {
  471.                 $this->getLinePen()->assign($this->tmp->linePen);
  472.             }
  473.         }
  474.         parent::assign($source);
  475.     }
  476.  
  477.     public function setChart($c) {
  478.         parent::setChart($c);
  479.         $this->getLinePen()->setChart($this->chart);
  480.     }
  481.  
  482.     /**
  483.      * Determines pen to draw the line connecting all points.<br>
  484.      *
  485.      * @return ChartPen
  486.      *
  487.     public function getLinePen() {
  488.         if ($this->linePen == null) {
  489.             $tmpColor = new Color();
  490.             $this->linePen = new ChartPen($this->chart, $tmpColor->EMPTY);
  491.         }
  492.         return $this->linePen;
  493.     }
  494. }
  495. */
  496. ?>

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