--- loncom/interface/loncommon.pm 2003/10/27 21:21:08 1.136 +++ loncom/interface/loncommon.pm 2003/10/29 15:21:10 1.137 @@ -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 @@ sub DrawBarGraph { 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 @@ sub DrawBarGraph { $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 ''; +} + +############################################################ +############################################################ + +=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 ''; } + ############################################################ ############################################################ @@ -2779,8 +2833,9 @@ sub DrawBarGraph { ############################################################ ############################################################ -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,21 +2849,35 @@ sub DrawXYGraph { $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); return ''; }