[LON-CAPA-cvs] cvs: loncom /interface loncommon.pm
matthew
lon-capa-cvs@mail.lon-capa.org
Wed, 15 Oct 2003 21:12:24 -0000
matthew Wed Oct 15 17:12:24 2003 EDT
Modified files:
/loncom/interface loncommon.pm
Log:
Rewrite of DrawGraph to allow user specified colors and multiple data sets.
Index: loncom/interface/loncommon.pm
diff -u loncom/interface/loncommon.pm:1.128 loncom/interface/loncommon.pm:1.129
--- loncom/interface/loncommon.pm:1.128 Mon Oct 13 18:35:05 2003
+++ loncom/interface/loncommon.pm Wed Oct 15 17:12:24 2003
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# a pile of common routines
#
-# $Id: loncommon.pm,v 1.128 2003/10/13 22:35:05 albertel Exp $
+# $Id: loncommon.pm,v 1.129 2003/10/15 21:12:24 matthew Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -2686,12 +2686,19 @@
############################################################
############################################################
sub DrawGraph {
- my ($Title,$xlabel,$ylabel,$Max,$values1,$values2)=@_;
+ my ($Title,$xlabel,$ylabel,$Max,$colors,@Values)=@_;
#
my $identifier = time.'_'.int(rand(1000));
- if (! defined($values1) || ref($values1) ne 'ARRAY') {
+ if (! @Values || ref($Values[0]) ne 'ARRAY') {
return '';
}
+ my $NumBars = scalar(@{$Values[0]});
+ my %ValuesHash;
+ my $NumSets=1;
+ foreach my $array (@Values) {
+ next if (! ref($array));
+ $ValuesHash{$identifier.'.data.'.$NumSets++} = join(',',@$array);
+ }
#
$Title = '' if (! defined($Title));
$xlabel = '' if (! defined($xlabel));
@@ -2700,13 +2707,6 @@
$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++;
@@ -2718,8 +2718,9 @@
$identifier.'.ylabel' => $ylabel,
$identifier.'.Max' => $Max,
$identifier.'.NumBars' => $NumBars,
- $identifier.'.data1' => $data1,
- $identifier.'.data2' => $data2);
+ $identifier.'.NumSets' => $NumSets,
+ $identifier.'.Colors' => join(',',@{$colors}),
+ %ValuesHash);
return '<IMG src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
}