11 |
my $debug = 0; |
my $debug = 0; |
12 |
|
|
13 |
my $width = 600; # width of bar |
my $width = 600; # width of bar |
14 |
my $height = 12; # height of bar |
my $height = 19; # height of bar |
15 |
my $use_js = 1; # use JavaScript pop-up |
my $use_js = 1; # use JavaScript pop-up |
16 |
|
|
17 |
# status colors |
# status colors |
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); |
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 |
# draw hour grid |
# draw hour grid |
124 |
print "<tr><td align=right><small>hour grid</small></td><td colspan=2>"; |
sub hour_grid { |
125 |
my @c = ("255,255,128","255,192,128"); |
print "<tr><td align=right><small>hour grid</small></td><td colspan=2>"; |
126 |
my $hr=strftime("%H",localtime ($from_t)); |
my @c = ("255,255,128","255,192,128"); |
127 |
print color_bar(3600 - $from_t % 3600,$c[0],$hr++ % 24); |
my $hr=strftime("%H",localtime ($from_t)); |
128 |
for (my $i=1; $i<int(($to_t-$from_t)/3600); $i++) { |
my $min_l=1; |
129 |
print color_bar(3600,$c[1],sprintf("%02d",$hr++ % 24)); |
print color_bar(3600 - $from_t % 3600,$c[0],sprintf("%02d",$hr++ % 24)); |
130 |
push @c, shift @c; |
for (my $i=1; $i<int(($to_t-$from_t)/3600); $i++) { |
131 |
|
print color_bar(3600,$c[1],sprintf("%02d",$hr++ % 24)); |
132 |
|
push @c, shift @c; |
133 |
|
} |
134 |
|
print color_bar($from_t % 3600,$c[1],sprintf("%02d",$hr % 24)); |
135 |
|
print "</td></tr>\n"; |
136 |
} |
} |
|
print color_bar($from_t % 3600,$c[1],$hr % 24); |
|
|
print "</td></tr>\n"; |
|
137 |
|
|
138 |
my $fix_d = 0; # used to fix graph len |
hour_grid(); |
139 |
|
|
140 |
|
my $fix_d = 0; # used to fix graph len (in pixels) |
141 |
|
my $fix_s = 0; # used to collect round errors of size |
142 |
|
|
143 |
sub bar { |
sub bar { |
144 |
my $l = shift @_; |
my $l = shift @_; |
158 |
# $col .= '240,240,240'; |
# $col .= '240,240,240'; |
159 |
$col .= '220,220,220'; |
$col .= '220,220,220'; |
160 |
} |
} |
161 |
return color_bar($l,$col,$alt); |
return color_bar($l,$col,$alt,$min_l); |
162 |
} |
} |
163 |
|
|
164 |
sub color_bar { |
sub color_bar { |
165 |
my $l = shift @_; # lenght of event utime |
my $l = shift @_; # lenght of event utime |
166 |
my $col = shift @_ || '240,240,240'; # default color (filler) |
my $col = shift @_ || '240,240,240'; # default color (filler) |
167 |
my $alt = shift @_ || undef; |
my $alt = shift @_ || undef; |
168 |
|
my $min_l = shift @_ || 1; |
169 |
|
|
170 |
my $size = int($l / ($len_t / $width)); |
my $size = $l / ($len_t / $width); |
171 |
if ($size < $min_l) { |
$fix_s += $size - int($size); |
172 |
|
$size=int($size); |
173 |
|
# add rounding error to size |
174 |
|
if ($fix_s > 1) { |
175 |
|
my $i = $fix_s ; $i = int($i); |
176 |
|
$fix_s -= $i; |
177 |
|
$size += $i; |
178 |
|
} |
179 |
|
|
180 |
|
if ($alt && $size < $min_l) { |
181 |
$fix_d += ($min_l - $size); |
$fix_d += ($min_l - $size); |
182 |
print STDERR "fix_d: $fix_d\n" if ($debug); |
print STDERR "fix_d: $fix_d\n" if ($debug); |
183 |
$size = $min_l; |
$size = $min_l; |
229 |
} |
} |
230 |
|
|
231 |
print "</td></tr>\n" if ($curr_t != $from_t); |
print "</td></tr>\n" if ($curr_t != $from_t); |
232 |
|
($fix_s,$fix_d) = (0,0); # init fix vars for bar |
233 |
print "<tr><td>", $row->{specification},"</td><td colspan=2>"; |
print "<tr><td>", $row->{specification},"</td><td colspan=2>"; |
234 |
|
|
235 |
$curr_t = $from_t; # init timeline |
$curr_t = $from_t; # init timeline |
237 |
|
|
238 |
} |
} |
239 |
|
|
240 |
my $start_t = m_round(str2time($row->{start})); |
my $start_t = str2time($row->{start}); |
241 |
my $fin_t = m_round(str2time($row->{finish})); |
my $fin_t = str2time($row->{finish}); |
242 |
|
|
243 |
if ($start_t > $curr_t + 60) { |
# Can I squeeze here 1 pixel of time (many seconds) ? |
244 |
|
if ($start_t > $curr_t + ($len_t / $width)) { |
245 |
my $t = $start_t - $curr_t; |
my $t = $start_t - $curr_t; |
246 |
print STDERR "[middle filler $curr_t:$t]" if ($debug); |
print STDERR "[middle filler $curr_t:$t]" if ($debug); |
247 |
print bar($t); |
print bar($t); |
294 |
undef $sth; |
undef $sth; |
295 |
$dbh->disconnect; |
$dbh->disconnect; |
296 |
|
|
297 |
print "</td></tr>\n</table>"; |
print "</td></tr>\n"; |
298 |
|
hour_grid(); |
299 |
|
print "</table>"; |
300 |
|
|
301 |
|
|
302 |
# label and usage |
# label and usage |