Annotation of loncom/cgi/graph.png, revision 1.2

1.1       minaeibi    1: #!/usr/bin/perl
                      2: #
                      3: # The LearningOnline Network with CAPA
                      4: #
                      5: # Behrouz Minaei
                      6: # 9/13/2001, 9/25/2001
                      7: # 10/6/2001, 10,9,2001
                      8: #
                      9: # A CGI script that dynamically outputs a graphical chart for lonstatistics.
                     10: 
                     11: use strict;
                     12: use GD::Graph::bars;
                     13: use GD::Graph::colour;
                     14: use GD::Graph::Data;
                     15: 
                     16: my ($cid, $Tag, $Max, $PNo, $data) = split(/&/,$ENV{'QUERY_STRING'});
                     17: 
                     18: my @data1=split(/\,/,$data);
                     19:    
                     20: my @xlabels;
                     21: for (my $nIdx=0; $nIdx<$PNo; $nIdx++ ) {
                     22:     $xlabels[$nIdx]=$nIdx+1;
                     23: } 
                     24: my @data =(\@xlabels,\@data1);
                     25: 
                     26: my $Range;
                     27: if ( $PNo > 10 ) {$Range = 30*$PNo;}
                     28: else { $Range = 300+30*$PNo; }
                     29: 
                     30: if ( $Max < 1 ) { $Max = 1; }
                     31: elsif ( $Max < 10 ) { $Max = 10; }
                     32: elsif ( $Max < 100 ) { $Max = 100; }
                     33: 
                     34: my $MyGraph = GD::Graph::bars->new($Range, 400);
                     35: 
                     36: $MyGraph->set( 
                     37:     x_label         => 'Problems #',
                     38:     y_label         => $Tag,
                     39:     title           => 'LON-CAPA Graphical Chart, Course: '.$cid,
                     40:     y_max_value     => $Max,
                     41:     y_tick_number   => 10,
                     42:     y_label_skip    => 1,
                     43:     x_label_skip    => 2,
                     44:     
                     45:     # colors
                     46:     dclrs           => [ qw(green lblue lyellow lpurple cyan lorange)],
                     47:     
                     48:     # shadows
                     49:     bar_spacing     => 4,
                     50:     shadow_depth    => 1,
                     51:     shadowclr       => 'dred',
                     52: 
                     53:     transparent     => 0,
                     54: ) or warn $MyGraph->error; 
                     55: 
                     56: # Tell the server we are sending a gif graphic
                     57: print <<END;
                     58: Content-type: image/gif
                     59: 
                     60: END
                     61: 
                     62: my $BinaryData=$MyGraph->plot(\@data)->png;
                     63: undef $MyGraph;
                     64: binmode(STDOUT);
1.2     ! minaeibi   65: open IMG,"|pngtopnm|ppmtogif 2>/dev/null"; # convert into a gif image
1.1       minaeibi   66: print IMG $BinaryData; # output image
                     67: $|=1; # be sure to flush before closing
                     68: close IMG;

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>