[LON-CAPA-cvs] cvs: loncom /interface loncommon.pm
matthew
lon-capa-cvs@mail.lon-capa.org
Thu, 09 Oct 2003 22:07:08 -0000
matthew Thu Oct 9 18:07:08 2003 EDT
Modified files:
/loncom/interface loncommon.pm
Log:
Added DrawGraph, an interface to graph.png.
Index: loncom/interface/loncommon.pm
diff -u loncom/interface/loncommon.pm:1.126 loncom/interface/loncommon.pm:1.127
--- loncom/interface/loncommon.pm:1.126 Sat Oct 4 20:44:44 2003
+++ loncom/interface/loncommon.pm Thu Oct 9 18:07:08 2003
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# a pile of common routines
#
-# $Id: loncommon.pm,v 1.126 2003/10/05 00:44:44 www Exp $
+# $Id: loncommon.pm,v 1.127 2003/10/09 22:07:08 matthew Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -2658,6 +2658,60 @@
}
return undef;
}
+
+############################################################
+############################################################
+
+=pod
+
+=item DrawGraph
+
+Returns a link to cgi-bin/graph
+
+=cut
+
+############################################################
+############################################################
+sub DrawGraph {
+ my ($Title,$xlabel,$ylabel,$Max,$values1,$values2)=@_;
+ #
+ my $identifier = time.'_'.int(rand(1000));
+ if (! defined($values1) || ref($values1) ne 'ARRAY') {
+ return '';
+ }
+ #
+ $Title = '' if (! defined($Title));
+ $xlabel = '' if (! defined($xlabel));
+ $ylabel = '' if (! defined($ylabel));
+ $Title = &Apache::lonnet::escape($Title);
+ $xlabel = &Apache::lonnet::escape($xlabel);
+ $ylabel = &Apache::lonnet::escape($ylabel);
+ #
+ my $data1 = join(',', @$values1);
+ my $data2;
+ if (defined($values2)) {
+ $data2 = join(',', @$values2);
+ }
+ #
+ my $NumBars = scalar(@$values1);
+ $Max = 1 if ($Max < 1);
+ if ( int($Max) < $Max ) {
+ $Max++;
+ $Max = int($Max);
+ }
+ #
+ &Apache::lonnet::appenv($identifier.'.title' => $Title,
+ $identifier.'.xlabel' => $xlabel,
+ $identifier.'.ylabel' => $ylabel,
+ $identifier.'.Max' => $Max,
+ $identifier.'.NumBars' => $NumBars,
+ $identifier.'.data1' => $data1,
+ $identifier.'.data2' => $data2);
+ return '<IMG src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
+}
+
+############################################################
+############################################################
=pod