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

1.1       minaeibi    1: #!/usr/bin/perl
                      2: #
1.7     ! minaeibi    3: # $Id: graph.gif,v 1.6 2002/01/22 13:49:03 minaeibi Exp $
1.5       minaeibi    4: #
                      5: # Copyright Michigan State University Board of Trustees
                      6: #
                      7: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
                      8: #
                      9: # LON-CAPA is free software; you can redistribute it and/or modify
                     10: # it under the terms of the GNU General Public License as published by
                     11: # the Free Software Foundation; either version 2 of the License, or
                     12: # (at your option) any later version.
                     13: #
                     14: # LON-CAPA is distributed in the hope that it will be useful,
                     15: # but WITHOUT ANY WARRANTY; without even the implied warranty of
                     16: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
                     17: # GNU General Public License for more details.
                     18: #
                     19: # You should have received a copy of the GNU General Public License
                     20: # along with LON-CAPA; if not, write to the Free Software
                     21: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
                     22: #
                     23: # /home/httpd/cgi-bin/graph.gif
                     24: #
                     25: # http://www.lon-capa.org/
                     26: #
1.1       minaeibi   27: # The LearningOnline Network with CAPA
                     28: # Behrouz Minaei
1.5       minaeibi   29: # YEAR=2001
                     30: # 9/13/2001, 9/25/2001, 10/6/2001, 10/9/2001, 12/25/2001
1.1       minaeibi   31: #
                     32: # A CGI script that dynamically outputs a graphical chart for lonstatistics.
1.5       minaeibi   33: # 
                     34: #### 
1.1       minaeibi   35: 
                     36: use strict;
1.3       minaeibi   37: use GD::Graph::bars3d;
1.1       minaeibi   38: use GD::Graph::colour;
                     39: use GD::Graph::Data;
                     40: 
1.4       matthew    41: $|=1;   # Autoflush after each print/write
1.1       minaeibi   42: my ($cid, $Tag, $Max, $PNo, $data) = split(/&/,$ENV{'QUERY_STRING'});
                     43: 
                     44: my @data1=split(/\,/,$data);
                     45:    
                     46: my @xlabels;
                     47: for (my $nIdx=0; $nIdx<$PNo; $nIdx++ ) {
                     48:     $xlabels[$nIdx]=$nIdx+1;
                     49: } 
                     50: my @data =(\@xlabels,\@data1);
                     51: 
                     52: my $Range;
                     53: if ( $PNo > 10 ) {$Range = 30*$PNo;}
                     54: else { $Range = 300+30*$PNo; }
                     55: 
1.7     ! minaeibi   56: $Max += (10 - $Max % 10);
1.1       minaeibi   57: 
1.3       minaeibi   58: my $MyGraph = GD::Graph::bars3d->new($Range, 400);
1.1       minaeibi   59: 
                     60: $MyGraph->set( 
                     61:     x_label         => 'Problems #',
                     62:     y_label         => $Tag,
                     63:     title           => 'LON-CAPA Graphical Chart, Course: '.$cid,
                     64:     y_max_value     => $Max,
                     65:     y_tick_number   => 10,
                     66:     y_label_skip    => 1,
                     67:     x_label_skip    => 2,
                     68:     
                     69:     # colors
1.3       minaeibi   70:     dclrs           => [ qw( green lblue lyellow lpurple cyan lorange)],
1.1       minaeibi   71:     
                     72:     # shadows
                     73:     bar_spacing     => 4,
                     74:     shadow_depth    => 1,
                     75:     shadowclr       => 'dred',
                     76: 
                     77:     transparent     => 0,
                     78: ) or warn $MyGraph->error; 
                     79: 
                     80: # Tell the server we are sending a gif graphic
                     81: print <<END;
                     82: Content-type: image/gif
                     83: 
                     84: END
                     85: 
                     86: my $BinaryData=$MyGraph->plot(\@data)->png;
                     87: undef $MyGraph;
                     88: binmode(STDOUT);
1.2       minaeibi   89: open IMG,"|pngtopnm|ppmtogif 2>/dev/null"; # convert into a gif image
1.1       minaeibi   90: print IMG $BinaryData; # output image
                     91: $|=1; # be sure to flush before closing
                     92: close IMG;
1.3       minaeibi   93: 

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