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

Source for file CustomPoint.php

Documentation is available at CustomPoint.php

  1. <?php
  2.  
  3. /**
  4.   *
  5.   * <p>Title: CustomPoint class</p>
  6.   *
  7.   * <p>Description: Base Series class inherited by a number of TeeChart
  8.   * series styles.</p>
  9.   *
  10.   * <p>Copyright (c) 2005-2008 by Steema Software SL. All Rights
  11.   * Reserved.</p>
  12.   *
  13.   * <p>Company: Steema Software SL</p>
  14.   *
  15.   */
  16.  
  17.  
  18.  class CustomPoint extends BaseLine {
  19.  
  20.     protected $point;
  21.     protected $iStacked = 0// TCustomStack.NONE;
  22.  
  23.     // Interceptors
  24.     function __get$property {
  25.       $method ="get{$property}";
  26.       if method_exists$this$method ) ) {
  27.         return $this->$method();
  28.       }
  29.     }
  30.  
  31.     function __set $property,$value {
  32.       $method ="set{$property}";
  33.       if method_exists$this$method ) ) {
  34.         return $this->$method($value);
  35.       }
  36.     }
  37.  
  38.     public function CustomPoint($c=null{
  39.         parent::BaseLine($c);
  40.     }
  41.  
  42.     public function assign($source{
  43.         if ($source instanceof CustomPoint{
  44.             $tmp $source;
  45.             if ($tmp->point != null{
  46.                 $this->getPointer()->assign($tmp->point);
  47.             }
  48.             $this->iStacked = $tmp->iStacked;
  49.         }
  50.         parent::assign($source);
  51.     }
  52.  
  53. /* todo    public function addSeriesMouseListener($l) {
  54.         $this->listenerList->add($this->SeriesMouseListener->class, $l);
  55.     }
  56.  
  57.     public function removeSeriesMouseListener($l) {
  58.         $this->listenerList->remove($this->SeriesMouseListener->class, $l);
  59.     }
  60. */
  61.     private $styleResolver;
  62.  
  63.     public function setPointerStyleResolver($resolver{
  64.         $this->styleResolver $resolver;
  65.     }
  66.  
  67.     public function removePointerStyleResolver({
  68.         $this->styleResolver null;
  69.     }
  70.  
  71.     private function setOtherStacked({
  72.         if ($this->chart != null{
  73.             for $t 0$t $this->chart->getSeriesCount()$t++{
  74.                  $s $this->chart->getSeries($t);
  75.                 if ($s instanceof CustomPoint{
  76.                     $s->iStacked $this->iStacked;
  77.                 }
  78.             }
  79.         }
  80.     }
  81.  
  82.         /**
  83.           * Defines how multiple series will be displayed.<br><br>
  84.           * Stacking options of Points series are:<br> <br>
  85.           * CustomSeriesStack.None: No overlap action. All Series displayed in
  86.           * individual Z space <br>
  87.           * CustomSeriesStack.Overlap: Series displayed in same Z space (all Series
  88.           * take same ZOrder position). This will result in overpainting of equal
  89.           * Series points. <br>
  90.           * CustomSeriesStack.Stack: Stack Series one above the other. Series begin
  91.           * with lowest index order at bottom, further Series are then plotted above
  92.           * in their respective indexed order with each point taking the cumulative
  93.           * value of lower points as their starting value. <br>
  94.           * CustomSeriesStack.Stack100: Plots take up full Bottom to Top space of
  95.           * the Chart Area resulting in a percentage division by Area to reflect
  96.           * Series values. The Y displacement below each line equates to its
  97.           * percentage value of total. Thus the Last Line will be parallel with/at
  98.           * the top of the Chart and the area below that line reflects its
  99.           * percentage proportion. <br>
  100.           * Default value: CustomStack::$NONE
  101.           *
  102.           * @return CustomStack 
  103.           */
  104.     public function getStacked({
  105.         return $this->iStacked;
  106.     }
  107.  
  108.         /**
  109.           * Defines how multiple series will be displayed.
  110.           * Default value: CustomStack::$NONE
  111.           *
  112.           * @param value CustomStack
  113.           */
  114.     public function setStacked($value{
  115.         if ($this->iStacked != $value{
  116.             $this->iStacked = $value;
  117.             $this->setOtherStacked();
  118.             $this->invalidate();
  119.         }
  120.     }
  121.  
  122.         /**
  123.           * Defines all necessary properties of the Series Pointer.<br>
  124.           * It is a subclass of Points series, Line series and all other derived
  125.           * Points series classes like Bubble series.<br>
  126.           * Each point in a Points series is drawn using the Pointer properties.<br>
  127.           * Pointer contains several methods to control the formatting attributes of
  128.           * Points like Pen, Brush, Draw3D, Visible, etc. <br>
  129.           * Default value: Null
  130.           *
  131.           * @return SeriesPointer 
  132.           */
  133.     public function getPointer({
  134.         if ($this->point == null{
  135.             $this->point = new SeriesPointer($this->chart$this);
  136.         }
  137.         return $this->point;
  138.     }
  139.  
  140.         //MM Jan04 set { point=value; }
  141.     public function setChart($c{
  142.         parent::setChart($c);
  143.         if ($this->point != null{
  144.             $this->point->setChart($this->chart);
  145.         }
  146.     }
  147.  
  148.     protected function onGetPointerStyle($valueIndex$style{
  149.         $s=$style;
  150.         if ($this->styleResolver != null{
  151.             $s $this->styleResolver->getStyle($this$valueIndex$s);
  152.         }
  153.         return $s;
  154.     }
  155.  
  156.     private function axisPosition({
  157.         if ($this->getYMandatory()) {
  158.             return $this->getVertAxis()->iEndPos;
  159.         else {
  160.             return $this->getHorizAxis()->iEndPos;
  161.         }
  162.     }
  163.  
  164.     private function calcStackedPos($valueIndex$value{
  165.         $value += $this->pointOrigin($valueIndexfalse);
  166.         if ($this->iStacked == CustomStack::$STACK{
  167.             return min($this->axisPosition()$this->calcPosValue($value));
  168.         else {
  169.              $tmp $this->pointOrigin($valueIndextrue);
  170.             return ($tmp != 0$this->calcPosValue($value 100.0 $tmp:
  171.                     $this->axisPosition();
  172.         }
  173.     }
  174.  
  175.         /**
  176.           * For stacked series, PointOrigin returns the sum of ValueIndex values of
  177.           * all series, until this series in the Chart.Series collection order.<br>
  178.           *
  179.           * @param valueIndex int the point index
  180.           * @param sumAll boolean when true, all series are taken into calculation
  181.           * @return double point origin value
  182.           */
  183.     private function pointOrigin($valueIndex$sumAll{
  184.          $result 0;
  185.  
  186.         for $t 0$t $this->chart->getSeriesCount()$t++{
  187.              $s $this->chart->getSeries($t);
  188.             if ((!$sumAll&& ($s == $this)) {
  189.                 break;
  190.             else
  191.             if ($s->getActive(&& ($s instanceof CustomPoint&&
  192.                 ($this->s->getCount($valueIndex)) {
  193.                  $tmp $s->getOriginValue($valueIndex);
  194.                 if ($tmp 0{
  195.                     $result += $tmp;
  196.                 }
  197.             }
  198.         }
  199.         return $result;
  200.     }
  201.  
  202.     public function calcHorizMargins($margins{
  203.         parent::calcHorizMargins($margins);
  204.         $this->getPointer()->calcHorizMargins($margins);
  205.     }
  206.  
  207.     public function calcVerticalMargins($margins{
  208.         parent::calcVerticalMargins($margins);
  209.         $this->getPointer()->calcVerticalMargins($margins);
  210.     }
  211.  
  212.     public function calcZOrder({
  213.         if ($this->iStacked == CustomStack::$NONE{
  214.             parent::calcZOrder();
  215.         else {
  216.             $this->iZOrder = $this->chart->getMaxZOrder();
  217.         }
  218.     }
  219.  
  220.         /**
  221.           * For internal use
  222.           *
  223.           * @param valueIndex int
  224.           * @param tmpX int
  225.           * @param tmpY int
  226.           * @param int
  227.           * @param int
  228.           * @return boolean 
  229.           */
  230.     public function clickedPointer($valueIndex$tmpX$tmpY$x$y{
  231.         return ($this->point != null&& (abs($tmpX $x$this->point->getHorizSize()) &&
  232.                 (abs($tmpY $y$this->point->getVertSize());
  233.     }
  234.  
  235.     protected function drawLegendShape($g$valueIndex$rect{
  236.         if ($this->getPointer()->getVisible()) {
  237.              $tmpColor ($valueIndex == -1$this->getColor(:
  238.                              $this->getValueColor($valueIndex);
  239.             $this->point->drawLegendShape($g$tmpColor$rectfalse);
  240.         else {
  241.             parent::drawLegendShape($g$valueIndex$rect);
  242.         }
  243.     }
  244.  
  245.     protected function drawMark($valueIndex$s$position{
  246.         $this->getMarks()->setZPosition($this->getStartZ());
  247.         if ($this->getYMandatory()) {
  248.             $position $this->getMarks()->applyArrowLength($position);
  249.         }
  250.  
  251.         parent::drawMark($valueIndex$s$position);
  252.     }
  253.  
  254.         /**
  255.           * Draws series pointer to the Canvas.
  256.           * It displays a pointer at the specified px and py screen pixel
  257.           * coordinates with the tmpHoriz and tmpVert size dimensions.
  258.           *
  259.           * @param aX int
  260.           * @param aY int
  261.           * @param aColor Color
  262.           * @param valueIndex int
  263.           */
  264.     public function drawPointer($aX$aY$aColor$valueIndex{
  265.         $this->point->prepareCanvas($this->chart->getGraphics3D()$aColor);
  266.         $tmpStyle $this->onGetPointerStyle($valueIndex$this->point->getStyle());
  267.         $this->point->draw($aX$aY$aColor$tmpStyle);
  268.     }
  269.  
  270.         /**
  271.           * Returns vertical screen position for a given point.
  272.           * This coordinate is calculated using the Series associated Vertical Axis.
  273.           *
  274.           * @param valueIndex int
  275.           * @return int 
  276.           */
  277.     public function calcYPos($valueIndex{
  278.         if ((!$this->getYMandatory()) || ($this->iStacked == CustomStack::$NONE||
  279.             ($this->iStacked == CustomStack::$OVERLAP)) {
  280.             return parent::calcYPos($valueIndex);
  281.         else {
  282.             return $this->calcStackedPos($valueIndex$this->vyValues->value[$valueIndex]);
  283.         }
  284.     }
  285.  
  286.         /**
  287.           * Returns horizontal screen position for a given point.
  288.           * This coordinate is calculated using the Series associated Horizontal
  289.           * Axis.
  290.           *
  291.           * @param valueIndex int
  292.           * @return int 
  293.           */
  294.     public function calcXPos($valueIndex{
  295.         if (($this->getYMandatory()) || ($this->iStacked == CustomStack::$NONE||
  296.             ($this->iStacked == CustomStack::$OVERLAP)) {
  297.             return parent::calcXPos($valueIndex);
  298.         else {
  299.             return $this->calcStackedPos($valueIndex$this->vxValues->value[$valueIndex]);
  300.         }
  301.     }
  302.  
  303.     protected function getOriginPos($valueIndex{
  304.         if (($this->iStacked == CustomStack::$NONE||
  305.             ($this->iStacked == CustomStack::$OVERLAP)) {
  306.             if ($this->yMandatory{
  307.                 return $this->getVertAxis()->getInverted($this->getVertAxis()->iStartPos :
  308.                         $this->getVertAxis()->iEndPos;
  309.             else {
  310.                 return $this->getHorizAxis()->getInverted($this->getHorizAxis()->iEndPos :
  311.                         $this->getHorizAxis()->iStartPos;
  312.             }
  313.         else {
  314.             return $this->calcStackedPos($valueIndex0);
  315.         }
  316.     }
  317.  
  318.         /**
  319.           * Called internally. Draws the "ValueIndex" point of the Series.
  320.           *
  321.           * @param valueIndex int
  322.           */
  323.     public function drawValue($valueIndex{
  324.         $this->drawPointer($this->calcXPos($valueIndex)$this->calcYPos($valueIndex),
  325.                     $this->getValueColor($valueIndex)$valueIndex);
  326.     }
  327.  
  328.         /**
  329.           * Returns the ValueIndex of the "clicked" point in the Series.
  330.           *
  331.           * @param int
  332.           * @param int
  333.           * @return int 
  334.           */
  335.     public function clicked($x$y{
  336.         if ($this->chart != null{
  337.              $p $this->chart->getGraphics3D()->calculate2DPosition($x$y$this->getStartZ());
  338.             $x $p->x;
  339.             $y $p->y;
  340.         }
  341.  
  342.          $result parent::clicked($x$y);
  343.  
  344.         if (($result == -1&& ($this->firstVisible > -1&& ($this->lastVisible > -1)) {
  345.             for $t $this->firstVisible$t <= $this->lastVisible$t++{
  346.                 if ($this->clickedPointer($t$this->calcXPos($t)$this->calcYPos($t)$x$y)) {
  347.                     $this->doClickPointer($t$x$y);
  348.                     return $t;
  349.                 }
  350.             }
  351.         }
  352.  
  353.         return $result;
  354.     }
  355.  
  356.         /**
  357.           * Returns the Maximum Value of the Series X Values List.
  358.           *
  359.           * @return double 
  360.           */
  361.     public function getMaxXValue({
  362.          $result 0;
  363.         if ($this->yMandatory{
  364.             $result parent::getMaxXValue();
  365.         else {
  366.             if ($this->iStacked == CustomStack::$STACK100{
  367.                 $result 100;
  368.             else {
  369.                 $result parent::getMaxXValue();
  370.                 if ($this->iStacked == CustomStack::$STACK{
  371.                     for $t 0$t $this->getCount()$t++{
  372.                         $result max($result,
  373.                                           $this->pointOrigin($tfalse+
  374.                                           $this->getXValues()->value[$t]);
  375.                     }
  376.                 }
  377.             }
  378.         }
  379.         return $result;
  380.     }
  381.  
  382.         /**
  383.           * Returns the Minimum Value of the Series X Values List.
  384.           *
  385.           * @return double 
  386.           */
  387.     public function getMinXValue({
  388.         if ((!$this->getYMandatory()) && ($this->iStacked == CustomStack::$STACK100)) {
  389.             return 0;
  390.         else {
  391.             return parent::getMinXValue();
  392.         }
  393.     }
  394.  
  395.         /**
  396.           * Returns the Maximum Value of the Series Y Values List.
  397.           *
  398.           * @return double 
  399.           */
  400.     public function getMaxYValue({
  401.         if ($this->getYMandatory()) {
  402.             $tmpCustomStack new CustomStack();
  403.             if ($this->iStacked == CustomStack::$STACK100{
  404.                 return 100;
  405.             else {
  406.                  $result parent::getMaxYValue();
  407.                 if ($this->iStacked == CustomStack::$STACK{
  408.                     for $t 0$t $this->getCount()$t++{
  409.                         $result max($result,
  410.                                           $this->pointOrigin($tfalse+
  411.                                           $this->vyValues->value[$t]);
  412.                     }
  413.                 }
  414.                 return $result;
  415.             }
  416.         else {
  417.             return parent::getMaxYValue();
  418.         }
  419.     }
  420.  
  421.         /**
  422.           * Returns the Minimum Value of the Series Y Values List.
  423.           *
  424.           * @return double 
  425.           */
  426.     public function getMinYValue({
  427.         return ($this->getYMandatory(&& ($this->iStacked == CustomStack::$STACK100)) :
  428.                 parent::getMinYValue();
  429.     }
  430. }
  431. ?>

Documentation generated on Wed, 16 Jun 2010 12:04:55 +0200 by phpDocumentor 1.4.1