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

Source for file SeriesCollection.php

Documentation is available at SeriesCollection.php

  1. <?php
  2.  
  3. /**
  4.  * SeriesCollection class
  5.  *
  6.  * Description: The SeriesCollection class, a collection of Series objects,
  7.  * is manipulated via the TChart TChart.getSeries() method.
  8.  *
  9.  * @author
  10.  * @copyright (c) 1995-2008 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. final class SeriesCollection extends ArrayObject {
  18.  
  19.     public $chart;
  20.  
  21.     private $arrayList array();
  22.     private $applyZOrder true;
  23.  
  24.     // Interceptors
  25.     function __get$property {
  26.       $method ="get{$property}";
  27.       if method_exists$this$method ) ) {
  28.         return $this->$method();
  29.       }
  30.     }
  31.  
  32.     function __set $property,$value {
  33.       $method ="set{$property}";
  34.       if method_exists$this$method ) ) {
  35.         return $this->$method($value);
  36.       }
  37.     }
  38.  
  39.     public function SeriesCollection($c=null{
  40.         parent::__construct();
  41.         $this->chart = $c;
  42.     }
  43.  
  44.     public function internalAdd($s{
  45.         $this->add($s);
  46.     }
  47.  
  48.     /* TODO
  49.     public function add(Class type) throws InstantiationException,
  50.             IllegalAccessException {
  51.         return add((Series) (type.newInstance()));
  52.     }
  53.  
  54.     public function add($type) {
  55.         return $this->add($type->newInstance());
  56.     }
  57.     */
  58.  
  59.     /**
  60.      * Adds a new Series instance to Chart.
  61.      *
  62.      * @param Series The Series instance to add.
  63.      * @return Series The same Series.
  64.      */
  65.     public function add($s{
  66.         if ($this->indexOf($s== -1{
  67.            if (is_object($this)) {
  68.               parent::offsetset(sizeof($this),$s);
  69.            }
  70.            else
  71.            {
  72.               parent::append($s);
  73.            }
  74.  
  75.             // TODO $this->chart->broadcastEvent($s, SeriesEventStyle.ADD);
  76.  
  77.             // TODO remove, but adding series throught delphi ide does not
  78.             // save the chart property into the object
  79.             // temp line
  80.             $this->chart=$s->getChart();
  81.  
  82.             if (!($s->getChart(=== $this->chart)) {
  83.                 $s->setChart($this->chart);
  84.             }
  85.         }
  86.         return $s;
  87.     }
  88.  
  89.     public function getSeries($index{
  90.         return parent::offsetget($index);
  91.     }
  92.  
  93.     public function setSeries($index$value{
  94.         parent::offsetset($index,$value);
  95.     }
  96.  
  97.     public function insert($index$s{
  98.         /** @todo VALID? */
  99.         // $this->add(index, s);
  100.     }
  101.  
  102.     public function moveTo($s$index{
  103.         $old $this->indexOf($s);
  104.  
  105.         if ($old != $index{
  106.             $tmp $this->get($index);
  107.             $this->set($index$s);
  108.             $this->set($old$tmp);
  109.             $s->repaint();
  110.         }
  111.     }
  112.  
  113.     /**
  114.      * Returns the corresponding point index which has the specified Value.
  115.      *
  116.      * @param Series
  117.      * @return int 
  118.      */
  119.     public function indexOf($s{
  120.         for ($t 0$t $this->count()$t++{
  121.             if ($this->getSeries($t=== $s{
  122.                 return $t;
  123.             }
  124.         }
  125.         return -1;
  126.     }
  127.  
  128.     public function withTitle($title{
  129.         for ($t 0$t sizeof($this)$t++{
  130.             $s $this->getSeries($t);
  131.             if ($s->toString()->equals($title)) {
  132.                 return $s;
  133.             }
  134.         }
  135.         return null;
  136.     }
  137.  
  138.     /**
  139.      * Deletes the specified Series from the Chart list of series.
  140.      *
  141.      * @param Series
  142.      */
  143.     public function remove($s{
  144.         $i $this->indexOf($s);
  145.  
  146.         if ($i > -1{
  147.             // TODO $this->chart->broadcastEvent($s, SeriesEventStyle.REMOVE);
  148.             parent::offsetUnset($i);
  149.  
  150.             $tmpArray=Array();
  151.             foreach($this as $item)
  152.             {
  153.                 $tmpArray[]=$item;
  154.             }
  155.  
  156.             $this->clear();
  157.             for ($i=0;$i<sizeof($tmpArray);$i++)
  158.             {
  159.                $this[$i]=$tmpArray[$i];
  160.             }
  161.             // TODO $this->chart->invalidate();
  162.         }
  163.     }
  164.  
  165.     /**
  166.      * Removes all Series from the Chart but  does not dispose of (destroy)
  167.      * them.
  168.      */
  169.     public function removeAllSeries({
  170.         while (sizeof($this0{
  171.             $this->remove($this[0]);
  172.         }
  173.     }
  174.  
  175.     /**
  176.      * Changes the Series order, swapping one Series Z position with another.<br>
  177.      * The Chart repaints to reflect the new Series order. <br>
  178.      * It accesses TChart.SeriesList method.
  179.      *
  180.      * @param series1 int
  181.      * @param series2 int
  182.      */
  183.     public function exchange($series1$series2{
  184.         $s1 $this->getSeries($series1);
  185.         $s2 $this->getSeries($series2);
  186.         $this->setSeries($series1$s2);
  187.         $this->setSeries($series2$s1);
  188.  
  189.         // TODO $this->chart->broadcastEvent(null, SeriesEventStyle.SWAP);
  190.         $this->chart->invalidate();
  191.     }
  192.  
  193.     /**
  194.      * Removes (and optionally disposes) all Series.
  195.      *
  196.      * @param dispose boolean
  197.      */
  198.     public function clear($dispose=true{
  199.  
  200.         foreach($this as $key=>$item)
  201.         {
  202.             // TODO review parent::offsetUnset($key);
  203.         }
  204.  
  205.        /*     $tmp->onDisposing();
  206.             if ($dispose) {
  207.                 $tmp->dispose();
  208.             } */
  209.  
  210.         /* TODO review - This cannot be done due to the php bug (does not
  211.            serialize fine the classes which extends from ArrayObject, it does
  212.            not serializes the properties. This has been fixed in php 5.3.
  213.  
  214.         $this->arrayList->clear();
  215.         before super.clear();
  216.  
  217.         $this->chart->invalidate();
  218.         */
  219.  
  220.         // TODO
  221.         // $this->chart->broadcastEvent(null, SeriesEventStyle.REMOVEALL);
  222.     }
  223.  
  224.     /**
  225.      * Defines the Chart component.
  226.      *
  227.      * @return IBaseChart 
  228.      */
  229.     public function getChart({
  230.         return $this->chart;
  231.     }
  232.  
  233.     public function activeUseAxis({
  234.         for ($t 0$t sizeof($this)$t++{
  235.             $s $this->getSeries($t);
  236.             if ($s->getActive()) {
  237.                 return $s->getUseAxis();
  238.             }
  239.         }
  240.         return true;
  241.     }
  242.  
  243.     /**
  244.      * Sets multiple Series on same Chart in different Z spaces when true.<br>
  245.      * Run-time only. <br>
  246.      * It's valid only when TChart.View3D is true and when there's more than
  247.      * one Series in the same chart.<br>
  248.      * When false, all Series are drawn using the full Chart Z space. The
  249.      * Chart output can be confusing if Series overlap. <br>
  250.      * Default value: true
  251.      *
  252.      * @return boolean 
  253.      */
  254.     public function getApplyZOrder({
  255.         return $this->applyZOrder;
  256.     }
  257.  
  258.     /**
  259.      * Sets multiple Series on same Chart in different Z spaces when true.<br>
  260.      * Run-time only. <br>
  261.      * Default value: true
  262.      *
  263.      * @param value boolean
  264.      */
  265.     public function setApplyZOrder($value{
  266.         $this->applyZOrder $value;
  267.         if ($this->chart != null{
  268.             $this->chart->invalidate();
  269.         }
  270.     }
  271.  
  272.     /**
  273.      * Adds the specified NumValues random points to all series in the collection.
  274.      *
  275.      * @param numValues int the number of sample values to add.
  276.      */
  277.     public function fillSampleValues($numValues=-1{
  278.         for ($t 0$t sizeof($this)$t++{
  279.             $this->getSeries($t)->fillSampleValues($numValues);
  280.         }
  281.     }
  282.  
  283.     public function setChart($chart{
  284.         $this->chart = $chart;
  285.  
  286.         for ($t 0$t sizeof($this)$t++{
  287.             $this->getSeries($t)->setChart($chart);
  288.         }
  289.     }
  290. }
  291. ?>

Documentation generated on Wed, 16 Jun 2010 12:07:56 +0200 by phpDocumentor 1.4.1