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

Source for file Bubble.php

Documentation is available at Bubble.php

  1. <?php
  2.  
  3. /**
  4.  * Bubble class
  5.  *
  6.  * Description: Bubble Series
  7.  *
  8.  * Example:
  9.  *
  10.  * $bubbleSeries = new Bubble($myChart->getChart());
  11.  * $bubbleSeries->getXValues().setDateTime(true);
  12.  * $bubbleSeries->getRadiusValues()->setDateTime(false);
  13.  * $bubbleSeries->getRadiusValues()->setName("Radius");
  14.  * $bubbleSeries->getRadiusValues()->setOrder(ValueListOrder::$NONE);
  15.  * $bubbleSeries->setHorizontalAxis(HorizontalAxis::$TOP);
  16.  * $bubbleSeries->getMarks()->setArrowLength(0);
  17.  * $bubbleSeries->getMarks()->setClip(true);
  18.  * $bubbleSeries->getMarks()->getFont().setColor(Color::getWhite);
  19.  * $bubbleSeries->getMarks()->getFont().setSize(16);
  20.  * $bubbleSeries->getMarks()->getFont().setItalic(true);
  21.  * $bubbleSeries->getMarks()->getFrame().setVisible(false);
  22.  * $bubbleSeries->getMarks()->setTransparent(true);
  23.  * $bubbleSeries->getMarks()->setVisible(false);
  24.  * $bubbleSeries->getPointer()->setHorizSize(14);
  25.  * $bubbleSeries->getPointer()->setVertSize(14);
  26.  * $bubbleSeries->getPointer()->setInflateMargins(false);
  27.  * $bubbleSeries->setVisible(true);
  28.  * @author
  29.  * @copyright (c) 1995-2008 by Steema Software SL. All Rights Reserved. <info@steema.com>
  30.  * @version 1.0
  31.  * @package TeeChartPHP
  32.  * @subpackage styles
  33.  * @link http://www.steema.com
  34.  */
  35.  
  36. class Bubble extends Points
  37. {
  38.  
  39.    private $squared true;
  40.    private $radiusValues;
  41.  
  42.     // Interceptors
  43.     function __get$property {
  44.       $method ="get{$property}";
  45.       if method_exists$this$method ) ) {
  46.         return $this->$method();
  47.       }
  48.     }
  49.  
  50.     function __set $property,$value {
  51.       $method ="set{$property}";
  52.       if method_exists$this$method ) ) {
  53.         return $this->$method($value);
  54.       }
  55.     }
  56.  
  57.    public function Bubble($c null)
  58.    {
  59.       parent::Points($c);
  60.       
  61.       if ($this->radiusValues==null{
  62.          $this->radiusValues new ValueList($thisLanguage::getString("ValuesBubbleRadius"));
  63.       }
  64.  
  65.       $this->point->setInflateMargins(false);
  66.       $this->point->setStyle(PointerStyle::$CIRCLE);
  67.       $point->allowChangeSize false;
  68.       $this->getMarks()->getPen()->setDefaultVisible(false);
  69.       $this->getMarks()->setArrowLength(0-($this->getChart()->getGraphics3D()->getFontHeight(/2));
  70.       $this->getMarks()->setTransparent(true);
  71.       $this->getMarks()->getArrow()->setVisible(false);
  72.       $this->bColorEach = true;
  73.    }
  74.  
  75.    /**
  76.    * Determines how the Bubble size is calculated.<br>
  77.    * By default, the horizontal and vertical Bubble sizes are equal to the
  78.    * radius of each bubble. When Squared is false, Bubble horizontal and
  79.    * vertical sizes are calculated independently based on Series axis scales.
  80.    * <br>
  81.    * Default value: true
  82.    *
  83.    * @return boolean 
  84.    */
  85.    public function getSquared()
  86.    {
  87.       return $this->squared;
  88.    }
  89.  
  90.    /**
  91.    * Determines how the Bubble size is calculated.<br>
  92.    * Default value: true
  93.    *
  94.    * @param value boolean
  95.    */
  96.    public function setSquared($value)
  97.    {
  98.       $this->squared $this->setBooleanProperty($this->squared$value);
  99.    }
  100.  
  101.    private function applyRadius($value$aList$increment)
  102.    {
  103.       $result $value;
  104.       for($t 0$t $this->getCount(1$t++)
  105.       {
  106.          if($increment)
  107.          {
  108.             $result max($result$aList->value[$t$this->radiusValues->value[$t]);
  109.          }
  110.          else
  111.          {
  112.             $result min($result$aList->value[$t$this->radiusValues->value[$t]);
  113.          }
  114.       }
  115.       return $result;
  116.    }
  117.  
  118.    protected function numSampleValues()
  119.    {
  120.       return 8;
  121.    }
  122.  
  123.    protected function addSampleValues($numValues)
  124.    {
  125.       $r $this->randomBounds($numValues);
  126.  
  127.       // some sample values to see something in design mode...
  128.       for($t 1$t <= $numValues$t++)
  129.       {
  130.          $this->__add($r->tmpX// $this->X
  131.          MathUtils::round($r->DifY $r->Random())// $this->Y
  132.          ($r->DifY 15.0MathUtils::round($r->DifY (10 15 $r->Random())));// $this->Radius
  133.          $r->tmpX += $r->StepX;
  134.       }
  135.    }
  136.  
  137.    protected function drawLegendShape($g$valueIndex$r)
  138.    {
  139.       $tmp min($r->width$r->height);
  140.       $this->point->setHorizSize($tmp);
  141.       $this->point->setVertSize($tmp);
  142.       parent::drawLegendShape($g$valueIndex$r);
  143.    }
  144.  
  145.    /**
  146.    * Called internally. Draws the "ValueIndex" point of the Series.
  147.    *
  148.    * @param valueIndex int
  149.    */
  150.    public function drawValue($valueIndex)
  151.    {
  152.  
  153.       /* This overrided method is the main paint for bubble points.
  154.       The bubble effect is achieved by changing the Pointer.Size based
  155.       for    $the $this->series->  */
  156.  
  157.       $tmpSize $this->calcYSizeValue($this->radiusValues->value[$valueIndex]);
  158.       $this->point->setHorizSize($this->squared $tmpSize :
  159.       $this->calcXSizeValue($this->radiusValues->value[$valueIndex]));
  160.       $this->point->setVertSize($tmpSize);
  161.       $this->drawPointer($this->calcXPos($valueIndex)$this->calcYPos($valueIndex),
  162.       $this->getValueColor($valueIndex)$valueIndex);
  163.  
  164.       /* dont call inherited to avoid drawing the "pointer" */
  165.    }
  166.  
  167.    /**
  168.    * Adds a new Bubble point to the Series Points List and color.<br>
  169.    * The Bubble point is assigned to be at AX, AY coordinates and have
  170.    * ARadius and Color parameters. The Label parameter is used to
  171.    * draw Axis Labels, Bubble Marks and Legend.
  172.    *
  173.    * @param double x coordinate of bubble point.
  174.    * @param double y coordinate of bubble point.
  175.    * @param radius double
  176.    * @param color Color
  177.    * @return int 
  178.    */
  179.  
  180.    public function ___add($x$y$radius$color null)
  181.    {
  182.       return $this->addBubble($x$y$radius""$color);
  183.    }
  184.  
  185.    /**
  186.    * Adds a new Bubble point to the Series Points List.<br>
  187.    * The Bubble point is assigned to be at AX, AY coordinates and has
  188.    * ARadius  parameter. The Label parameter is used to
  189.    * draw Axis Labels, Bubble Marks and Legend.
  190.    *
  191.    * @param double x coordinate of bubble point.
  192.    * @param double y coordinate of bubble point.
  193.    * @param radius double
  194.    * @return int 
  195.    */
  196.    public function __add($x$y$radius)
  197.    {
  198.       $tmpColor new Color(0000true);// EMPTY color
  199.       return $this->addBubble($x$y$radius""$tmpColor);
  200.    }
  201.  
  202.    /**
  203.    * Adds a new Bubble point to the Series Points List and label.<br>
  204.    * The Bubble point is assigned to be at AX, AY coordinates and have
  205.    * ARadius and Label parameters. The Label parameter is used to
  206.    * draw Axis Labels, Bubble Marks and Legend.
  207.    *
  208.    * @param double x coordinate of bubble point.
  209.    * @param double y coordinate of bubble point.
  210.    * @param radius double
  211.    * @param text String
  212.    * @return int 
  213.    */
  214.    public function _add($x$y$radius$text)
  215.    {
  216.       $tmpColor new Color(0000true);// EMPTY color
  217.       return $this->addBubble($x$y$radius$text$tmpColor);
  218.    }
  219.  
  220.    /**
  221.    * Adds a new Bubble point to the Series Points List, label and color.<br>
  222.    * The Bubble point is assigned to be at AX, AY coordinates and have
  223.    * ARadius, Label and Color parameters. The Label parameter is used to
  224.    * draw Axis Labels, Bubble Marks and Legend.
  225.    *
  226.    * @param double x coordinate of bubble point.
  227.    * @param double y coordinate of bubble point.
  228.    * @param radius double
  229.    * @param text String
  230.    * @param color Color
  231.    * @return int 
  232.    */
  233.  
  234.    public function addBubble($x$y$radius$text=""$color=null)
  235.    {
  236.       $this->radiusValues->tempValue $radius;
  237.       return $this->addXYTextColor($x$y$text$color);
  238.    }
  239.  
  240.    /**
  241.    * It's used to validate the DataSource property both at design and
  242.    * run-time. <br>
  243.    * It returns false if the Value parameter is the same as Self.
  244.    *
  245.    * @param value ISeries
  246.    * @return boolean 
  247.    */
  248.    public function isValidSourceOf($value)
  249.    {
  250.       return $value instanceof Bubble;//      $to $this->Bubbles->
  251.    }
  252.  
  253.    /**
  254.    * The Maximum Value of the Series Y Values List.
  255.    *
  256.    * @return double 
  257.    */
  258.    public function getMaxYValue()
  259.    {
  260.       return $this->applyRadius(parent::getMaxYValue()$this->vyValuestrue);
  261.    }
  262.  
  263.    /**
  264.    * The Minimum Value of the Series Y Values List.
  265.    *
  266.    * @return double 
  267.    */
  268.    public function getMinYValue()
  269.    {
  270.       return $this->applyRadius(parent::getMinYValue()$this->vyValuesfalse);
  271.    }
  272.  
  273.    /**
  274.    * The maximum Z value.
  275.    *
  276.    * @return double 
  277.    */
  278.    public function getMaxZValue()
  279.    {
  280.       if($this->point->getDraw3D())
  281.       {
  282.          return $this->radiusValues->getMaximum();
  283.       }
  284.       else
  285.       {
  286.          return parent::getMaxZValue();
  287.       }
  288.    }
  289.  
  290.    /**
  291.    * The minimum Z value.
  292.    *
  293.    * @return double 
  294.    */
  295.    public function getMinZValue()
  296.    {
  297.       if($this->point->getDraw3D())
  298.       {
  299.          return $this->getRadiusValues()->getMaximum();
  300.       }
  301.       else
  302.       {
  303.          return parent::getMinZValue();
  304.       }
  305.    }
  306.  
  307.    /**
  308.    * A TList object that stores each Bubble point Radius value.<br>
  309.    * You can change Radius values by using the RadiusValues.Value[] array
  310.    * of doubles method
  311.    *
  312.    * @return ValueList 
  313.    */
  314.    public function getRadiusValues()
  315.    {
  316.       if ($this->radiusValues==null)
  317.       {
  318.            $this->radiusValues new ValueList($thisLanguage::getString("ValuesBubbleRadius"));
  319.       }
  320.  
  321.       return $this->radiusValues;
  322.    }
  323.  
  324.    /**
  325.    * A TList object that stores each Bubble point Radius value.<br>
  326.    *
  327.    * @param value ValueList
  328.    */
  329.    public function setRadiusValues($value)
  330.    {
  331.       $this->setValueList($this->radiusValues$value);
  332.    }
  333.  
  334.    /**
  335.    * Controls which color will be drawn on the bubbles.<br>
  336.    * If false, all points will be drawn using Series Series.Color.
  337.    * If true, each Series point will be "colored" with its corresponding
  338.    * point color. <br>
  339.    * You can change this property both at design and runtime.<br>
  340.    * Default value: true
  341.    *
  342.    * @return boolean 
  343.    */
  344.    public function getColorEach()
  345.    {
  346.       return $this->bColorEach;
  347.    }
  348.  
  349.    /**
  350.    * Gets descriptive text.
  351.    *
  352.    * @return String 
  353.    */
  354.    public function getDescription()
  355.    {
  356.       return Language::getString("GalleryBubble");
  357.    }
  358. }
  359.  
  360. ?>

Documentation generated on Wed, 16 Jun 2010 12:03:35 +0200 by phpDocumentor 1.4.1