5 |
use Data::Dumper; |
use Data::Dumper; |
6 |
use Date::Parse; |
use Date::Parse; |
7 |
use CGI qw/:standard/; |
use CGI qw/:standard/; |
8 |
|
use CGI::Carp qw(fatalsToBrowser); |
9 |
use POSIX qw(strftime); |
use POSIX qw(strftime); |
10 |
|
|
11 |
my $debug = 0; |
my $debug = 0; |
112 |
return "<a href=\"".$q->url(-relative=>1)."?from_t=${f}&to_t=${t}\">$ch</a>"; |
return "<a href=\"".$q->url(-relative=>1)."?from_t=${f}&to_t=${t}\">$ch</a>"; |
113 |
} |
} |
114 |
|
|
115 |
print "<table>"; |
print "<table cellspacing=0 cellpadding=0>"; |
116 |
print "<tr bgcolor=#e0e0e0><td>Specification</td><td align=left>"; |
print "<tr bgcolor=#e0e0e0><td>Specification</td><td align=left>"; |
117 |
print mknav(($from_t-$int_t),$to_t,'<small><<</small>'),$from; |
print mknav(($from_t-$int_t),$to_t,'<small><<</small>'),$from; |
118 |
print mknav(($from_t+$int_t),$to_t,'<small>>></small>') if ($from_t+$int_t < $to_t); |
print mknav(($from_t+$int_t),$to_t,'<small>>></small>') if ($from_t+$int_t < $to_t); |
120 |
print mknav($from_t,($to_t-$int_t),'<small><<</small>') if ($to_t-$int_t > $from_t); |
print mknav($from_t,($to_t-$int_t),'<small><<</small>') if ($to_t-$int_t > $from_t); |
121 |
print $to,mknav($from_t,($to_t+$int_t),'<small>>></small>'),"</td></tr>\n"; |
print $to,mknav($from_t,($to_t+$int_t),'<small>>></small>'),"</td></tr>\n"; |
122 |
|
|
123 |
my $fix_d = 0; # used to fix graph len |
# draw hour grid |
124 |
|
sub hour_grid { |
125 |
|
print "<tr><td align=right><small>hour grid</small></td><td colspan=2>"; |
126 |
|
my @c = ("255,255,128","255,192,128"); |
127 |
|
my $hr=strftime("%H",localtime ($from_t)); |
128 |
|
print color_bar(3600 - $from_t % 3600,$c[0],sprintf("%02d",$hr++ % 24)); |
129 |
|
for (my $i=1; $i<int(($to_t-$from_t)/3600); $i++) { |
130 |
|
print color_bar(3600,$c[1],sprintf("%02d",$hr++ % 24)); |
131 |
|
push @c, shift @c; |
132 |
|
} |
133 |
|
print color_bar($from_t % 3600,$c[1],sprintf("%02d",$hr % 24)); |
134 |
|
print "</td></tr>\n"; |
135 |
|
} |
136 |
|
|
137 |
|
hour_grid(); |
138 |
|
|
139 |
|
my $fix_d = 0; # used to fix graph len (in pixels) |
140 |
|
my $fix_s = 0; # used to collect round errors of size |
141 |
|
|
142 |
sub bar { |
sub bar { |
143 |
my $l = shift @_; # lenght of event utime |
my $l = shift @_; |
144 |
my $status = shift @_ || undef; # what to draw |
my $status = shift @_; |
145 |
|
my $alt = shift @_; |
146 |
|
|
147 |
|
my $col; |
148 |
|
|
149 |
|
if ($status) { |
150 |
|
if ($cols{$status}) { |
151 |
|
$col .= $cols{$status}; |
152 |
|
} else { |
153 |
|
$col .= "0,0,0"; # unknown status, black |
154 |
|
} |
155 |
|
$count{$status}++; |
156 |
|
} else { |
157 |
|
# $col .= '240,240,240'; |
158 |
|
$col .= '220,220,220'; |
159 |
|
} |
160 |
|
return color_bar($l,$col,$alt); |
161 |
|
} |
162 |
|
|
163 |
|
sub color_bar { |
164 |
|
my $l = shift @_; # lenght of event utime |
165 |
|
my $col = shift @_ || '240,240,240'; # default color (filler) |
166 |
my $alt = shift @_ || undef; |
my $alt = shift @_ || undef; |
167 |
|
|
168 |
my $size = int($l / ($len_t / $width)); |
my $size = $l / ($len_t / $width); |
169 |
if ($size < $min_l) { |
$fix_s += $size - int($size); |
170 |
|
$size=int($size); |
171 |
|
if ($fix_s > 1) { |
172 |
|
$fix_s -= 1; |
173 |
|
$size++; |
174 |
|
} |
175 |
|
|
176 |
|
if ($alt && $size < $min_l) { |
177 |
$fix_d += ($min_l - $size); |
$fix_d += ($min_l - $size); |
178 |
print STDERR "fix_d: $fix_d\n" if ($debug); |
print STDERR "fix_d: $fix_d\n" if ($debug); |
179 |
$size = $min_l; |
$size = $min_l; |
184 |
print STDERR "fix_d: $fix_d\n" if ($debug); |
print STDERR "fix_d: $fix_d\n" if ($debug); |
185 |
} |
} |
186 |
|
|
187 |
print STDERR "bar[$status] len:$l s scale:",($len_t/$width)," size:$size px<br> alt:$alt\n" if ($debug); |
print STDERR "bar[$col] len:$l s scale:",($len_t/$width)," size:$size px<br> alt:$alt\n" if ($debug); |
|
|
|
|
my $html = "<img src=\"".$q->url(-relative=>1)."?pic="; |
|
188 |
|
|
189 |
if ($status) { |
my $html = "<img src=\"".$q->url(-relative=>1)."?pic=$col\" width=\"$size\" height=\"$height\""; |
|
if ($cols{$status}) { |
|
|
$html .= $cols{$status}; |
|
|
} else { |
|
|
$html .= "0,0,0"; # unknown status, black |
|
|
} |
|
|
$count{$status}++; |
|
|
} else { |
|
|
# $html .= '240,240,240'; |
|
|
$html .= '220,220,220'; |
|
|
} |
|
190 |
|
|
|
$html .= "\" width=\"$size\" height=\"$height\""; |
|
191 |
if ($use_js && $alt) { |
if ($use_js && $alt) { |
192 |
$html .= " onmouseover=\"T('$alt')\" onmouseout=\"T()\""; |
$html .= " onmouseover=\"T('$alt')\" onmouseout=\"T()\""; |
193 |
} elsif ($alt) { |
} elsif ($alt) { |
288 |
undef $sth; |
undef $sth; |
289 |
$dbh->disconnect; |
$dbh->disconnect; |
290 |
|
|
291 |
print "</td></tr>\n</table>"; |
print "</td></tr>\n"; |
292 |
|
hour_grid(); |
293 |
|
print "</table>"; |
294 |
|
|
295 |
|
|
296 |
# label and usage |
# label and usage |