Annotation of loncom/cgi/graph.png, revision 1.13
1.1 minaeibi 1: #!/usr/bin/perl
2: #
1.13 ! minaeibi 3: # $Id: graph.gif,v 1.11 2002/02/02 11:06:00 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.1 minaeibi 33: # A CGI script that dynamically outputs a graphical chart for lonstatistics.
1.5 minaeibi 34: #
35: ####
1.1 minaeibi 36:
37: use strict;
1.9 minaeibi 38: use GD::Graph::bars;
1.1 minaeibi 39: use GD::Graph::colour;
40: use GD::Graph::Data;
41:
1.4 matthew 42: $|=1; # Autoflush after each print/write
1.11 minaeibi 43: my ($Titr,$xlab,$ylab,$Max,$PNo,$data1,$data2)=split(/&/,$ENV{'QUERY_STRING'});
44:
45: my @data11=split(/\,/,$data1);
46: my @data12=split(/\,/,$data2);
1.1 minaeibi 47:
48: my @xlabels;
49: for (my $nIdx=0; $nIdx<$PNo; $nIdx++ ) {
50: $xlabels[$nIdx]=$nIdx+1;
51: }
1.11 minaeibi 52:
1.13 ! minaeibi 53:
1.11 minaeibi 54:
55: my @data =(\@xlabels,\@data11,\@data12);
1.1 minaeibi 56:
1.12 minaeibi 57: my $Range1;
58: my $Range2;
59:
1.11 minaeibi 60: if ($xlab=~/^Concepts$/){
1.12 minaeibi 61: $Range1=270;
62: $Range2=200;
63: } else {
64: if ( $PNo > 10 ) {
65: $Range1 = 20*$PNo;
66: } else {
67: $Range1 = 250+30*$PNo;
68: }
69: $Range2=200;
1.11 minaeibi 70: }
1.1 minaeibi 71:
72:
1.12 minaeibi 73: my $MyGraph = GD::Graph::bars->new($Range1,$Range2);
1.1 minaeibi 74:
75: $MyGraph->set(
1.12 minaeibi 76: # x_label => $xlab,
1.11 minaeibi 77: y_label => $ylab,
78: long_ticks => 1,
79: tick_length => 0,
80: x_ticks => 0,
81: # title => 'LON-CAPA Option Response Problem:'.$cid,
82: title => $Titr,
1.1 minaeibi 83: y_max_value => $Max,
1.11 minaeibi 84: # y_tick_number => $ytic,
85: y_label_skip => 1,
86:
1.13 ! minaeibi 87: dclrs => [ qw( lgreen dgreen lyellow lpurple cyan lorange)],
1.1 minaeibi 88:
1.11 minaeibi 89: bar_spacing => 10,
90: cumulate => 2,
91: zero_axis => 1,
92:
93: # legend_placement => 'RT',
94:
95: fgclr => 'black',
1.13 ! minaeibi 96: boxclr => 'white',
1.11 minaeibi 97: accentclr => 'dblue',
98: valuesclr => '#ffff77',
99: l_margin => 10,
100: b_margin => 10,
101: r_margin => 10,
102: t_margin => 10,
1.1 minaeibi 103:
104: transparent => 0,
105: ) or warn $MyGraph->error;
1.12 minaeibi 106: #if ($xlab=~/^Concepts$/){
107: # $MyGraph->set_legend( 'Correct Answers', 'Incorrect Answers');
108: #}
109:
110:
1.1 minaeibi 111: # Tell the server we are sending a gif graphic
112: print <<END;
113: Content-type: image/gif
114:
115: END
1.12 minaeibi 116:
117: #$MyGraph->set_y_label_font('/home/httpd/cgi-bin/cetus.ttf', 16);
118: #$MyGraph->set_x_label_font('/home/httpd/cgi-bin/cetus.ttf', 16);
119: #$MyGraph->set_y_axis_font('/home/httpd/cgi-bin/cetus.ttf', 12);
120: #$MyGraph->set_x_axis_font('/home/httpd/cgi-bin/cetus.ttf', 12);
121: #$MyGraph->set_title_font('/home/httpd/cgi-bin/cetus.ttf', 18);
122: #$MyGraph->set_legend_font('/home/httpd/cgi-bin/cetus.ttf', 10);
123: #$MyGraph->set_values_font('/home/httpd/cgi-bin/cetus.ttf', 10);
124:
1.1 minaeibi 125:
126: my $BinaryData=$MyGraph->plot(\@data)->png;
127: undef $MyGraph;
128: binmode(STDOUT);
1.2 minaeibi 129: open IMG,"|pngtopnm|ppmtogif 2>/dev/null"; # convert into a gif image
1.1 minaeibi 130: print IMG $BinaryData; # output image
131: $|=1; # be sure to flush before closing
132: close IMG;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>