Annotation of loncom/cgi/graph.png, revision 1.21
1.1 minaeibi 1: #!/usr/bin/perl
2: #
1.21 ! matthew 3: # $Id: graph.png,v 1.20 2003/01/13 17:41:45 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
1.9 minaeibi 30: # 9/13/01, 9/25/01, 10/6/01, 10/9/01, 12/25/01
31: # YEAR=2002
1.13 minaeibi 32: # 2/1/, 5/13, 5/15
1.17 minaeibi 33: # YEAR=2003
1.20 minaeibi 34: # 1/7/, 1/13
1.1 minaeibi 35: # A CGI script that dynamically outputs a graphical chart for lonstatistics.
1.5 minaeibi 36: #
37: ####
1.1 minaeibi 38:
39: use strict;
1.9 minaeibi 40: use GD::Graph::bars;
1.1 minaeibi 41: use GD::Graph::colour;
42: use GD::Graph::Data;
43:
1.21 ! matthew 44: sub unescape {
! 45: my $str=shift;
! 46: $str =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
! 47: return $str;
! 48: }
! 49:
1.4 matthew 50: $|=1; # Autoflush after each print/write
1.11 minaeibi 51: my ($Titr,$xlab,$ylab,$Max,$PNo,$data1,$data2)=split(/&/,$ENV{'QUERY_STRING'});
1.21 ! matthew 52: $Titr = &unescape($Titr);
! 53: $xlab = &unescape($xlab);
! 54: $ylab = &unescape($ylab);
1.11 minaeibi 55:
56: my @data11=split(/\,/,$data1);
57: my @data12=split(/\,/,$data2);
1.18 minaeibi 58: my $skip_x = 1;
59: my $bar_space=10;
1.1 minaeibi 60:
61: my @xlabels;
1.17 minaeibi 62:
1.19 minaeibi 63: if ($Titr =~ /^Percentage$/){
1.17 minaeibi 64: for (my $nIdx=0; $nIdx<$PNo; $nIdx++ ) {
1.18 minaeibi 65: $xlabels[$nIdx]=$nIdx;
1.17 minaeibi 66: }
67: @data11=();
68: @data11=split(/\,/,$data2);
1.19 minaeibi 69: @data12=();
70: $Titr = '';
1.17 minaeibi 71: } else {
72: for (my $nIdx=0; $nIdx<$PNo; $nIdx++ ) {
73: $xlabels[$nIdx]=$nIdx+1;
74: }
1.1 minaeibi 75: }
1.11 minaeibi 76:
77: my @data =(\@xlabels,\@data11,\@data12);
1.1 minaeibi 78:
1.21 ! matthew 79: my $width;
! 80: my $height = 200;
1.12 minaeibi 81:
1.11 minaeibi 82: if ($xlab=~/^Concepts$/){
1.21 ! matthew 83: $width=270;
! 84: } elsif ($xlab=~/^Problem\snumber$/){
! 85: $width=450;
1.19 minaeibi 86: } else {
1.21 ! matthew 87: $width=($PNo==100) ? 800 : (120+$PNo*10);
1.18 minaeibi 88: $skip_x=5;
89: $bar_space=1;
1.11 minaeibi 90: }
1.1 minaeibi 91:
1.21 ! matthew 92: my $x_tick_offset = 0;
! 93: if ($skip_x > 1) {
! 94: $x_tick_offset = $skip_x - 1;
! 95: }
1.1 minaeibi 96:
1.21 ! matthew 97: my $MyGraph = GD::Graph::bars->new($width,$height);
1.1 minaeibi 98:
99: $MyGraph->set(
1.14 minaeibi 100: x_label => $xlab,
1.11 minaeibi 101: y_label => $ylab,
1.21 ! matthew 102: x_label_position => 0.5,
1.11 minaeibi 103: long_ticks => 1,
104: tick_length => 0,
105: x_ticks => 0,
106: title => $Titr,
1.1 minaeibi 107: y_max_value => $Max,
1.11 minaeibi 108: # y_tick_number => $ytic,
1.18 minaeibi 109: y_label_skip => 5,
110: x_label_skip => $skip_x,
1.21 ! matthew 111: x_tick_offset => $x_tick_offset,
1.11 minaeibi 112:
1.13 minaeibi 113: dclrs => [ qw( lgreen dgreen lyellow lpurple cyan lorange)],
1.1 minaeibi 114:
1.18 minaeibi 115: bar_spacing => $bar_space,
1.11 minaeibi 116: cumulate => 2,
117: zero_axis => 1,
118:
119: # legend_placement => 'RT',
120:
121: fgclr => 'black',
1.13 minaeibi 122: boxclr => 'white',
1.11 minaeibi 123: accentclr => 'dblue',
124: valuesclr => '#ffff77',
125: l_margin => 10,
126: b_margin => 10,
127: r_margin => 10,
128: t_margin => 10,
1.1 minaeibi 129:
130: transparent => 0,
131: ) or warn $MyGraph->error;
1.14 minaeibi 132:
1.12 minaeibi 133:
1.16 albertel 134: # Tell the server we are sending a png graphic
1.1 minaeibi 135: print <<END;
1.16 albertel 136: Content-type: image/png
1.1 minaeibi 137:
138: END
139:
140: my $BinaryData=$MyGraph->plot(\@data)->png;
141: undef $MyGraph;
142: binmode(STDOUT);
1.16 albertel 143: #open IMG,"|pngtopnm|ppmtogif 2>/dev/null"; # convert into a gif image
144: #print IMG $BinaryData; # output image
145: #$|=1; # be sure to flush before closing
146: #close IMG;
147: print $BinaryData;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>