function ConfigureTimeAxis(INTERVAL $iv, array &$data, array &$spec) { global $GRAPH_SUBSECOND_THRESHOLD; $from = $spec['from']; $to = $spec['to']; if ($this->set_time_axes || $spec['from'] == $spec['to']) { $spec['from'] = $iv->GetRequestWindowStart(); $spec['to'] = $iv->GetRequestWindowEnd(); } $spec['length'] = dsMathPreciseSubstract($spec['to'], $spec['from']); $from = $spec['from']; $to = $spec['to']; $length = $spec['length']; if ($length > $GRAPH_SUBSECOND_THRESHOLD) { $this->scale_start = 0; $this->scale_coef = 1; } $afrom = getdate($from); $ato = getdate($to); $axis_info = array('ticks' => false); if ($this->set_time_axes && $from != $to) { $axis_info['from'] = $from; $axis_info['to'] = $to; } else { // According to jpgraph.php SetScale default values $axis_info['from'] = 1; $axis_info['to'] = 1; } if ($length > 315360000) { // 10 years $date_format = 'Y'; $label_interval = 1; $date_title = ""; } elseif ($length > 31104000) { // 1 year if ($afrom['year'] == $ato['year']) { $date_format = 'M'; $label_interval = 2; $date_title = $afrom['year']; } else { $date_format = 'M, Y'; $label_interval = 2; $date_title = $afrom['year'] . " - " . $ato['year']; } } elseif ($length > 1036800) { // 12 days $date_format = 'M d'; $label_interval = 3; if ($afrom['year'] == $ato['year']) { if ($afrom['mon'] == $ato['mon']) { $date_title = $afrom['month'] . ", " . $afrom['year']; } else { $date_title = $afrom['year']; } } else { $date_title = $afrom['year'] . " - " . $ato['year']; } } elseif ($length > 86400) { // 1 day $date_format = 'M d, H:i'; $label_interval = 4; if ($afrom['year'] == $ato['year']) { if ($afrom['mon'] == $ato['mon']) { $date_title = $afrom['month'] . ", " . $afrom['year']; } else { $date_title = $afrom['year']; } } else { $date_title = $afrom['year'] . " - " . $ato['year']; } } elseif ($length > 14400) { // 4 hours $date_format = 'H:i'; $label_interval = 2; if ($afrom['year'] == $ato['year']) { if ($afrom['mon'] == $ato['mon']) { if ($afrom['mday'] == $ato['mday']) { $date_title = $afrom['month'] . " " . $afrom['mday'] . ", " . $afrom['year']; } else { $date_title = $afrom['month'] . " " . $afrom['mday'] . " - " . $ato['mday'] . ", " . $afrom['year']; } } else { $date_title = date("M", $from) . " " . $afrom['mday'] . " - " . date("M", $to) . " " . $ato['mday'] . ", " . $afrom['year']; } } else { $date_title = date("M j, Y", $from) . " - " . date("M j, Y", $to); } } else { if ($length > $GRAPH_SUBSECOND_THRESHOLD) { $date_format = 'H:i:s'; $label_interval = 4; if ($afrom['year'] == $ato['year']) { if ($afrom['mon'] == $ato['mon']) { if ($afrom['mday'] == $ato['mday']) { $date_title = $afrom['month'] . " " . $afrom['mday'] . ", " . $afrom['year']; } else { $date_title = $afrom['month'] . " " . $afrom['mday'] . " - " . $ato['mday'] . ", " . $afrom['year']; } } else { $date_title = date("M", $from) . " " . $afrom['mday'] . " - " . date("M", $to) . " " . $ato['mday'] . ", " . $afrom['year']; } } else { $date_title = date("M j, Y", $from) . " - " . date("M j, Y", $to); } } else { $ifrom = floor($from); if (is_float($from)) { $rfrom = substr(printf("%.9F", $from - $ifrom), 2); } else { $pos = strpos($from, "."); if ($pos === false) { $rfrom = 0; } else { $rfrom = substr($from, $pos + 1); } } $date_title = date("M j, Y H:i:s", $ifrom); if ($rfrom) { $date_title .= "." . $rfrom; $rfrom = "0.{$rfrom}"; } if ($length > $this->width / 1000) { $coef = 1000; $suffix = "ms"; } elseif ($length > $this->width / 1000000) { $coef = 1000000; $suffix = "us"; } else { $coef = 1000000000; $suffix = "ns"; } $reallength = floor($length * $coef); $rem = ($reallength + 10) % 1000; if ($rem < 20) { $ilength = $reallength - ($rem - 10); } else { $ilength = $reallength; } $date_title .= " + " . $ilength . $suffix; $first_num = substr($ilength, 0, 1); $second_num = substr($ilength, 1, 1); if ($second_num > 4) { if (++$first_num == 10) { $istep = "1" . str_repeat("0", strlen($ilength) - 1); } else { $istep = $first_num . str_repeat("0", strlen($ilength) - 2); } } else { $istep = $first_num . str_repeat("0", strlen($ilength) - 2); } $axis_info['from'] = 0; $axis_info['to'] = $reallength; // + 1; $axis_info['ticks'] = array($istep, $istep / 4); $ticks = floor(($ilength + 1) / $istep); if ($this->width < 350) { if ($this->width < 70) { $lpt = $ticks; } else { $lpt = ceil($ticks / ($this->width / 70)); } } else { $lpt = round($ticks / 5); } $date_format = false; $label_interval = $lpt; // Replacing timings with offsets from interval begining (in ns/us/ms) foreach ($data as &$gdate) { foreach ($gdate['time'] as &$t) { strstr($t, "."); $it = floor($t); $pos = strpos($t, "."); if ($pos === false) { $rt = 0; } else { $rt = "0." . substr($t, $pos + 1); } $t = ($it - $ifrom) * $coef + floor(($rt - $rfrom) * $coef); } } $this->scale_start = $from; $this->scale_coef = $coef; } } $axis_info['date_title'] = $date_title; $axis_info['date_format'] = $date_format; $axis_info['label_interval'] = $label_interval; return $axis_info; }