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

Source for file Arrow.php

Documentation is available at Arrow.php

  1. <?php
  2.  
  3. /**
  4.   *
  5.   * <p>Title: Arrow class</p>
  6.   *
  7.   * <p>Description: Arrow Series.</p>
  8.   *
  9.   * <p>Example:
  10.   * <pre><font face="Courier" size="4">
  11.   * arrowSeries = new com.steema.teechart.styles.Arrow(myChart.getChart());
  12.   * arrowSeries.setArrowWidth(32);
  13.   * arrowSeries.setArrowHeight(32);
  14.   * arrowSeries.getXValues().setDateTime(false);
  15.   * arrowSeries.getYValues().setDateTime(false);
  16.   * arrowSeries.setColorEach(true);
  17.   * addRandomArrows();
  18.   * </font></pre></p>
  19.   *
  20.   * <p>Copyright (c) 2005-2007 by Steema Software SL. All Rights
  21.   * Reserved.</p>
  22.   *
  23.   * <p>Company: Steema Software SL</p>
  24.   *
  25.   */
  26.  class Arrow extends Points {
  27.  
  28.     private $endXValues;
  29.     private $endYValues;
  30.  
  31.     public function Arrow($c=null{
  32.         parent::Points($c);
  33.  
  34.         $this->calcVisiblePoints = false;
  35.         $this->endXValues new ValueList($thisLanguage::getString("ValuesArrowEndX"));
  36.         $this->endYValues new ValueList($thisLanguage::getString("ValuesArrowEndY"));
  37.         $this->point->setInflateMargins(false);
  38.         $this->getMarks()->getPen()->setVisiblefalse);
  39.         $this->getMarks()->setTransparent(true);
  40.     }
  41.  
  42.         /**
  43.           * Determines the vertical arrow head size in pixels.<br>
  44.           * It sets the distance from the base of the arrow head to the arrow tip
  45.           * in pixels. It can be used together with ArrowWidth to determine the
  46.           * overall size of the arrow head.
  47.           *
  48.           * @return int 
  49.           */
  50.     public function getArrowHeight({
  51.         return $this->point->getVertSize();
  52.     }
  53.  
  54.         /**
  55.           * Sets the vertical arrow head size in pixels.<br>
  56.           *
  57.           * @see #getArrowHeight
  58.           * @param value int
  59.           */
  60.     public function setArrowHeight($value{
  61.         $this->point->setVertSize($value);
  62.     }
  63.  
  64.         /**
  65.           * Determines the horizontal arrow head size in pixels. <br>
  66.           * Default value: 4
  67.           *
  68.           * @return int 
  69.           */
  70.     public function getArrowWidth({
  71.         return $this->point->getHorizSize();
  72.     }
  73.  
  74.         /**
  75.           * Sets the horizontal arrow head size in pixels. <br>
  76.           * Default value: 4
  77.           *
  78.           * @param value int
  79.           */
  80.     public function setArrowWidth($value{
  81.         $this->point->setHorizSize($value);
  82.     }
  83.  
  84.         /**
  85.           * The X0 values for Arrows. <br>
  86.           * Each Arrow has (X0,Y0) and (X1,Y1) coordinates. <br>
  87.           * StartXValues.DateTime property default value is true.
  88.           *
  89.           * @return ValueList 
  90.           */
  91.     public function getStartXValues({
  92.         return $this->vxValues;
  93.     }
  94.  
  95.         /**
  96.           * Sets X0 values for Arrows. <br>
  97.           *
  98.           * @param value ValueList
  99.           */
  100.     public function setStartXValues($value{
  101.         $this->setValueList($this->vxValues$value);
  102.     }
  103.  
  104.         /**
  105.           * The Y0 values for Arrows.<br>
  106.           * Each Arrow has (X0,Y0) and (X1,Y1) coordinates. <br>
  107.           *
  108.           * @return ValueList 
  109.           */
  110.     public function getStartYValues({
  111.         return $this->vyValues;
  112.     }
  113.  
  114.         /**
  115.           * Sets Y0 values for Arrows.<br>
  116.           *
  117.           * @param value ValueList
  118.           */
  119.     public function setStartYValues($value{
  120.         $this->setValueList($this->vyValues$value);
  121.     }
  122.  
  123.         /**
  124.           * The X1 values for Arrows.<br>
  125.           * Each Arrow has (X0,Y0) and (X1,Y1) coordinates. <br>
  126.           *
  127.           * @return ValueList 
  128.           */
  129.     public function getEndXValues({
  130.         return $this->endXValues;
  131.     }
  132.  
  133.         /**
  134.           * Sets X1 values for Arrows.<br>
  135.           *
  136.           * @param value ValueList
  137.           */
  138.     public function setEndXValues($value{
  139.         $this->setValueList($this->endXValues$value);
  140.     }
  141.  
  142.         /**
  143.           * The Y1 values for Arrows.<br>
  144.           * Each Arrow has (X0,Y0) and (X1,Y1) coordinates. <br><br>
  145.           *
  146.           * @return ValueList 
  147.           */
  148.     public function getEndYValues({
  149.         return $this->endYValues;
  150.     }
  151.  
  152.         /**
  153.           * Sets Y1 values for Arrows.<br>
  154.           *
  155.           * @param value ValueList
  156.           */
  157.     public function setEndYValues($value{
  158.         $this->setValueList($this->endYValues$value);
  159.     }
  160.  
  161.         /**
  162.           * Adds an Arrow with start and end coordinates.<br>
  163.           * Returns the position of the Arrow in the list.<br>
  164.           * Positions start at zero. <br><br>
  165.           * Each arrow is made of 2 points: <br>
  166.           * (X0,Y0)   The starting arrow point. <br>
  167.           * (X1,Y1)   The arrow head end point. <br>
  168.           *
  169.           * @param x0 double arrow start x coordinate
  170.           * @param y0 double arrow start y coordinate
  171.           * @param x1 double arrow end x coordinate
  172.           * @param y1 double arrow end y coordinate
  173.           * @return int 
  174.           */
  175.     public function _add($x0$y0$x1$y1{
  176.         $tmpColor new Color();
  177.         return $this->addArrow($x0$y0$x1$y1""$tmpColor->getEmpty());
  178.     }
  179.  
  180.         /**
  181.           * Adds an Arrow with start and end coordinates and label.<br>
  182.           * Returns the position of the Arrow in the list.<br>
  183.           * Positions start at zero. <br><br>
  184.           * Each arrow is made of 2 points: <br>
  185.           * (X0,Y0)   The starting arrow point. <br>
  186.           * (X1,Y1)   The arrow head end point. <br>
  187.           * Label (overload option) <br>
  188.           *
  189.           * @param x0 double arrow start x coordinate
  190.           * @param y0 double arrow start y coordinate
  191.           * @param x1 double arrow end x coordinate
  192.           * @param y1 double arrow end y coordinate
  193.           * @param text String label text
  194.           * @return int 
  195.           */
  196.     public function __add($x0$y0$x1$y1$text{
  197.         $tmpColor new Color();
  198.         return $this->addArrow($x0$y0$x1$y1$text$tmpColor->getEmpty());
  199.     }
  200.  
  201.         /**
  202.           * Returns the position of the Arrow in the list.<br>
  203.           * Positions start at zero. <br><br>
  204.           * Each arrow is made of 2 points: <br>
  205.           * (X0,Y0)   The starting arrow point. <br>
  206.           * (X1,Y1)   The arrow head end point. <br>
  207.           * Color (overload option) <br>
  208.           *
  209.           * @param x0 double arrow start x coordinate
  210.           * @param y0 double arrow start y coordinate
  211.           * @param x1 double arrow end x coordinate
  212.           * @param y1 double arrow end y coordinate
  213.           * @param color Color arrow color
  214.           * @return int 
  215.           */
  216.     public function ___add($x0$y0$x1$y1$color{
  217.         return $this->addArrow($x0$y0$x1$y1""$color);
  218.     }
  219.  
  220.         /**
  221.           * Returns the position of the Arrow in the list.<br>
  222.           * Positions start at zero. <br><br>
  223.           * Each arrow is made of 2 points: <br>
  224.           * (X0,Y0)   The starting arrow point. <br>
  225.           * (X1,Y1)   The arrow head end point. <br>
  226.           * Label (overload option) <br>
  227.           * Color (overload option) <br>
  228.           *
  229.           * @param x0 double arrow start x coordinate
  230.           * @param y0 double arrow start y coordinate
  231.           * @param x1 double arrow end x coordinate
  232.           * @param y1 double arrow end y coordinate
  233.           * @param text String label text
  234.           * @param color Color arrow color
  235.           * @return int 
  236.           */
  237.     public function AddArrow($x0$y0$x1$y1$text$color{
  238.         $this->endXValues->tempValue $x1;
  239.         $this->endYValues->tempValue $y1;
  240.         return parent::add($x0$y0$text$color);
  241.     }
  242.  
  243.     protected function addSampleValues($numValues{
  244.          $r $this->randomBounds($numValues);
  245.  
  246.          $tmpDifY MathUtils::round($r->DifY);
  247.          $tmpDifX MathUtils::round($r->StepX $numValues);
  248.  
  249.         for $t 1$t <= $numValues$t++{
  250.             $tmpX0 $r->tmpX $tmpDifX $r->Random();
  251.             $tmpY0 $r->MinY $tmpDifY $r->Random();
  252.             $this->_add($tmpX0$tmpY0$tmpX0 $tmpDifX $r->Random(),
  253.                 $tmpY0 $tmpDifY $r->Random());
  254.         }
  255.     }
  256.  
  257.     public function clicked($x$y{
  258.          $p new TeePoint($x$y);
  259.  
  260.         for $t 0$t $this->getCount()$t++{
  261.             /*ArrowPoints*/ $arrow=$this->getArrowPoints($t);
  262.  
  263.             if ($this->Graphics3D->pointInLineTolerance($p$arrow->p0$arrow->p1,
  264.                                      $this->getPointer()->getPen()->getWidth())) {
  265.                 return $t;
  266.             }
  267.         }
  268.  
  269.         return -1;
  270.     }
  271.  
  272.         /**
  273.           * The Maximum Value of the Series X Values List.
  274.           *
  275.           * @return double 
  276.           */
  277.     public function getMaxXValue({
  278.         return max(parent::getMaxXValue()$this->endXValues->getMaximum());
  279.     }
  280.  
  281.         /**
  282.           * The Minimum Value of the Series X Values List.
  283.           *
  284.           * @return double 
  285.           */
  286.     public function getMinXValue({
  287.         return min(parent::getMinXValue()$this->endXValues->getMinimum());
  288.     }
  289.  
  290.         /**
  291.           * The Maximum Value of the Series Y Values List.
  292.           * @return double 
  293.           */
  294.     public function getMaxYValue({
  295.         return max(parent::getMaxYValue()$this->endYValues->getMaximum());
  296.     }
  297.  
  298.         /**
  299.           * The Minimum Value of the Series Y Values List.
  300.           *
  301.           * @return double 
  302.           */
  303.     public function getMinYValue({
  304.         return min(parent::getMinYValue()$this->endYValues->getMinimum());
  305.     }
  306.  
  307.     private function getArrowPoints($valueIndex)
  308.         {
  309.                 /*ArrowPoints*/ $result=new ArrowPoints();
  310.                 $result->p0new TeePoint($this->calcXPos($valueIndex)$this->calcYPos($valueIndex));
  311.                 $result->p1 new TeePoint($this->calcXPosValue($this->endXValues->value[$valueIndex]),
  312.                     $this->calcYPosValue($this->endYValues->value[$valueIndex]));
  313.                 return $result;
  314.         }
  315.  
  316.         /**
  317.           * Called internally. Draws the "ValueIndex" point of the Series.<br>
  318.           *
  319.           * @param valueIndex int
  320.           */
  321.     public function drawValue($valueIndex{
  322.         /*ArrowPoints*/ $arrow=$this->getArrowPoints($valueIndex);
  323.  
  324.          $tmpColor $this->getValueColor($valueIndex);
  325.          $g $this->chart->getGraphics3D();
  326.  
  327.         if ($this->chart->getAspect()->getView3D()) {
  328.             $this->getPointer()->prepareCanvas($g$tmpColor);
  329.         else {
  330.             $g->setPen($this->getPointer()->getPen());
  331.             $g->getPen()->setColor$tmpColor);
  332.         }
  333.  
  334.         $g->arrow($this->chart->getAspect()->getView3D()$arrow->p0$arrow->p1$this->getPointer()->getHorizSize(),
  335.                 $this->getPointer()->getVertSize()$this->getMiddleZ());
  336.     }
  337.  
  338.         /**
  339.           * Gets descriptive text.
  340.           *
  341.           * @return String 
  342.           */
  343.     public function getDescription({
  344.         return Language::getString("GalleryArrow");
  345.     }
  346. }
  347.  
  348. class ArrowPoints {
  349.     
  350.   public $p0;  // Point  
  351.   public $p1;  // Point
  352.   
  353. }
  354. ?>

Documentation generated on Wed, 16 Jun 2010 12:02:39 +0200 by phpDocumentor 1.4.1