/adei/trunk

To get this branch, use:
bzr branch http://darksoft.org/webbzr/adei/trunk
72 by Suren A. Chilingaryan
Merge virtual infrastructure improovements from the UI branch
1
<?php
2
114 by Suren A. Chilingaryan
Massive rewrite of DRAW (unfinished): multiple groups and axis
3
class GRAPHAxis implements Iterator {
72 by Suren A. Chilingaryan
Merge virtual infrastructure improovements from the UI branch
4
 var $aid;
5
 var $title;
6
 var $mode;
7
 var $units;
81 by Suren A. Chilingaryan
Better handling of axes in base classes, the real implementation is not here yet
8
 var $range;
114 by Suren A. Chilingaryan
Massive rewrite of DRAW (unfinished): multiple groups and axis
9
 
10
 var $apos;		// Position in stack of axis
11
 var $anum;		// Number of channels in the stack
12
 
13
 var $channels;		// registered channels data
14
 var $chaninfo;		// registered channels information
15
 var $cur;		// Current channel (for iterating)
72 by Suren A. Chilingaryan
Merge virtual infrastructure improovements from the UI branch
16
327 by Suren A. Chilingaryan
Basic support for logarithmic axes
17
 const MODE_STD = 0;
18
 const MODE_LOG = 1;
72 by Suren A. Chilingaryan
Merge virtual infrastructure improovements from the UI branch
19
 
115 by Suren A. Chilingaryan
Further drawing improvements: legend, gaps, source tree
20
 function __construct(array &$base = NULL, array &$user = NULL, $aid = false) {
114 by Suren A. Chilingaryan
Massive rewrite of DRAW (unfinished): multiple groups and axis
21
    if ((!$aid)&&($aid !== 0)) {
115 by Suren A. Chilingaryan
Further drawing improvements: legend, gaps, source tree
22
	if ((isset($user["axis"]))&&(strlen($user["axis"])>0)) $aid = $user["axis"];
110 by Suren A. Chilingaryan
Some work on virtual groups, multiple groups in autogen, filtering fixes
23
    }
24
114 by Suren A. Chilingaryan
Massive rewrite of DRAW (unfinished): multiple groups and axis
25
    if (!$aid) {
110 by Suren A. Chilingaryan
Some work on virtual groups, multiple groups in autogen, filtering fixes
26
	$this->aid = 0;
81 by Suren A. Chilingaryan
Better handling of axes in base classes, the real implementation is not here yet
27
	$aprop = "axis";
110 by Suren A. Chilingaryan
Some work on virtual groups, multiple groups in autogen, filtering fixes
28
    } else {    
29
	if (is_numeric($aid)) {
159 by Suren A. Chilingaryan
Support for axis and item tables in DBReader
30
	    $this->aid = $aid;
110 by Suren A. Chilingaryan
Some work on virtual groups, multiple groups in autogen, filtering fixes
31
	    $aprop = "axis$aid";
32
	} else {
33
	    $this->aid = $aid;
34
	    $aprop = $aid . "_axis";
35
	}
81 by Suren A. Chilingaryan
Better handling of axes in base classes, the real implementation is not here yet
36
    }
37
    
115 by Suren A. Chilingaryan
Further drawing improvements: legend, gaps, source tree
38
    $this->title = $user[$aprop . "_name"]?$user[$aprop . "_name"]:$base["axis_name"];
39
    $this->units = $user[$aprop . "_units"]?$user[$aprop . "_units"]:$base["axis_units"];
40
41
    $mode = $user[$aprop . "_mode"]?$user[$aprop . "_mode"]:$base["axis_mode"];
42
    if ($mode) {
81 by Suren A. Chilingaryan
Better handling of axes in base classes, the real implementation is not here yet
43
	if (is_numeric($mode)) $this->mode = $mode;
44
	else {
115 by Suren A. Chilingaryan
Further drawing improvements: legend, gaps, source tree
45
	    $name = "GRAPHAxis::MODE_" . strtoupper($mode);
81 by Suren A. Chilingaryan
Better handling of axes in base classes, the real implementation is not here yet
46
	    if (defined($name)) $this->mode = constant($name);
47
	    else throw new ADEIException(translate("Unknown axis mode (%s) is specified", $mode));
48
	}
49
    } else {
327 by Suren A. Chilingaryan
Basic support for logarithmic axes
50
	$this->mode = GRAPHAxis::MODE_STD;
81 by Suren A. Chilingaryan
Better handling of axes in base classes, the real implementation is not here yet
51
    }
115 by Suren A. Chilingaryan
Further drawing improvements: legend, gaps, source tree
52
53
    $range = $user[$aprop . "_range"]?$user[$aprop . "_range"]:$base["axis_range"];
145 by Suren A. Chilingaryan
Several fixes: Axes range loading, few bugs related to support dates prior to Jan 1, 1970
54
    if (($range)&&(preg_match("/(-?[^:]+):(-?[^:]+)/", $range, $m))) {
81 by Suren A. Chilingaryan
Better handling of axes in base classes, the real implementation is not here yet
55
	$this->range = array($m[1], $m[2]);
115 by Suren A. Chilingaryan
Further drawing improvements: legend, gaps, source tree
56
    } else if ((1)||($aid === false)) { /*DS*/
57
	$ivl = new INTERVAL($user);
114 by Suren A. Chilingaryan
Massive rewrite of DRAW (unfinished): multiple groups and axis
58
	if ($ivl->y_min < $ivl->y_max) {
59
	    $this->range = array($ivl->y_min, $ivl->y_max);
60
	} else {
61
	    $this->range = false;
62
	}
81 by Suren A. Chilingaryan
Better handling of axes in base classes, the real implementation is not here yet
63
    } else {
64
	$this->range = false;
65
    }
114 by Suren A. Chilingaryan
Massive rewrite of DRAW (unfinished): multiple groups and axis
66
    
67
    $this->channels = array();
68
    $this->chaninfo = array();
69
    $this->apos = false;
70
    $this->anum = false;
71
 }
72
 
73
 function SetPosition($pos, $num = false) {
74
    $this->apos = $pos;
75
    $this->anum = $num;
72 by Suren A. Chilingaryan
Merge virtual infrastructure improovements from the UI branch
76
 }
110 by Suren A. Chilingaryan
Some work on virtual groups, multiple groups in autogen, filtering fixes
77
115 by Suren A. Chilingaryan
Further drawing improvements: legend, gaps, source tree
78
 function GetPosition() {
79
    return $this->apos;
80
 }
81
110 by Suren A. Chilingaryan
Some work on virtual groups, multiple groups in autogen, filtering fixes
82
 function SetRange($min, $max) {
83
    if (($min)||($max)) {
84
	$this->range = array($min, $max);
85
    } else {
86
	$this->range = false;
87
    }
88
 }
89
 
90
 function GetID() {
91
    return $this->aid;
92
 }
93
 
94
 function GetRange() {
95
    return $this->range;
96
 }
327 by Suren A. Chilingaryan
Basic support for logarithmic axes
97
 
98
 function GetMode() {
99
    return $this->mode;
100
 }
101
 
102
 function IsLogarithmic() {
103
    return ($this->mode === GRAPHAxis::MODE_LOG);
104
 }
114 by Suren A. Chilingaryan
Massive rewrite of DRAW (unfinished): multiple groups and axis
105
106
 function GetTitle() {
107
    if ($this->title) {
108
	if ($this->units) return "{$this->title} ({$this->units})";
109
	else return $this->title;
110
    } else if ($this->units) {
111
	return $this->units;
112
    } else if ($this->aid) {
113
	if (is_numeric($this->aid)) {
114
	    return translate("axis %d", $this->aid);
115
	} else {
116
	    return $this->aid;
117
	}
118
    } else {
117 by Suren A. Chilingaryan
Multiple axis support in JavaScript, multiple fixups in source tree handling
119
	return "";
114 by Suren A. Chilingaryan
Massive rewrite of DRAW (unfinished): multiple groups and axis
120
    }
121
 }
122
  
117 by Suren A. Chilingaryan
Multiple axis support in JavaScript, multiple fixups in source tree handling
123
 function GetName() {
124
    if ($this->title) return $this->title;
125
    else if ($this->aid) return $this->aid;
126
    else return translate("default");
127
 }
128
 
114 by Suren A. Chilingaryan
Massive rewrite of DRAW (unfinished): multiple groups and axis
129
 function GetColor() {
130
    global $AXES_COLORS;
131
132
    if (sizeof($AXES_COLORS)) {
133
	$color = $AXES_COLORS[$this->apos%sizeof($AXES_COLORS)][0];
134
    } else {
135
	$color = 0;
136
    }
137
        
138
    return $color;
139
 }
140
 
141
 function GetChannelColor($id) {
142
    global $AXES_COLORS;
143
    global $GRAPH_COLORS;
144
    
145
    if ((sizeof($AXES_COLORS))&&($this->anum > 1)) {
146
	$acid = $this->apos%sizeof($AXES_COLORS);
147
	$color = $AXES_COLORS[$acid][$id % sizeof($AXES_COLORS[$acid])];
148
    } else if (sizeof($GRAPH_COLORS)) {
149
	$color = $GRAPH_COLORS[$id%sizeof($GRAPH_COLORS)];
150
    } else {
151
	$color = 0;
152
    }
153
    return $color;
154
 }
155
156
 function GetChannelProperty($id, $prop, $default = false) {
157
    global $GRAPH_LINE_WEIGHT;
158
    global $GRAPH_ACCURACY_MARKS_COLOR;
159
    global $GRAPH_ACCURACY_MARKS_TYPE;
160
    global $GRAPH_ACCURACY_MARKS_SIZE;
161
437 by Suren A. Chilingaryan
More strict verification if the marks should be shown in the default mode, should handle the data isles properly
162
    if (isset($this->chaninfo[$id][$prop])) 
163
	return $this->chaninfo[$id][$prop];
164
114 by Suren A. Chilingaryan
Massive rewrite of DRAW (unfinished): multiple groups and axis
165
    switch ($prop) {
166
     case "weight":
167
        if ($GRAPH_LINE_WEIGHT) return $GRAPH_LINE_WEIGHT;
168
     break;
169
     case "mark_type":
170
	if ($GRAPH_ACCURACY_MARKS_TYPE) {
171
	    eval("\$mtype=$GRAPH_ACCURACY_MARKS_TYPE;");
172
	} else if ($default) {
173
	    return $default;
174
	} else {
175
	    $mtype = MARK_FILLEDCIRCLE;
176
	}
177
	return $mtype;
178
     break;
179
     case "mark_size":
180
        if ($GRAPH_ACCURACY_MARKS_SIZE) return $GRAPH_ACCURACY_MARKS_SIZE;
181
     break;
182
     case "mark_fill":
183
        if ((sizeof($this->channels) > 1)||($this->anum > 1)) return $this->GetChannelColor($id);
184
	else if ($GRAPH_ACCURACY_MARKS_COLOR) return $GRAPH_ACCURACY_MARKS_COLOR;
185
     break;
186
    }
187
    
188
    return $default;
189
 }
190
191
 function RegisterChannel(array &$time, array &$values, array &$iid) {
192
//    echo sizeof($time) . ", " . sizeof($values) . "\n";
193
    array_push($this->channels, array(&$time, &$values));
194
    array_push($this->chaninfo, $iid);
195
 }
196
197
 function rewind() {
198
    $this->cur = 0;
199
 }
200
201
 function valid() {
202
    return isset($this->channels[$this->cur]);
203
 }
204
 
205
 function current() {
206
    return $this->channels[$this->cur];
207
 }
208
 
209
 function key() {
210
    return $this->cur;
211
 }
212
 
213
 function next() {
214
    $this->cur++;
215
 }
216
217
 function Normalize() {
218
    /* DS: We could like to adjust (or set) range in order to prevent
219
    overdrawing of the screen */
220
 }
72 by Suren A. Chilingaryan
Merge virtual infrastructure improovements from the UI branch
221
}
222
223
/*
224
class UIAxis extends GRAPHAxis {
225
}
226
*/
227
228
?>