/[omni_gantt]/db2gantt.cgi
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /db2gantt.cgi

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.9 by dpavlin, Fri Sep 13 14:34:02 2002 UTC revision 1.14 by dpavlin, Fri Sep 13 23:59:38 2002 UTC
# Line 5  use DBI; Line 5  use DBI;
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;
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
# Line 74  if (param('pic')) { Line 75  if (param('pic')) {
75  }  }
76    
77  print "Content-type: text/html  print "Content-type: text/html
78    Cache-Control: max-age=60, must-revalidate
79    
80  <html>  <html>
81  <head>  <head>
82  <title>OmniBack Gantt: $from - $to</title>";  <title>OmniBack Gantt: $from - $to</title>
83    <meta HTTP-EQUIV=\"Refresh\" CONTENT=60>";
84  if ($use_js) {  if ($use_js) {
85  print '  print '
86  <script type="text/javascript" language="javascript" src="1k.js"></script>  <script type="text/javascript" language="javascript" src="1k.js"></script>
# Line 111  sub mknav { Line 114  sub mknav {
114          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>";
115  }  }
116    
117  print "<table>";  print "<table cellspacing=0 cellpadding=0>";
118  print "<tr bgcolor=#e0e0e0><td>Specification</td><td align=left>";  print "<tr bgcolor=#e0e0e0><td>Specification</td><td align=left>";
119  print mknav(($from_t-$int_t),$to_t,'<small>&lt;&lt;</small>'),$from;  print mknav(($from_t-$int_t),$to_t,'<small>&lt;&lt;</small>'),$from;
120  print mknav(($from_t+$int_t),$to_t,'<small>&gt;&gt;</small>') if ($from_t+$int_t < $to_t);  print mknav(($from_t+$int_t),$to_t,'<small>&gt;&gt;</small>') if ($from_t+$int_t < $to_t);
# Line 119  print "</td><td align=right>"; Line 122  print "</td><td align=right>";
122  print mknav($from_t,($to_t-$int_t),'<small>&lt;&lt;</small>') if ($to_t-$int_t > $from_t);  print mknav($from_t,($to_t-$int_t),'<small>&lt;&lt;</small>') if ($to_t-$int_t > $from_t);
123  print $to,mknav($from_t,($to_t+$int_t),'<small>&gt;&gt;</small>'),"</td></tr>\n";  print $to,mknav($from_t,($to_t+$int_t),'<small>&gt;&gt;</small>'),"</td></tr>\n";
124    
125  my $fix_d = 0;  # used to fix graph len  # draw hour grid
126    sub hour_grid {
127            print "<tr><td align=right><small>hour grid</small></td><td colspan=2>";
128            my @c = ("255,255,128","255,192,128");
129            my $hr=strftime("%H",localtime ($from_t));
130            my $min_l=1;
131            print color_bar(3600 - $from_t % 3600,$c[0],sprintf("%02d",$hr++ % 24));
132            for (my $i=1; $i<int(($to_t-$from_t)/3600); $i++) {
133                    print color_bar(3600,$c[1],sprintf("%02d",$hr++ % 24));
134                    push @c, shift @c;
135            }
136            print color_bar($from_t % 3600,$c[1],sprintf("%02d",$hr % 24));
137            print "</td></tr>\n";
138    }
139    
140    hour_grid();
141    
142    my $fix_d = 0;  # used to fix graph len (in pixels)
143    my $fix_s = 0;  # used to collect round errors of size
144    
145  sub bar {  sub bar {
146          my $l = shift @_;       # lenght of event utime          my $l = shift @_;
147          my $status = shift @_ || undef; # what to draw          my $status = shift @_;
148            my $alt = shift @_;
149    
150            my $col;
151    
152            if ($status) {
153                    if ($cols{$status}) {
154                            $col .= $cols{$status};
155                    } else {
156                            $col .= "0,0,0";        # unknown status, black
157                    }
158                    $count{$status}++;
159            } else {
160    #               $col .= '240,240,240';
161                    $col .= '220,220,220';
162            }
163            return color_bar($l,$col,$alt,$min_l);
164    }
165    
166    sub color_bar {
167            my $l = shift @_;                       # lenght of event utime
168            my $col = shift @_ || '240,240,240';    # default color (filler)
169          my $alt = shift @_ || undef;          my $alt = shift @_ || undef;
170            my $min_l = shift @_ || 1;
171    
172            my $size = $l / ($len_t / $width);
173            $fix_s += $size - int($size);
174            $size=int($size);
175            # add rounding error to size
176            if ($fix_s > 1) {
177                    my $i = $fix_s ; $i = int($i);
178                    $fix_s -= $i;
179                    $size += $i;
180            }
181    
182          my $size = int($l / ($len_t / $width));          if ($alt && $size < $min_l) {
         if ($size < $min_l) {  
183                  $fix_d += ($min_l - $size);                  $fix_d += ($min_l - $size);
184                  print STDERR "fix_d: $fix_d\n" if ($debug);                  print STDERR "fix_d: $fix_d\n" if ($debug);
185                  $size = $min_l;                  $size = $min_l;
# Line 138  sub bar { Line 190  sub bar {
190                  print STDERR "fix_d: $fix_d\n" if ($debug);                  print STDERR "fix_d: $fix_d\n" if ($debug);
191          }          }
192    
193          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);
194    
195          my $html = "<img src=\"".$q->url(-relative=>1)."?pic=";          my $html = "<img src=\"".$q->url(-relative=>1)."?pic=$col\" width=\"$size\" height=\"$height\"";
196    
         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';  
         }  
   
         $html .= "\" width=\"$size\" height=\"$height\"";  
197          if ($use_js && $alt) {          if ($use_js && $alt) {
198                  $html .= " onmouseover=\"T('$alt')\" onmouseout=\"T()\"";                  $html .= " onmouseover=\"T('$alt')\" onmouseout=\"T()\"";
199          } elsif ($alt) {          } elsif ($alt) {
# Line 192  while(my $row = $sth->fetchrow_hashref) Line 231  while(my $row = $sth->fetchrow_hashref)
231                  }                  }
232    
233                  print "</td></tr>\n" if ($curr_t != $from_t);                  print "</td></tr>\n" if ($curr_t != $from_t);
234                    ($fix_s,$fix_d) = (0,0); # init fix vars for bar
235                  print "<tr><td>", $row->{specification},"</td><td colspan=2>";                  print "<tr><td>", $row->{specification},"</td><td colspan=2>";
236    
237                  $curr_t = $from_t;      # init timeline                  $curr_t = $from_t;      # init timeline
# Line 199  while(my $row = $sth->fetchrow_hashref) Line 239  while(my $row = $sth->fetchrow_hashref)
239    
240          }          }
241    
242          my $start_t = m_round(str2time($row->{start}));          my $start_t = str2time($row->{start});
243          my $fin_t = m_round(str2time($row->{finish}));          my $fin_t = str2time($row->{finish});
244    
245          if ($start_t > $curr_t + 60) {          # Can I squeeze here 1 pixel of time (many seconds) ?
246            if ($start_t > $curr_t + ($len_t / $width)) {
247                  my $t = $start_t - $curr_t;                  my $t = $start_t - $curr_t;
248                  print STDERR "[middle filler $curr_t:$t]" if ($debug);                  print STDERR "[middle filler $curr_t:$t]" if ($debug);
249                  print bar($t);                  print bar($t);
250                  $curr_t = $start_t;                  $curr_t = $start_t;
251            } else {
252                    # prepend too few seconds to next event
253                    $start_t = $curr_t;
254          }          }
255    
256          my $len = $fin_t - $start_t;          my $len = $fin_t - $start_t;
# Line 255  if ($curr_t < $to_t ) { Line 299  if ($curr_t < $to_t ) {
299  undef $sth;  undef $sth;
300  $dbh->disconnect;  $dbh->disconnect;
301    
302  print "</td></tr>\n</table>";  print "</td></tr>\n";
303    hour_grid();
304    print "</table>";
305    
306    
307  # label and usage  # label and usage
# Line 271  foreach my $status (keys %count) { Line 317  foreach my $status (keys %count) {
317          # it will first evaluate bar sub (thus increasing number by one) and          # it will first evaluate bar sub (thus increasing number by one) and
318          # then display number (wrongly).          # then display number (wrongly).
319  }  }
320  print "</table>\n<p>Reload <a href=\"",$q->url(-relative=>1),"\">current</a>.</p></body></html>";  print "</table>\n<p>Reload <a href=\"",$q->url(-relative=>1),"\">current</a> or see <a href=\"db2gantt_help.html\">help</a>.</p></body></html>";
321    

Legend:
Removed from v.1.9  
changed lines
  Added in v.1.14

  ViewVC Help
Powered by ViewVC 1.1.26