188
186
if ($width < $this->min_width) $width = $this->min_width;
189
187
if ($height < $this->min_height) $height = $this->min_height;
189
$length = $this->ivl->GetWindowSize();
192
191
$graph = new Graph($width, $height);
193
$graph->SetScale('datlin');
192
if ($length < $GRAPH_SUBSECOND_THRESHOLD)
193
$graph->SetScale('linlin');
195
$graph->SetScale('datlin');
194
196
$graph->xaxis->SetPos('min');
195
197
$graph->xaxis->SetLabelAngle(90);
196
198
$graph->xaxis->title->SetFont(FF_ARIAL, FS_BOLD);
197
199
$graph->yaxis->title->SetFont(FF_ARIAL, FS_BOLD);
198
$graph->yaxis->SetTitle("$this->math_func");
200
$graph->xaxis->SetTextLabelInterval(1);
200
202
$ydata = array_values($data);
201
203
$xdata = array_keys($data);
203
$max_val = max($ydata);
204
$yaxis_margin = strlen("$max_val") * 5;
205
$graph->img->SetMargin(20 + $yaxis_margin, 10, 10, 60);
206
$graph->yaxis->SetTitleMargin($yaxis_margin);
205
$graph->img->SetMargin(60, 10, 15, 60);
206
$graph->title->Set("$this->math_func");
208
$length = dsMathPreciseSubstract($xdata[sizeof($xdata) - 1], $xdata[0]);
209
208
if ($length > 315360000) { // 10 years
210
209
$graph->xaxis->scale->SetDateFormat('Y');
211
$graph->xaxis->SetTextLabelInterval(1);
212
210
$graph->xaxis->scale->ticks->Set($this->GetTicks($width, $length, 315360000), 315360000);
213
211
} elseif ($length > 31104000) { // 1 year
214
212
$graph->xaxis->scale->SetDateFormat('M, Y');
215
$graph->xaxis->SetTextLabelInterval(2);
216
$graph->xaxis->scale->ticks->Set($this->GetTicks($width, $length, 31104000), 3104000);
213
$graph->xaxis->scale->ticks->Set($this->GetTicks($width, $length, 3104000), 3104000);
217
214
} elseif ($length > 1036800) { // 12 days
218
215
$graph->xaxis->scale->SetDateFormat('M d');
219
$graph->xaxis->SetTextLabelInterval(3);
220
$graph->xaxis->scale->ticks->Set($this->GetTicks($width, $length, 1036800), 3600*24);
216
$graph->xaxis->scale->ticks->Set($this->GetTicks($width, $length, 3600 * 24), 3600 * 24);
221
217
} elseif ($length > 86400) { // 1 day
222
218
$graph->xaxis->scale->SetDateFormat('M d, H:i');
223
$graph->xaxis->SetTextLabelInterval(4);
224
$graph->xaxis->scale->ticks->Set($this->GetTicks($width, $length, 86400), 3600 * 4);
219
$graph->img->SetMargin(60, 10, 15, 100);
220
$graph->xaxis->scale->ticks->Set($this->GetTicks($width, $length, 3600 * 4), 3600 * 4);
225
221
} elseif ($length > 14400) { // 4 hours
226
222
$graph->xaxis->scale->SetDateFormat('H:i');
227
$graph->xaxis->SetTextLabelInterval(4);
228
$graph->xaxis->scale->ticks->Set($this->GetTicks($width, $length, 14400), 1800);
223
$graph->xaxis->scale->ticks->Set($this->GetTicks($width, $length, 1800), 1800);
229
224
} elseif ($length > $GRAPH_SUBSECOND_THRESHOLD) {
230
225
$graph->xaxis->scale->SetDateFormat('H:i:s');
231
$graph->xaxis->SetTextLabelInterval(1);
232
$majTicks = $this->GetTicks($width, $length, $GRAPH_SUBSECOND_THRESHOLD);
233
$graph->xaxis->scale->ticks->Set($majTicks, $majTicks/10);
226
$graph->xaxis->scale->ticks->Set($this->GetTicks($width, $length, $GRAPH_SUBSECOND_THRESHOLD), $GRAPH_SUBSECOND_THRESHOLD);
235
228
$from = $xdata[0];
236
$ifrom = floor($from);
237
if (is_float($from)) {
238
$rfrom = substr(printf("%.9F", $from - $ifrom), 2);
240
$pos = strpos($from, ".");
241
$rfrom = $pos === false ? 0 : substr($from, $pos + 1);
245
$date_title .= "." . $rfrom;
249
if ($length > $this->width / 1000) {
251
} elseif ($length > $this->width / 1000000) {
257
$reallength = floor($length * $coef);
258
$rem = ($reallength + 10) % 1000;
259
$ilength = $rem < 20 ? $reallength - ($rem - 10) : $reallength;
261
$first_num = substr($ilength, 0, 1);
262
$second_num = substr($ilength, 1, 1);
263
if ($second_num > 4) {
264
if ((++$first_num) == 10) {
265
$istep = "1" . str_repeat("0", strlen($ilength) - 1);
267
$istep = $first_num . str_repeat("0", strlen($ilength) - 2);
270
$istep = $first_num . str_repeat("0", strlen($ilength) - 2);
273
$ticks = array($istep, $istep / 4);
274
$graph->xaxis->scale->ticks->Set($ticks[0], $ticks[1]);
275
$ticks = floor(($ilength + 1) / $istep);
277
if ($width < 70) $lpt = $ticks;
278
else $lpt = ceil($ticks / ($width / 70));
280
$lpt = round($ticks / 5);
283
$graph->xaxis->SetTextLabelInterval($lpt);
284
$graph->xaxis->scale->SetDateFormat(false);
229
foreach ($xdata as &$x) $x = dsMathPreciseSubstract($x, $from);
287
232
$lineplot = new LinePlot($ydata, $xdata);
289
233
$graph->Add($lineplot);
290
234
$graph->Stroke("$TMP_PATH/$tmp_file");