3
require_once($ADEI_ROOTDIR . "/classes/draw.php");
5
abstract class BASETimeSeriesView extends VIEW {
6
var $axis_label_font_size = 8;
7
var $axis_title_font_size = 8;
8
var $axis_title_symbol_width = 8;
9
var $axis_title_height = 20;
10
var $x_axis_margin_correction = 10;
13
function __construct(REQUEST $req = NULL, $options) {
14
parent::__construct($req, $options);
17
function GetTimeAxisLabelsWidth($format) {
18
global $GRAPH_MARGINS;
20
// $bottom_margin_threshold = $length > 86400 && $length < 1036800 ? 70 : 40;
21
if ($format['time_format']) {
22
$formatted = date($format['time_format']);
23
$symbols = strlen($formatted);
24
$ret = $this->axis_title_symbol_width * $symbols;
26
$ret = $GRAPH_MARGINS['axis'] - $this->axis_title_height;
31
function GetYAxisLabelsWidth($format) {
32
global $GRAPH_MARGINS;
34
return $GRAPH_MARGINS['axis'] - $this->axis_title_height;
38
private function GetTimeAxisMajorTickStep($length, $width, $min_tick) {
39
$n_ticks = $width / 40;
40
if (!$n_ticks) $n_ticks = 1;
41
$tick_step = $length / $n_ticks;
42
return 2 * $min_tick * ceil($tick_step / $min_tick / 2);
45
function GetTimeAxisFormat(INTERVAL $ivl, $width = 0) {
46
global $GRAPH_SUBSECOND_THRESHOLD;
49
$min_ticks = 0; $maj_ticks = 0;
51
$length = $ivl->GetWindowSize();
53
if ($length > 315360000) { // 10 years
55
$min_ticks = 315360000;
56
} elseif ($length > 31104000) { // 1 year
57
$time_format = 'M, Y';
59
} elseif ($length > 1036800) { // 12 days
61
$min_ticks = 3600 * 24;
62
} elseif ($length > 86400) { // 1 day
63
$time_format = 'M d, H:i';
64
$min_ticks = 3600 * 4;
65
} elseif ($length > 14400) { // 4 hours
68
} elseif ($length > 1800) { // 30 min
71
} elseif ($length > 600) { // 5 min
74
} elseif ($length > $GRAPH_SUBSECOND_THRESHOLD) {
75
$time_format = 'H:i:s';
76
$min_ticks = $GRAPH_SUBSECOND_THRESHOLD;
78
/* We need to adjust data in the VIEW code, like this:
80
foreach ($xdata as &$x) $x = dsMathPreciseSubstract($x, $from);*/
83
if (($width)&&($min_ticks)) {
84
$maj_ticks = $this->GetTimeAxisMajorTickStep($length, $width, $min_ticks);
88
'time_format' => $time_format,
89
'minor_tick_step' => $min_ticks,
90
'major_tick_step' => $maj_ticks
94
function ConfigureTimeAxis(Graph $graph, INTERVAL $ivl, $width) {
95
global $GRAPH_SUBSECOND_THRESHOLD;
97
$format = $this->GetTimeAxisFormat($ivl, $width);
98
if ($format['time_format']) {
99
$graph->SetScale('datlin', 0, 0, $this->ivl->GetWindowStart(), $this->ivl->GetWindowEnd());
100
$graph->xaxis->scale->SetDateFormat($format['time_format']);
102
$graph->SetScale('linlin', 0, 0, 0, $this->ivl->GetWindowSize());
103
$graph->xaxis->SetLabelFormatCallback(array(new DRAW_JPGraphAxisHolder(NULL, NULL, $graph->xaxis), 'YLabelFormat'));
106
if ($format['major_tick_step'])
107
$graph->xaxis->scale->ticks->Set($format['major_tick_step'], $format['minor_tick_step']);
109
$graph->xaxis->SetPos('min');
110
$graph->xaxis->SetLabelAngle(90);
111
$graph->xaxis->SetTextLabelInterval(1);
112
$graph->xaxis->SetFont(FF_ARIAL, FS_NORMAL, $this->axis_label_font_size);
113
$graph->xaxis->title->SetFont(FF_ARIAL, FS_BOLD, $this->axis_title_font_size);
115
$format['labels_width'] = $this->GetTimeAxisLabelsWidth($format);
119
function GetYAxisFormat(array $minmax = NULL, $height = 0) {
123
function ConfigureYAxis(Graph $graph, Axis $axis, array $minmax = NULL, $height = 0) {
124
$axis->SetLabelFormatCallback(array(new DRAW_JPGraphAxisHolder(NULL, NULL, $axis), 'YLabelFormat'));
126
$axis->SetFont(FF_ARIAL, FS_NORMAL, $this->axis_label_font_size);
127
$axis->title->SetFont(FF_ARIAL, FS_BOLD, $this->axis_title_font_size);
129
$format = $this->GetYAxisFormat($minmax, $height);
130
$format['labels_width'] = $this->GetYAxisLabelsWidth($format);
134
function ConfigureXAxisTitle(Graph $graph, $label, $position = 0) {
135
$graph->xaxis->SetTitle("$label");
138
$graph->xaxis->SetTitleMargin($position - $this->x_axis_margin_correction);
139
return $position + $this->axis_title_height;// + $this->x_axis_margin_correction;
145
function ConfigureYAxisTitle(Graph $graph, Axis $axis, $label, $position = 0) {
146
$axis->SetTitle("$label");
149
$axis->SetTitleMargin($position);
150
return $position + $this->axis_title_height;
b'\\ No newline at end of file'