[LON-CAPA-cvs] cvs: loncom /interface loncommon.pm
matthew
lon-capa-cvs@mail.lon-capa.org
Wed, 29 Oct 2003 15:21:10 -0000
matthew Wed Oct 29 10:21:10 2003 EDT
Modified files:
/loncom/interface loncommon.pm
Log:
DrawBarGraph: moved checking on maximum y-value to be prior to when it is
stored away, instead of checking it afterwards. Made passing of maximum
y value conform to new version of graph.png.
DrawXYGraph: Complete reimplementation.
DrawXYYGraph: Implemented.
Index: loncom/interface/loncommon.pm
diff -u loncom/interface/loncommon.pm:1.136 loncom/interface/loncommon.pm:1.137
--- loncom/interface/loncommon.pm:1.136 Mon Oct 27 16:21:08 2003
+++ loncom/interface/loncommon.pm Wed Oct 29 10:21:10 2003
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# a pile of common routines
#
-# $Id: loncommon.pm,v 1.136 2003/10/27 21:21:08 matthew Exp $
+# $Id: loncommon.pm,v 1.137 2003/10/29 15:21:10 matthew Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -2741,13 +2741,18 @@
push (@Labels,$i+1);
}
#
+ $Max = 1 if ($Max < 1);
+ if ( int($Max) < $Max ) {
+ $Max++;
+ $Max = int($Max);
+ }
$Title = '' if (! defined($Title));
$xlabel = '' if (! defined($xlabel));
$ylabel = '' if (! defined($ylabel));
$ValuesHash{$id.'.title'} = &Apache::lonnet::escape($Title);
$ValuesHash{$id.'.xlabel'} = &Apache::lonnet::escape($xlabel);
$ValuesHash{$id.'.ylabel'} = &Apache::lonnet::escape($ylabel);
- $ValuesHash{$id.'.Max'} = $Max;
+ $ValuesHash{$id.'.y_max_value'} = $Max;
$ValuesHash{$id.'.NumBars'} = $NumBars;
$ValuesHash{$id.'.NumSets'} = $NumSets;
$ValuesHash{$id.'.PlotType'} = 'bar';
@@ -2758,16 +2763,65 @@
$ValuesHash{$id.'.bar_width'} = $bar_width;
$ValuesHash{$id.'.labels'} = join(',',@Labels);
#
- $Max = 1 if ($Max < 1);
- if ( int($Max) < $Max ) {
- $Max++;
- $Max = int($Max);
+ &Apache::lonnet::appenv(%ValuesHash);
+ return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
+}
+
+############################################################
+############################################################
+
+=pod
+
+=item DrawXYGraph
+
+=cut
+
+############################################################
+############################################################
+sub DrawXYGraph {
+ my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
+ #
+ # Create the identifier for the graph
+ my $identifier = &get_cgi_id();
+ my $id = 'cgi.'.$identifier;
+ #
+ $Title = '' if (! defined($Title));
+ $xlabel = '' if (! defined($xlabel));
+ $ylabel = '' if (! defined($ylabel));
+ my %ValuesHash =
+ (
+ $id.'.title' => &Apache::lonnet::escape($Title),
+ $id.'.xlabel' => &Apache::lonnet::escape($xlabel),
+ $id.'.ylabel' => &Apache::lonnet::escape($ylabel),
+ $id.'.y_max_value'=> $Max,
+ $id.'.labels' => join(',',@$Xlabels),
+ $id.'.PlotType' => 'XY',
+ $id.'.NumSets' => 1,
+ );
+ #
+ if (defined($colors) && ref($colors) eq 'ARRAY') {
+ $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
+ }
+ #
+ if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
+ return '';
+ }
+ my $NumSets=1;
+ foreach my $array ($Ydata){
+ next if (! ref($array));
+ $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
+ }
+ #
+ # Deal with other parameters
+ while (my ($key,$value) = each(%Values)) {
+ $ValuesHash{$id.'.'.$key} = $value;
}
#
&Apache::lonnet::appenv(%ValuesHash);
return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
}
+
############################################################
############################################################
@@ -2779,8 +2833,9 @@
############################################################
############################################################
-sub DrawXYGraph {
- my ($Title,$xlabel,$ylabel,$Max,$Xlabels,$Ydata,%Values)=@_;
+sub DrawXYYGraph {
+ my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
+ $Ydata2,$Min2,$Max2,%Values)=@_;
#
# Create the identifier for the graph
my $identifier = &get_cgi_id();
@@ -2794,19 +2849,33 @@
$id.'.title' => &Apache::lonnet::escape($Title),
$id.'.xlabel' => &Apache::lonnet::escape($xlabel),
$id.'.ylabel' => &Apache::lonnet::escape($ylabel),
- $id.'.Max' => $Max,
$id.'.labels' => join(',',@$Xlabels),
$id.'.PlotType' => 'XY',
$id.'.NumSets' => 2,
+ $id.'.two_axes' => 1,
+ $id.'.y1_max_value' => $Max1,
+ $id.'.y1_min_value' => $Min1,
+ $id.'.y2_max_value' => $Max2,
+ $id.'.y2_min_value' => $Min2,
);
#
- if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
+ if (defined($colors) && ref($colors) eq 'ARRAY') {
+ $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
+ }
+ #
+ if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
+ ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
return '';
}
my $NumSets=1;
- foreach my $array ($Ydata){
+ foreach my $array ($Ydata1,$Ydata2){
next if (! ref($array));
$ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
+ }
+ #
+ # Deal with other parameters
+ while (my ($key,$value) = each(%Values)) {
+ $ValuesHash{$id.'.'.$key} = $value;
}
#
&Apache::lonnet::appenv(%ValuesHash);