--- db2gantt.cgi 2002/09/13 14:34:02 1.9 +++ db2gantt.cgi 2002/09/13 19:06:46 1.12 @@ -5,6 +5,7 @@ use Data::Dumper; use Date::Parse; use CGI qw/:standard/; +use CGI::Carp qw(fatalsToBrowser); use POSIX qw(strftime); my $debug = 0; @@ -111,7 +112,7 @@ return "url(-relative=>1)."?from_t=${f}&to_t=${t}\">$ch"; } -print ""; +print "
"; print "\n"; -my $fix_d = 0; # used to fix graph len +# draw hour grid +sub hour_grid { + print "\n"; +} + +hour_grid(); + +my $fix_d = 0; # used to fix graph len (in pixels) +my $fix_s = 0; # used to collect round errors of size sub bar { - my $l = shift @_; # lenght of event utime - my $status = shift @_ || undef; # what to draw + my $l = shift @_; + my $status = shift @_; + my $alt = shift @_; + + my $col; + + if ($status) { + if ($cols{$status}) { + $col .= $cols{$status}; + } else { + $col .= "0,0,0"; # unknown status, black + } + $count{$status}++; + } else { +# $col .= '240,240,240'; + $col .= '220,220,220'; + } + return color_bar($l,$col,$alt); +} + +sub color_bar { + my $l = shift @_; # lenght of event utime + my $col = shift @_ || '240,240,240'; # default color (filler) my $alt = shift @_ || undef; - my $size = int($l / ($len_t / $width)); - if ($size < $min_l) { + my $size = $l / ($len_t / $width); + $fix_s += $size - int($size); + $size=int($size); + if ($fix_s > 1) { + $fix_s -= 1; + $size++; + } + + if ($alt && $size < $min_l) { $fix_d += ($min_l - $size); print STDERR "fix_d: $fix_d\n" if ($debug); $size = $min_l; @@ -138,23 +184,10 @@ print STDERR "fix_d: $fix_d\n" if ($debug); } - print STDERR "bar[$status] len:$l s scale:",($len_t/$width)," size:$size px
alt:$alt\n" if ($debug); - - my $html = "url(-relative=>1)."?pic="; + print STDERR "bar[$col] len:$l s scale:",($len_t/$width)," size:$size px
alt:$alt\n" if ($debug); - if ($status) { - 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'; - } + my $html = "url(-relative=>1)."?pic=$col\" width=\"$size\" height=\"$height\""; - $html .= "\" width=\"$size\" height=\"$height\""; if ($use_js && $alt) { $html .= " onmouseover=\"T('$alt')\" onmouseout=\"T()\""; } elsif ($alt) { @@ -255,7 +288,9 @@ undef $sth; $dbh->disconnect; -print "\n
Specification"; print mknav(($from_t-$int_t),$to_t,'<<'),$from; print mknav(($from_t+$int_t),$to_t,'>>') if ($from_t+$int_t < $to_t); @@ -119,15 +120,60 @@ print mknav($from_t,($to_t-$int_t),'<<') if ($to_t-$int_t > $from_t); print $to,mknav($from_t,($to_t+$int_t),'>>'),"
hour grid"; + my @c = ("255,255,128","255,192,128"); + my $hr=strftime("%H",localtime ($from_t)); + print color_bar(3600 - $from_t % 3600,$c[0],sprintf("%02d",$hr++ % 24)); + for (my $i=1; $i
"; +print "\n"; +hour_grid(); +print ""; # label and usage