Go to the documentation of this file.00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00015 final class GoogleChartDataSet
00016 {
00017 private $data = array();
00018
00019 private $minMax = null;
00020
00021 private $base = null;
00022
00026 public static function create()
00027 {
00028 return new self;
00029 }
00030
00031 public function __construct()
00032 {
00033 $this->minMax = FloatRange::create(0, 0);
00034 }
00035
00039 public function setData(array $data)
00040 {
00041 $this->data = $data;
00042
00043 return $this;
00044 }
00045
00046 public function getData()
00047 {
00048 return $this->data;
00049 }
00050
00054 public function addElement($element)
00055 {
00056 $this->data[] = $element;
00057
00058 return $this;
00059 }
00060
00064 public function setBase($base)
00065 {
00066 $this->base = $base;
00067
00068
00069 $this->minMax->setMax(0);
00070
00071 return $this;
00072 }
00073
00074 public function getBase()
00075 {
00076 return $this->base;
00077 }
00078
00079 public function getSize()
00080 {
00081 return count($this->data);
00082 }
00083
00084 public function getMin()
00085 {
00086 return $this->minMax->getMin();
00087 }
00088
00089 public function setMax($max)
00090 {
00091 $this->minMax->setMax($max);
00092
00093 return $this;
00094 }
00095
00096 public function getMax()
00097 {
00098 if ($this->minMax->getMax() == 0)
00099 $this->calculateMax();
00100
00101 return $this->minMax->getMax();
00102 }
00103
00104 public function getMinMax()
00105 {
00106 return $this->minMax;
00107 }
00108
00109 public function getStepSize()
00110 {
00111 Assert::isTrue($this->base !== null);
00112
00113 if ($this->base == 0)
00114 return 0;
00115 else
00116 return $this->getMax() / $this->base;
00117 }
00118
00122 private function calculateMax()
00123 {
00124 $maxValue = max($this->data);
00125
00126 if ($this->base)
00127 $maxValue =
00128 MathUtils::alignByBase($maxValue, $this->base, true);
00129
00130 if ($maxValue == 0) {
00131 if ($this->base)
00132 $maxValue = $this->base;
00133 else
00134 $maxValue = 1;
00135 }
00136
00137 $this->minMax->setMax($maxValue);
00138
00139 return $this;
00140 }
00141 }
00142 ?>