Go to the documentation of this file.00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 require_once("phplot.php");
00017
00018 class PHPlot_Data extends PHPlot
00019 {
00023 function PHPlot_Data($which_width=600, $which_height=400, $which_output_file=NULL, $which_input_file=NULL)
00024 {
00025 if (! isset($this->img)) {
00026 $this->PHPlot($which_width, $which_height, $which_output_file, $which_input_file);
00027 }
00028 }
00029
00036 function DoScaleData($even, $show_in_legend)
00037 {
00038 $offset = 0;
00039
00040 if ($this->data_type == 'text-data') {
00041 $offset = 1;
00042 } elseif ($this->data_type != 'data-data') {
00043 $this->DrawError('wrong data type!!');
00044 return FALSE;
00045 }
00046
00047
00048
00049 $maxmax = 0;
00050 for($i=0; $i < $this->num_data_rows; $i++) {
00051 $rowsize = count($this->data[$i]);
00052 for ($j=$offset; $j < $rowsize; $j++) {
00053 if ($this->data[$i][$j] > @ $max[$j])
00054 $max[$j] = $this->data[$i][$j];
00055 if (@ $max[$j] > $maxmax)
00056 $maxmax = $max[$j];
00057 }
00058 }
00059
00060
00061 $end = count($max) + $offset;
00062 for ($i=$offset; $i < $end; $i++) {
00063 if ($max[$i] == 0 || $max[$i] == $maxmax) {
00064 $amplify[$i] = 1;
00065 } else {
00066 if ($even) {
00067 $amp = pow(10,round(log10($maxmax / $max[$i]))-1);
00068 if ($amp * $max[$i] * 5 < $maxmax) {
00069 $amp *= 5;
00070 } elseif ($amp * $max[$i] * 2 < $maxmax) {
00071 $amp *= 2;
00072 }
00073 } else {
00074 $amp = $maxmax / $max[$i];
00075 $digits = floor(log10($amp));
00076 $amp = round($amp/pow(10,$digits-1))*pow(10,$digits-1);
00077 }
00078 $amplify[$i] = $amp;
00079 }
00080 if ($amplify[$i] != 1 && $show_in_legend)
00081 @ $this->legend[$i] .= "*$amplify[$i]";
00082 }
00083
00084
00085
00086
00087 for ($i = 0; $i < $this->num_data_rows; $i++) {
00088 $rowsize = count($this->data[$i]);
00089 for ($j=$offset; $j < $rowsize; $j++) {
00090 $this->data[$i][$j] *= $amplify[$j];
00091 }
00092 }
00093
00094
00095 if ( ! $this->y_tick_increment) {
00096 $this->SetYTickIncrement() ;
00097 }
00098
00099 return TRUE;
00100 }
00101
00102
00117 function DoMovingAverage($datarow, $interval, $show=TRUE, $color=NULL, $width=NULL)
00118 {
00119 $off = 1;
00120
00121 $this->PadArrays();
00122
00123 if ($interval == 0) {
00124 $this->DrawError('DoMovingAverage(): interval can\'t be 0');
00125 return FALSE;
00126 }
00127
00128 if ($datarow >= $this->records_per_group) {
00129 $this->DrawError("DoMovingAverage(): Data row out of bounds ($datarow >= $this->records_per_group)");
00130 return FALSE;
00131 }
00132
00133 if ($this->data_type == 'text-data') {
00134
00135 } elseif ($this->data_type == 'data-data') {
00136 $off++;
00137 } else {
00138 $this->DrawError('DoMovingAverage(): wrong data type!!');
00139 return FALSE;
00140 }
00141
00142
00143 if ($color) {
00144 array_push($this->ndx_data_colors, $this->SetIndexDarkColor($color));
00145 } else {
00146 array_push($this->ndx_data_colors, $this->SetIndexDarkColor($this->data_colors[$datarow]));
00147 }
00148
00149 if ($width) {
00150 array_push($this->line_widths, $width);
00151 } else {
00152 array_push($this->line_widths, $this->line_widths[$datarow] * 2);
00153 }
00154
00155 if ($show) {
00156 $this->legend[$this->records_per_group-1] = "(MA[$datarow]:$interval)";
00157 }
00158
00159 $datarow += $off;
00160 for ($i = 0; $i < $this->num_data_rows; $i++) {
00161 $storage[$i % $interval] = @ $this->data[$i][$datarow];
00162 $ma = array_sum($storage);
00163 $ma /= count($storage);
00164 array_push($this->data[$i], $ma);
00165 $this->num_recs[$i]++;
00166 }
00167 $this->records_per_group++;
00168
00169 return TRUE;
00170 }
00171
00172
00178 function DoExponentialMovingAverage($datarow, $perc, $show_in_legend)
00179 {
00180 if ($this->data_type == 'text-data') {
00181 $datarow++;
00182 } elseif ($this->data_type != 'data-data') {
00183 $this->DrawError('DoWeightedMovingAverage(): wrong data type!!');
00184 return FALSE;
00185 }
00186
00187 if ($show_in_legend) {
00188 $this->legend[$datarow] .= " (MA: $interval)";
00189 }
00190
00191 $storage[0] = $this->data[0][$datarow];
00192 for ($i=1;$i < $this->num_data_rows; $i++) {
00193 $storage[$i] = @ $storage[$i-1] + $perc * ($this->data[$i][$datarow] - $storage[$i-1]);
00194 $ma = array_sum($storage);
00195 $ma /= count($storage);
00196 $this->data[$i][$datarow] = $ma;
00197 }
00198 return TRUE;
00199 }
00200
00201
00205 function DoRemoveDataSet($index)
00206 {
00207 $offset = 1;
00208 if ($this->data_type == 'data-data') {
00209 $offset++;
00210 } elseif ($this->data_type != 'text-data') {
00211 $this->DrawError('wrong data type!!');
00212 return FALSE;
00213 }
00214
00215 $index += $offset;
00216 foreach ($this->data as $key=>$val) {
00217 foreach ($val as $key2=>$val2) {
00218 if ($key2 >= $index) {
00219 if (isset($this->data[$key][$key2+1])) {
00220 $this->data[$key][$key2] = $this->data[$key][$key2+1];
00221 } else {
00222 unset($this->data[$key][$key2]);
00223 }
00224 }
00225 }
00226 }
00227 }
00228
00229
00234 function DoDivision($x,$y)
00235 {
00236 $offset = 1;
00237 if ($this->data_type == 'data-data') {
00238 $offset++;
00239 } elseif ($this->data_type != 'text-data') {
00240 $this->DrawError('wrong data type!!');
00241 return FALSE;
00242 }
00243
00244 $x += $offset; $y += $offset;
00245 reset($this->data);
00246 while (list($key, $val) = each($this->data)) {
00247 if ($this->data[$key][$y] == 0) {
00248 $this->data[$key][$x] = 0;
00249 } else {
00250 $this->data[$key][$x] /= $this->data[$key][$y];
00251 }
00252 }
00253
00254 $this->DoRemoveDataSet($y-$offset);
00255 }
00256
00257 }
00258 ?>