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

Source for file ValueList.php

Documentation is available at ValueList.php

  1. <?php
  2.  
  3. /**
  4.  * ValueList class
  5.  *
  6.  * Description: Array to hold Series data point values
  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 ValueList extends TeeBase {
  17.  
  18.     public $defaultCapacity=0;
  19.     public $value;
  20.     public $count=0;
  21.     public $capacity;
  22.     public $dateTime=false;
  23.     public $maximum;
  24.     public $minimum;
  25.     public $total;
  26.     public $totalABS;
  27.     public $statsOk;
  28.     public $tempValue;
  29.     public $valueSource = "";
  30.     public $series;
  31.  
  32.     private $order;
  33.  
  34.     // "name" should not be transient, as it can be the "valueSource"
  35.     // (setDataMember) of another series source. So it must be serialized.
  36.     protected $name;
  37.  
  38.     // Interceptors
  39.     function __get$property {
  40.       $method ="get{$property}";
  41.       if method_exists$this$method ) ) {
  42.         return $this->$method();
  43.       }
  44.     }
  45.  
  46.     function __set $property,$value {
  47.       $method ="set{$property}";
  48.       if method_exists$this$method ) ) {
  49.         return $this->$method($value);
  50.       }
  51.     }
  52.  
  53.     public function ValueList($s$name$initialCapacity=-1{
  54.         if ($initialCapacity==-1{
  55.             $initialCapacity=$this->defaultCapacity;
  56.         }
  57.  
  58.         // TODO review before $this->value = new double[1];
  59.         $this->value = Array();
  60.         $this->order ValueListOrder::$NONE;
  61.  
  62.         parent::__construct(null);
  63.        
  64.         $this->series = $s;
  65.         $this->series->valuesListAdd($this);
  66.         $this->name = $name;
  67.         $this->capacity = $initialCapacity;
  68.     }
  69.  
  70.         /**
  71.           * Field to use as source for this value list.<br>
  72.           * Default value: ""
  73.           *
  74.           * @return String 
  75.           */
  76.     public function getDataMember({
  77.         return $this->valueSource;
  78.     }
  79.  
  80.         /**
  81.           * Field to use as source for this value list.<br>
  82.           * Default value: ""
  83.           *
  84.           * @param value String
  85.           */
  86.     public function setDataMember($value{
  87.         if ($this->valueSource->equals($value)) {
  88.             $this->valueSource = $value;
  89.             if ($this->series != null{
  90.                 $this->series->checkDataSource();
  91.             }
  92.         }
  93.     }
  94.  
  95.         /**
  96.           * Allows values to be expressed either as numbers or as Date+Time
  97.           * values.<br><br>
  98.           * Each Series value list has a boolean property called DateTime.  The
  99.           * boolean DateTime method tells TeeChart what type the numbers are. The
  100.           * horizontal (x axis) and vertical (y axis) value defaults are number
  101.           * format (DateTime False). DateTime can be changed both at design-time and
  102.           * run-time, forcing the Chart to repaint. It used whenever a value must be
  103.           * converted to text, for example, to draw it as the chart axis labels.
  104.           * Axis labels will be drawn in DateTime or numeric format accordingly to
  105.           * the setting of the DateTime method. <br><br>
  106.           * You can also set the Chart Series ValueFormat and the Chart Axis
  107.           * DateTimeFormat formatting strings, to control how the values will be
  108.           * displayed. <br>
  109.           * Default value: false
  110.           *
  111.           * @return boolean 
  112.           */
  113.     public function getDateTime({
  114.         return $this->dateTime;
  115.     }
  116.  
  117.         /**
  118.           * Allows values to be expressed either as numbers or as Date+Time
  119.           * values.<br>
  120.           * Default value: false
  121.           *
  122.           * @param value boolean
  123.           */
  124.     public function setDateTime($value{
  125.         if ($this->dateTime != $value{
  126.             $this->dateTime = $value;
  127.             $this->series->invalidate();
  128.         }
  129.     }
  130.  
  131.         /**
  132.           * Determines if points are automatically sorted or left at original
  133.           * position.<br> Runtime only. <br>
  134.           * This Order is used by default by the Series XValues to draw lines from
  135.           * Left to Right. Setting the XValues.Order property to loNone will respect
  136.           * the points order at point creation. This can be used to draw polygons.
  137.           * <br>Default value: None
  138.           *
  139.           * @return ValueListOrder 
  140.           */
  141.     public function getOrder({
  142.         return $this->order;
  143.     }
  144.  
  145.         /**
  146.           * Determines if points are automatically sorted or left at original
  147.           * position.<br> Runtime only. <br>
  148.           * Default value: None
  149.           *
  150.           * @param value ValueListOrder
  151.           */
  152.     public function setOrder($value{
  153.         if ($this->order != $value{
  154.             $this->order $value;
  155.  
  156.             //DB: Removed as it breaks series initialization at design-time,
  157.             //when changing series order it'll call fillSampleValues.
  158.             //if (series != null) {
  159.             //    series.checkDataSource();
  160.             //}
  161.         }
  162.     }
  163.  
  164.         /**
  165.           * Returns the name of this ValueList.
  166.           * The Name property can be used to link series when using functions.
  167.           * You can link one series ValueList to another series list, by using
  168.           * the setDataMember method.
  169.           *
  170.           * For example:
  171.           *
  172.           * mySeries.setDataSource( myCandle );
  173.           * mySeries.getYValues().setDataMember(myCandle.getHighValues().getName());
  174.           *
  175.           * @param name String
  176.           */
  177.     public function setName($name{
  178.         $this->name = $name;
  179.     }
  180.  
  181.         /**
  182.           * Returns the name of this ValueList.
  183.           * The "Name" property is used as the "dataMember" of other series
  184.           * when they are linked through functions.
  185.           *
  186.           * @return String 
  187.           */
  188.     public function getName({
  189.         return $this->name;
  190.     }
  191.  
  192.         /**
  193.           * Removes all values in the list.
  194.           * Warning: You should not call this "clear" method directly.
  195.           * Call the series "clear" method instead.
  196.           */
  197.     public function clear({
  198.         $this->count = 0;
  199.         $this->value = Array()// todo review new double[1];
  200.     }
  201.  
  202.         /**
  203.           * Returns the corresponding point index which has the specified Value.<br>
  204.           * You can use it for example to obtain X co-ordinates based on Y values, or
  205.           * vice-versa.
  206.           *
  207.           * @param value double
  208.           * @return int 
  209.           */
  210.     public function indexOf($value{
  211.         for $t 0$t sizeof($this->value)$t++{
  212.             if ($this->value[$t== $value{
  213.                 return $t;
  214.             }
  215.         }
  216.         return -1;
  217.     }
  218.  
  219.     public function removeRange($index$count{
  220.         $this->count -= $count;
  221.         for $t $index$t $this->count$t++{
  222.             $this->value[$t$this->value[$t $count];
  223.         }
  224.         $this->statsOk = false;
  225.     }
  226.  
  227.     public function removeAt($index{
  228.         $this->removeRange($index1);
  229.     }
  230.  
  231.         /**
  232.           * Re-orders Series points, interchanging their position in the Series
  233.           * Values lists.<br>
  234.           * By default, Series are set to sort points in ascending order using their
  235.           * X coordinates. This is accomplished with this code: <br><br>
  236.           * [C#]<br>
  237.           * tChart1.getSeries(0).getXValues().setOrder( loAscending )<br>
  238.           * tChart1.getSeries(0).getYValues().setOrder( loNone )<br><br>
  239.           * By default, Series draw points using the point ValueIndex, except in
  240.           * some non common situations like having the horizontal axis inverted.<br>
  241.           * <b>Important Note:</b>  Re-Ordering Series points do NOT change point
  242.           * X coordinates. Series points which have no X coordinates are assigned a
  243.           * unique incremental number to determine the point horizontal positions.
  244.           * Automatic Point indexes  start at zero. You will need to change every
  245.           * point X coordinate when sorting Series points with automatic X values.
  246.           */
  247.     public function sort({
  248.         if ($this->order != ValueListOrder::$NONE{
  249.             $this->Utils->sort(0$this->count - 1,
  250.                             new CompareValueIndex(),
  251.                             $this->series->getValueIndexSwapper()
  252.                        );
  253.         }
  254.     }
  255.  
  256.         // Eliminates excess of empty values in array.
  257.         // (Array always contains Count plus some more empty values to
  258.         // reduce overhead expanding the array each time a new value is added).
  259.     public function trim({
  260.         /*double[]*/ $newValue array()// todo review double[$this->count];
  261.         $this->System->arraycopy($this->value,0,$this->newValue,0,$this->count);
  262.  
  263.         /*
  264.         for (int t = 0; t < count; t++) {
  265.             newValue[t] = value[t];
  266.         }
  267.         */
  268.  
  269.         $this->value = $this->newValue;
  270.     }
  271.  
  272.         /**
  273.           * Returns the First point value.
  274.           *
  275.           * @return double 
  276.           */
  277.     public function getFirst({
  278.         return $this->value[0];
  279.     }
  280.  
  281.     function insertChartValue($valueIndex,$value{
  282.  
  283.         $this->incrementArray();
  284.  
  285.         for ($t $this->count - 1$t $valueIndex$t--{
  286.               $this->value[$t$this->value[$t 1];
  287.         }
  288.  
  289.         $this->value[$valueIndex$value;
  290.         $this->statsOk = false;
  291.     }
  292.  
  293.         /**
  294.           * Returns the Last point value.<br>
  295.           * This is the same value as the Count - 1 index value:
  296.           *
  297.           * @return double 
  298.           */
  299.     public function getLast({
  300.         return $this->value[$this->count - 1];
  301.     }
  302.  
  303.         /**
  304.           * Obsolete.&nbsp;Please use IndexOf method instead.
  305.           *
  306.           * @param value double
  307.           * @return int 
  308.           */
  309.     public function locate($value{
  310.         return $this->indexOf($value);
  311.     }
  312.  
  313.     public function assign($value{
  314.         $this->order $value->order;
  315.         $this->dateTime = $value->dateTime;
  316.         $this->name = $value->name;
  317.         $this->valueSource = $value->valueSource;
  318.     }
  319.  
  320.     private function calcStats({
  321.         if ($this->count > 0{
  322.             $this->minimum = $this->value[0];
  323.             $this->maximum = $this->minimum;
  324.             $this->total = $this->minimum;
  325.             $this->totalABS = abs($this->total);
  326.  
  327.              // todo review before - for $t = 1....
  328.             for $t 1$t $this->count$t++{
  329.                 $tmp $this->value[$t];
  330.                 if ($tmp $this->minimum{
  331.                     $this->minimum = $tmp;
  332.                 }
  333.                 if ($tmp $this->maximum{
  334.                     $this->maximum = $tmp;
  335.                 }
  336.                 $this->total += $tmp;
  337.                 $this->totalABS += abs($tmp);
  338.             }
  339.         else {
  340.             $this->minimum = 0;
  341.             $this->maximum = 0;
  342.             $this->total = 0;
  343.             $this->totalABS = 0;
  344.         }
  345.         $this->statsOk = true;
  346.     }
  347.  
  348.     /**
  349.       *
  350.       * @return double 
  351.       */
  352.     public function getRange()
  353.         {
  354.                 if (!$this->statsOk{
  355.                         $this->calcStats();
  356.                 }
  357.                 return $this->maximum - $this->minimum;
  358.         }
  359.  
  360.         /**
  361.           * The highest of all values in the list.<br>
  362.           * As new points are being added to Series, the IValueList object
  363.           * calculates the Maximum, Minimum and TotalABS properties. <br>
  364.           * This applies to all Series lists of values, such as XValues, YValues,
  365.           * etc. <br>
  366.           *
  367.           * @return double 
  368.           */
  369.     public function getMaximum()
  370.         {
  371.                 if (!$this->statsOk{
  372.                         $this->calcStats();
  373.                 }
  374.                 return $this->maximum;
  375.         }
  376.  
  377.         /**
  378.           * Obsolete.&nbsp;Please use Maximum method instead.
  379.           *
  380.           * @return double 
  381.           */
  382.     public function getMaxValue({
  383.         return $this->maximum;
  384.     }
  385.  
  386.         /**
  387.           * Obsolete.&nbsp;Please use Minimum instead.
  388.           *
  389.           * @return double 
  390.           */
  391.     public function getMinValue({
  392.         return $this->minimum;
  393.     }
  394.  
  395.         /**
  396.           * The lowest of all values in the list.<br>
  397.           *
  398.           * @see ValueList#getMaximum
  399.           * @return double 
  400.           */
  401.     public function getMinimum({
  402.         if (!$this->statsOk{
  403.             $this->calcStats();
  404.         }
  405.         return $this->minimum;
  406.     }
  407.  
  408.         /**
  409.           * The sum of all IValueList values.<br>
  410.           * When adding, deleting or modifying point values using the right methods,
  411.           * Total is automatically incremented and decremented. <br>
  412.           * Total is used by some Functions to improve speed when performing
  413.           * calculations against point values, where having already calculated
  414.           * the sum of point values is necessary. <br>
  415.           *
  416.           * @return double 
  417.           */
  418.     public function getTotal({
  419.         if (!$this->statsOk{
  420.             $this->calcStats();
  421.         }
  422.         return $this->total;
  423.     }
  424.  
  425.         /**
  426.           * The sum of all absolute values in the list.<br>
  427.           * Run-time and read only. <br>
  428.           * The values are first converted to their absolute value.<br>
  429.           * Pie series, for example, uses this property to calculate the percent
  430.           * each Pie slice represents. <br>
  431.           *
  432.           * @see ValueList#getMaximum
  433.           * @return double 
  434.           */
  435.     public function getTotalABS({
  436.         if (!$this->statsOk{
  437.             $this->calcStats();
  438.         }
  439.         return $this->totalABS;
  440.     }
  441.  
  442.         //set { totalABS=value; } // TODO: How to avoid Pie series setting ?
  443.  
  444.     public function getValue($index{
  445.         return $this->value[$index];
  446.     }
  447.  
  448.     public function setValue($index$value{
  449.         $this->value[$index$value;
  450.         $this->statsOk = false;
  451.     }
  452.  
  453.     // For XMLEncoder only
  454.     public function getValues({
  455.       return $this->value;
  456.     }
  457.  
  458.     // For XMLEncoder only
  459.     public function setValues($value{
  460.       $this->value=$value;
  461.     }
  462.  
  463.     // For XMLEncoder only
  464.     public function getCount({
  465.       return $this->count;
  466.     }
  467.  
  468.     // For XMLEncoder only
  469.     public function setCount($value{
  470.       $this->count=$value;
  471.     }
  472.  
  473.     public function asDateTime($index{
  474.         return new DateTime($this->value[$index]);
  475.     }
  476.  
  477.     private function incrementArray({
  478.         $this->count++;
  479.          $tmp sizeof($this->value);
  480.         if ($this->count > $tmp{
  481.             if ($this->capacity > 0{
  482.                 $tmp += $this->capacity;
  483.             else
  484.             if ($this->count > 3{
  485.                 $tmp += $this->count / 4;
  486.             else {
  487.                 $tmp += 100;
  488.             }
  489.             /*double[]*/ $newValue array()//todo review new double[$tmp];
  490.  
  491. // TODO Review   before         System->arraycopy($this->value,0,newValue,0,$this->count-1);
  492.  
  493.             $newValue=$this->value;
  494.             $this->value = $newValue;
  495.         }
  496.     }
  497.  
  498.     function addChartValue($value{
  499.  
  500.                 if ($this->order == ValueListOrder::$NONE{
  501.                         $result $this->count;
  502.  
  503.                         $this->incrementArray();
  504.                         $this->value[$result$value;
  505.                 else {
  506.                         $t $this->count - 1;
  507.                         if (($t == -1||
  508.                                 (($this->order == ValueListOrder::$ASCENDING&&
  509.                                   ($value >= $this->value[$t])) ||
  510.                                 (($this->order == ValueListOrder::$DESCENDING&&
  511.                                   ($value <= $this->value[$t]))) {
  512.  
  513.                                 $result $this->count;
  514.                                 $this->incrementArray();
  515.                                 $this->value[$result$value;
  516.                         else {
  517.                                 if ($this->order == ValueListOrder::$ASCENDING{
  518.                                         while (($t >= 0&& ($this->value[$t$value)) {
  519.                                                 $t--;
  520.                                         }
  521.                                 else {
  522.                                         while (($t >= 0&& ($this->value[$t$value)) {
  523.                                                 $t--;
  524.                                         }
  525.                                 }
  526.                                 $result $t 1;
  527.  
  528.                                 $this->incrementArray();
  529.                                 for ($t ($this->count - 1)$t ($result)$t--{
  530.                                         $this->value[$t$this->value[$t 1];
  531.                                 }
  532.                                 $this->value[$result$value;
  533.                         }
  534.                 }
  535.                 $this->statsOk = false;
  536.                 return $result;
  537.         }
  538.  
  539.  
  540.     /**
  541.       * Renumbers all values in a ValueList class starting at zero.<br>
  542.       * <b>Warning:</b>  Calling fillSequence removes any previous value in a
  543.       * ValueList. <br>
  544.       * Use fillSequence when deleting points at runtime.
  545.       *
  546.       * @see ValueList#sort
  547.       */
  548.     public function fillSequence({
  549.         for $t 0$t $this->count$t++{
  550.             $this->value[$t$t;
  551.         }
  552.         $this->statsOk = false;
  553.     }
  554.  
  555.     public function exchange($index1$index2{
  556.         $tmp $value[index1];
  557.         $this->value[$index1$this->value[$index2];
  558.         $this->value[$index2$this->tmp;
  559.     }
  560. }
  561.  
  562.   /* TODO   class CompareValueIndex implements Comparator {
  563.         public function compare($a, $b) {
  564.              $result = ($this->value[$a] < $this->value[$b]) ? -1 :
  565.                 ($this->value[$a] > $this->value[$b]) ? 1 : 0;
  566.             if ($this->order == ValueListOrder::$DESCENDING) {
  567.                 $result = -$result;
  568.             }
  569.             return $result;
  570.         }
  571.         }
  572.  
  573.          */
  574. ?>

Documentation generated on Wed, 16 Jun 2010 12:09:08 +0200 by phpDocumentor 1.4.1