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

Source for file Circular.php

Documentation is available at Circular.php

  1. <?php
  2.  
  3. /**
  4.  * Circular class
  5.  *
  6.  * Description: Circled Series
  7.  *
  8.  * @author
  9.  * @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 Circular extends Series {
  17.  
  18.     /**
  19.       Represents the static finalant pi / 180.
  20.     */
  21.     public static $PIDEGREE;
  22.  
  23.     private $circled;
  24.     private $rotationAngle;
  25.     private $customXRadius;
  26.     private $customYRadius;
  27.     private $circleWidth;
  28.     private $circleHeight;
  29.     protected $iXRadius;
  30.     protected $iYRadius;
  31.     private $circleBackColor;
  32.     private $circleGradient;
  33.  
  34.     private $iBack3D// global to all instances
  35.  
  36.     protected $iCircleXCenter;
  37.     protected $iCircleYCenter;
  38.     protected $rCircleRect;
  39.     protected $rotDegree;
  40.  
  41.     private $HALFPI;
  42.  
  43.     // Interceptors
  44.     function __get$property {
  45.       $method ="get{$property}";
  46.       if method_exists$this$method ) ) {
  47.         return $this->$method();
  48.       }
  49.     }
  50.  
  51.     function __set $property,$value {
  52.       $method ="set{$property}";
  53.       if method_exists$this$method ) ) {
  54.         return $this->$method($value);
  55.       }
  56.     }
  57.  
  58.     public function Circular($c=null{
  59.         self::$PIDEGREE M_PI 180;
  60.         $this->circleBackColor new Color(0,0,0,0,true)// EMPTY
  61.         $this->HALFPI 0.5 M_PI;
  62.  
  63.         parent::Series($c);
  64.         
  65.         $this->useAxis = false;
  66.         $this->calcVisiblePoints = false//   all $this->points
  67.         $this->vxValues->name "ValuesAngle"// TODO $this->Language->getString("ValuesAngle");
  68.     }
  69.  
  70.     protected function adjustCircleRect({
  71.  
  72.         $r $this->rCircleRect;
  73.         if (($r->width 2== 1{
  74.             $r->width--;
  75.         }
  76.         if (($r->height 2== 1{
  77.             $r->height--;
  78.         }
  79.         if ($r->width 4{
  80.             $r->width 4;
  81.         }
  82.         if ($r->height 4{
  83.             $r->height 4;
  84.         }
  85.         $this->circleWidth $r->width;
  86.         $this->circleHeight $r->height;
  87.         $tmp $this->rCircleRect->center();
  88.         $this->iCircleXCenter = $tmp->getX();
  89.         $this->iCircleYCenter = $tmp->getY();
  90.     }
  91.  
  92.     protected function calcCircleBackColor({
  93.         $result $this->circleBackColor;
  94.         if ($result->isEmpty()) {
  95.             if ($this->chart->getPrinting()) {
  96.                 $tmpColor new Color();
  97.                 $result $tmpColor->WHITE;
  98.             else
  99.             if (!$this->chart->getWalls()->getBack()->getTransparent()) {
  100.                 $result $this->getColor();
  101.             }
  102.         }
  103.  
  104.         if ($result->isEmpty()) {
  105.             $result $this->chart->getPanel()->getColor();
  106.         }
  107.         return $result;
  108.     }
  109.  
  110.     //CDI CircleGradient
  111.     protected function calcCircleGradient({
  112.          $result $this->circleGradient;
  113.         return $result;
  114.     }
  115.  
  116.     protected function calcRadius({
  117.         if ($this->customXRadius != 0{
  118.             $this->iXRadius = $this->customXRadius;
  119.             $this->circleWidth $this->iXRadius;
  120.         else {
  121.             $this->iXRadius = $this->circleWidth 2;
  122.         }
  123.  
  124.         if ($this->customYRadius != 0{
  125.             $this->iYRadius = $this->customYRadius;
  126.             $this->circleHeight $this->iYRadius;
  127.         else {
  128.             $this->iYRadius = $this->circleHeight 2;
  129.         }
  130.  
  131.         $this->rCircleRect->$this->iCircleXCenter - $this->iXRadius;
  132.         $this->rCircleRect->width $this->iXRadius;
  133.         $this->rCircleRect->$this->iCircleYCenter - $this->iYRadius;
  134.         $this->rCircleRect->height $this->iYRadius;
  135.     }
  136.  
  137.     private function adjustRatio($aRatio$g{
  138.          // todo: obtain width and height from "g" instead of screen device
  139.          $tmpH GraphicsGD::getScreenHeight();
  140.          $tmpW GraphicsGD::getScreenWidth();
  141.  
  142.          $result $aRatio;
  143.  
  144.         if ($tmpH != 0{
  145.              $tmpRatio (1.0 $tmpW $tmpH);
  146.             if ($tmpRatio != 0{
  147.                 $result 1.0 $aRatio $tmpRatio;
  148.             }
  149.         }
  150.         return $result;
  151.     }
  152.  
  153.     private function calcCircledRatio({
  154.         $dif;
  155.  
  156.         $ratio $this->adjustRatio(1.0 GraphicsGD::getScreenWidth(/
  157.                                    GraphicsGD::getScreenHeight(),
  158.                                    $this->chart->getGraphics3D());
  159.         $this->calcRadius();
  160.  
  161.         if (MathUtils::round($ratio $this->iYRadius$this->iXRadius{
  162.             $dif ($this->iXRadius - MathUtils::round($ratio $this->iYRadius));
  163.             $this->rCircleRect->+= $dif;
  164.             $this->rCircleRect->width -= $dif;
  165.         else {
  166.             $dif ($this->iYRadius - MathUtils::round(1.0 $this->iXRadius / $ratio));
  167.             $this->rCircleRect->+= $dif;
  168.             $this->rCircleRect->height -= $dif;
  169.         }
  170.  
  171.         $this->adjustCircleRect();
  172.     }
  173.  
  174.     private function adjustCircleMarks({
  175.         $tmpFrame $this->getMarks()->getCallout()->getLength();
  176.  
  177.         if ($this->getMarks()->getPen()->getVisible()) {
  178.             $tmpFrame += round($this->getMarks()->getPen()->getWidth());
  179.         }
  180.  
  181.         $this->chart->getGraphics3D()->setFont($this->getMarks()->getFont());
  182.  
  183.         $tmpH $this->chart->getGraphics3D()->getFontHeight($tmpFrame;
  184.  
  185.         $this->rCircleRect->+= $tmpH;
  186.         $this->rCircleRect->height -= $tmpH;
  187.  
  188.         $tmpW round($this->maxMarkWidth(+
  189.             $this->chart->getGraphics3D()->textWidth(" "$tmpFrame);  // TODO textWidth($this->Language->getString("CharForHeight"))
  190.  
  191.         $this->rCircleRect->+= $tmpW;
  192.         $this->rCircleRect->width -= $tmpW;
  193.         $this->adjustCircleRect();
  194.     }
  195.  
  196.     //CDI base method called last to initialise Radius values
  197.     protected function doBeforeDrawValues({
  198.         parent::doBeforeDrawValues();
  199.         $this->rCircleRect = $this->chart->getChartRect();
  200.         $this->adjustCircleRect();
  201.  
  202.         if ($this->getMarks()->getVisible()) {
  203.             $this->adjustCircleMarks();
  204.         }
  205.  
  206.         if ($this->circled{
  207.             $this->calcCircledRatio();
  208.         }
  209.         $this->calcRadius();
  210.     }
  211.  
  212.     protected function prepareLegendCanvas($g$valueIndex$backColor$aBrush{
  213.         $backColor $this->calcCircleBackColor();
  214.     }
  215.  
  216.     public function setActive($value{
  217.         parent::setActive($value);
  218.         $this->setParentProperties(!$this->bActive);
  219.     }
  220.  
  221.     // Trick (due to .Net delayed GC)
  222.     public function onDisposing({
  223.         $this->setParentProperties(true);
  224.     }
  225.  
  226.     public function setChart($value{
  227.         if ($value == null{
  228.             $this->setParentProperties(true);
  229.         }
  230.         if ($value != $this->chart{
  231.             parent::setChart($value);
  232.             if ($this->chart != null{
  233.                 $this->setParentProperties(false);
  234.             }
  235.         }
  236.     }
  237.  
  238.     protected function setParentProperties($enableParentProps{
  239.  
  240.         if ($this->chart != null{
  241.  
  242.              $g $this->chart->getGraphics3D();
  243.              $tmp ($g == nulltrue !$g->getSupportsFullRotation();
  244.  
  245.             if ($tmp{
  246.                 if ($enableParentProps{
  247.                     if ($this->iBack3D != null{
  248.                         $this->chart->getAspect()->assign($this->iBack3D);
  249.                     }
  250.                     $this->iBack3D null;
  251.                 else
  252.                 if ($this->iBack3D == null{
  253.                     $this->iBack3D new Aspect();
  254.  
  255.                      $a $this->chart->getAspect();
  256.                     $this->iBack3D->assign($a);
  257.  
  258.                     if ($a->getOrthogonal()) {
  259.                         $a->setOrthogonal(false);
  260.                         $a->setRotation(360);
  261.                         $a->setElevation(315);
  262.                         $a->setPerspective(0);
  263.                     }
  264.                     $a->setTilt(0);
  265.                 }
  266.             }
  267.         }
  268.     }
  269.  
  270.         /**
  271.           * The angle of Chart rotation.<br>
  272.           * The RotationAngle can be a valid integer number between 0 and 359.<br>
  273.           * This angle can be changed by code to rotate the Pie (or Polar). <br>
  274.           * Default value: 0
  275.           *
  276.           * @return int 
  277.           */
  278.     public function getRotationAngle({
  279.         return $this->rotationAngle;
  280.     }
  281.  
  282.         /**
  283.           * Sets angle of Chart rotation.<br>
  284.           * Default value: 0<br>
  285.           *
  286.           * <p>Example:
  287.           * <pre><font face="Courier" size="4">
  288.           * pieSeries = new com.steema.teechart.styles.Pie(myChart.getChart());
  289.           * pieSeries.getMarks().setVisible(true);
  290.           * pieSeries.getMarks().setStyle(MarksStyle.LABELPERCENT);
  291.           * pieSeries.fillSampleValues(5);
  292.           * pieSeries.setAngleSize(180);
  293.           * pieSeries.setRotationAngle(90);
  294.           * </font></pre></p>
  295.           *
  296.           * @param value int
  297.           */
  298.     public function setRotationAngle($value{
  299.         $this->rotationAngle $this->setIntegerProperty($this->rotationAngle$value 360);
  300.         $this->rotDegree = $this->rotationAngle self::$PIDEGREE;
  301.     }
  302.  
  303.         /**
  304.           * Returns the exact Screen position for a given pair of Angle and Radius
  305.           * values.
  306.           *
  307.           * @param angle double
  308.           * @param aXRadius double
  309.           * @param aYRadius double
  310.           * @return Point 
  311.           */
  312.     public function angleToPos($angle$aXRadius$aYRadius{
  313.         $tmpSin sin($this->rotDegree + $angle);
  314.         $tmpCos cos($this->rotDegree + $angle);
  315.         return new TeePoint($this->iCircleXCenter + MathUtils::round($aXRadius $tmpCos),
  316.                          $this->iCircleYCenter - MathUtils::round($aYRadius $tmpSin));
  317.     }
  318.  
  319.     public function associatedToAxis($a{
  320.         return true;
  321.     }
  322.  
  323.         /**
  324.           * Returns the angle from the XY point parameter to the circle center.
  325.           *
  326.           * @param int
  327.           * @param int
  328.           * @return double 
  329.           */
  330.     public function pointToAngle($x$y{
  331.          $result;
  332.         if (($x $this->iCircleXCenter== 0{
  333.             if ($y $this->iCircleYCenter{
  334.                 $result = -$this->HALFPI;
  335.             else {
  336.                 $result $this->HALFPI;
  337.             }
  338.         else
  339.         if (($this->iYRadius == 0|| ($this->iYRadius == 0)) {
  340.             $result 0;
  341.         else {
  342.             $result atan2(((double)($this->iCircleYCenter - $y/
  343.                                       (double) $this->iYRadius),
  344.                                      ((double) ($x $this->iCircleXCenter/
  345.                                       (double) $this->iXRadius));
  346.         }
  347.         if ($result 0{
  348.             $result += 2.0 M_PI;
  349.         }
  350.         $result -= $this->rotDegree;
  351.         if ($result 0{
  352.             $result += 2.0 M_PI;
  353.         }
  354.         return $result;
  355.     }
  356.  
  357.         /**
  358.           * Returns the radius from XY point to the circle center.
  359.           *
  360.           * @param int
  361.           * @param int
  362.           * @return double 
  363.           */
  364.     public function pointToRadius($x$y{
  365.         if ($this->getVertAxis(!= null{
  366.              $range $this->getVertAxis()->getMaximum(-
  367.                            $this->getVertAxis()->getMinimum();
  368.             if ($range == 0.0{
  369.                 return 0.0;
  370.             else {
  371.                  $dx $x $this->iCircleXCenter;
  372.                  $dy $y $this->iCircleYCenter;
  373.                 $dx *= $range / (double) $this->iXRadius;
  374.                 $dy *= $range / (double) $this->iYRadius;
  375.                 return sqrt($dx $dx $dy $dy$this->getVertAxis()->getMinimum();
  376.             }
  377.         else {
  378.             return 0.0;
  379.         }
  380.     }
  381.  
  382.         /**
  383.           * Returns the angle by which the Chart is rotated.
  384.           *
  385.           * @param angle int
  386.           */
  387.     public function rotate($angle{
  388.         $this->setRotationAngle(($this->rotationAngle $angle360);
  389.     }
  390.  
  391.         /**
  392.           * Returns the exact horizontal size of the ellipse's radius in pixels.<br>
  393.           * The ellipse XRadius can be set to a fixed number of pixels by using
  394.           * this method. Circled series.Circled controls whether both radii must
  395.           * be proportional to the Screen X/Y ratio.
  396.           *
  397.           * @return int 
  398.           */
  399.     public function getXRadius({
  400.         return $this->iXRadius;
  401.     }
  402.  
  403.         /**
  404.           * Returns the exact vertical size of the ellipse's radius in pixels.<br>
  405.           * The ellipse YRadius can be set to a fixed number of pixels by using this
  406.           * method. Circled series .Circled controls whether both radii must be
  407.           * proportional to the Screen X/Y ratio.
  408.           *
  409.           * @return int 
  410.           */
  411.     public function getYRadius({
  412.         return $this->iYRadius;
  413.     }
  414.  
  415.         /**
  416.           * Returns the exact horizontal position of ellipse's center in pixels.<br>
  417.           * Run-time and read only.
  418.           * The ellipse's radius is determined by Circled series.XRadius and YRadius.
  419.           * The AngleToPoint function converts from angles to X and Y Screen
  420.           * coordinates. The PointToAngle function converts from XY Screen positions
  421.           * to angles.
  422.           *
  423.           * @return int 
  424.           */
  425.     public function getCircleXCenter({
  426.         return $this->iCircleXCenter;
  427.     }
  428.  
  429.         /**
  430.           * Returns the exact vertical position of the ellipse's center in pixels.
  431.           * <br>
  432.           * The ellipse's radius is determined by Circled series.XRadius and YRadius.
  433.           * The AngleToPoint function converts from angles to X and Y Screen
  434.           * coordinates. The PointToAngle function converts from XY Screen positions
  435.           * to angles.
  436.           *
  437.           * @return int 
  438.           */
  439.     public function getCircleYCenter({
  440.         return $this->iCircleYCenter;
  441.     }
  442.  
  443.         /**
  444.           * Returns the width of the bounding Circle.
  445.           *
  446.           * @return int 
  447.           */
  448.     public function getCircleWidth({
  449.         return $this->circleWidth;
  450.     }
  451.  
  452.         /**
  453.           * Returns the height of the bounding Circle.
  454.           *
  455.           * @return int 
  456.           */
  457.     public function getCircleHeight({
  458.         return $this->circleHeight;
  459.     }
  460.  
  461.         /**
  462.           * Returns the rectangle that bounds the circle.<br>
  463.           * eg. Pie Series, in its default position displacement of elevevation,
  464.           * rotation ,etc not applied.
  465.  
  466.           * @return Rectangle 
  467.           */
  468.     public function getCircleRect({
  469.         return $this->rCircleRect;
  470.     }
  471.  
  472.     protected function shouldSerializeCircleBackColor({
  473.         return!$this->circleBackColor->isEmpty();
  474.     }
  475.  
  476.         /**
  477.           * Determines the color to fill the ellipse.<br>
  478.           * Setting it to Color.EMPTY indicates the CircledSeries to use to
  479.           * tChart.getPanel().getColor() color.
  480.           *
  481.           * @return Color 
  482.           */
  483.     public function getCircleBackColor({
  484.         return $this->circleBackColor;
  485.     }
  486.  
  487.         /**
  488.           * Determines the color to fill the ellipse.<br>
  489.           *
  490.           * @param value Color
  491.           */
  492.     public function setCircleBackColor($value{
  493.         if ($this->bBrush->getTransparency(!= 0{
  494.             $this->circleBackColor $value->transparentColor($this->bBrush->getTransparency());
  495.         else {
  496.             $this->circleBackColor $this->setColorProperty($this->circleBackColor$value);
  497.         }
  498.     }
  499.  
  500.         //CDI CircleGradient
  501.         /**
  502.           * Determines the Gradient which fills the ellipse.<br>
  503.           * Default value: null
  504.           *
  505.           * <p>Example:
  506.           * <pre><font face="Courier" size="4">
  507.           * series = new com.steema.teechart.styles.Polar(myChart.getChart());
  508.           * series.fillSampleValues(20);
  509.           * series.setCircled(true);
  510.           * series.getCircleGradient().setDirection(GradientDirection.RADIAL);
  511.           * series.getCircleGradient().setStartColor(Color.WHITE);
  512.           * series.getCircleGradient().setEndColor(Color.DARK_GRAY);
  513.           * series.getCircleGradient().setRadialX(100);
  514.           * series.getCircleGradient().setRadialY(-100);
  515.           * series.getCircleGradient().setVisible(true);
  516.           * series.getCirclePen().setColor(Color.NAVY);
  517.           * series.getCirclePen().setStyle(DashStyle::$DOT);
  518.           * series.getCirclePen().setWidth(2);
  519.           * </font></pre></p>
  520.           *
  521.           * @return Gradient 
  522.           */
  523.     public function getCircleGradient({
  524.         if ($this->circleGradient == null{
  525.             $this->circleGradient new Gradient($this->chart);
  526.         }
  527.         return $this->circleGradient;
  528.     }
  529.  
  530.         /**
  531.           * The CirleSeries as elliptical or circular.<br>
  532.           * Default value: false
  533.           *
  534.           * @return boolean 
  535.           */
  536.     public function getCircled({
  537.         return $this->circled;
  538.     }
  539.  
  540.         /**
  541.           * Sets CirleSeries as elliptical or circular.<br>
  542.           * Default value: false
  543.           *
  544.           * @param value boolean
  545.           */
  546.     public function setCircled($value{
  547.         $this->circled $this->setBooleanProperty($this->circled$value);
  548.     }
  549.  
  550.         /**
  551.           * The ellipse's horizontal radius in pixels.<br>
  552.           * Default value: 0
  553.           *
  554.           * @return int 
  555.           */
  556.     public function getCustomXRadius({
  557.         return $this->customXRadius;
  558.     }
  559.  
  560.         /**
  561.           * Sets ellipse's horizontal radius in pixels.<br>
  562.           * Default value: 0
  563.           *
  564.           * @param value int
  565.           */
  566.     public function setCustomXRadius($value{
  567.         $this->customXRadius $this->setIntegerProperty($this->customXRadius$value);
  568.     }
  569.  
  570.         /**
  571.           * The ellipse's vertical radius in pixels.<br>
  572.           * Default value: 0
  573.           *
  574.           * @return int 
  575.           */
  576.     public function getCustomYRadius({
  577.         return $this->customYRadius;
  578.     }
  579.  
  580.         /**
  581.           * Sets ellipse's vertical radius in pixels.<br>
  582.           * Default value: 0
  583.           *
  584.           * @param value int
  585.           */
  586.     public function setCustomYRadius($value{
  587.         $this->customYRadius $this->setIntegerProperty($this->customYRadius$value);
  588.     }
  589. }
  590. ?>

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