[LON-CAPA-cvs] cvs: loncom /cgi graph.png
matthew
lon-capa-cvs@mail.lon-capa.org
Wed, 26 Mar 2003 21:52:37 -0000
matthew Wed Mar 26 16:52:37 2003 EDT
Modified files:
/loncom/cgi graph.png
Log:
Added &unescape to unescape the title, xlabel, and ylabel.
Renamed $Range1 and $Range2 to $width and $height.
New settings on plots:
x_label_position = 0.5 center the label (sort of) instead of
having the label be on the right
x_tick_offset Gives control over where it starts counting
So now we count 5,10,15,... instead of
1,6,11,....
Index: loncom/cgi/graph.png
diff -u loncom/cgi/graph.png:1.20 loncom/cgi/graph.png:1.21
--- loncom/cgi/graph.png:1.20 Mon Jan 13 12:41:45 2003
+++ loncom/cgi/graph.png Wed Mar 26 16:52:37 2003
@@ -1,6 +1,6 @@
#!/usr/bin/perl
#
-# $Id: graph.png,v 1.20 2003/01/13 17:41:45 minaeibi Exp $
+# $Id: graph.png,v 1.21 2003/03/26 21:52:37 matthew Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -41,8 +41,17 @@
use GD::Graph::colour;
use GD::Graph::Data;
+sub unescape {
+ my $str=shift;
+ $str =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
+ return $str;
+}
+
$|=1; # Autoflush after each print/write
my ($Titr,$xlab,$ylab,$Max,$PNo,$data1,$data2)=split(/&/,$ENV{'QUERY_STRING'});
+$Titr = &unescape($Titr);
+$xlab = &unescape($xlab);
+$ylab = &unescape($ylab);
my @data11=split(/\,/,$data1);
my @data12=split(/\,/,$data2);
@@ -67,25 +76,30 @@
my @data =(\@xlabels,\@data11,\@data12);
-my $Range1;
-my $Range2 = 200;
+my $width;
+my $height = 200;
if ($xlab=~/^Concepts$/){
- $Range1=270;
-} elsif ($xlab=~/^Problem_number$/){
- $Range1=450;
+ $width=270;
+} elsif ($xlab=~/^Problem\snumber$/){
+ $width=450;
} else {
- $Range1=($PNo==100) ? 800 : (120+$PNo*10);
+ $width=($PNo==100) ? 800 : (120+$PNo*10);
$skip_x=5;
$bar_space=1;
}
+my $x_tick_offset = 0;
+if ($skip_x > 1) {
+ $x_tick_offset = $skip_x - 1;
+}
-my $MyGraph = GD::Graph::bars->new($Range1,$Range2);
+my $MyGraph = GD::Graph::bars->new($width,$height);
$MyGraph->set(
x_label => $xlab,
y_label => $ylab,
+ x_label_position => 0.5,
long_ticks => 1,
tick_length => 0,
x_ticks => 0,
@@ -94,6 +108,7 @@
# y_tick_number => $ytic,
y_label_skip => 5,
x_label_skip => $skip_x,
+ x_tick_offset => $x_tick_offset,
dclrs => [ qw( lgreen dgreen lyellow lpurple cyan lorange)],