version 1.135, 2003/10/24 21:09:24
|
version 1.136, 2003/10/27 21:21:08
|
Line 2678 sub check_if_partid_hidden {
|
Line 2678 sub check_if_partid_hidden {
|
return undef; |
return undef; |
} |
} |
|
|
|
sub get_cgi_id { |
|
return (time.'_'.int(rand(1000))); |
|
} |
|
|
############################################################ |
############################################################ |
############################################################ |
############################################################ |
|
|
Line 2685 sub check_if_partid_hidden {
|
Line 2689 sub check_if_partid_hidden {
|
|
|
=item DrawBarGraph |
=item DrawBarGraph |
|
|
|
|
=cut |
=cut |
|
|
############################################################ |
############################################################ |
Line 2700 sub DrawBarGraph {
|
Line 2703 sub DrawBarGraph {
|
]; |
]; |
} |
} |
# |
# |
my $identifier = time.'_'.int(rand(1000)); |
my $identifier = &get_cgi_id(); |
|
my $id = 'cgi.'.$identifier; |
if (! @Values || ref($Values[0]) ne 'ARRAY') { |
if (! @Values || ref($Values[0]) ne 'ARRAY') { |
return ''; |
return ''; |
} |
} |
Line 2709 sub DrawBarGraph {
|
Line 2713 sub DrawBarGraph {
|
my $NumSets=1; |
my $NumSets=1; |
foreach my $array (@Values) { |
foreach my $array (@Values) { |
next if (! ref($array)); |
next if (! ref($array)); |
$ValuesHash{'cgi.'.$identifier.'.data.'.$NumSets++} = |
$ValuesHash{$id.'.data.'.$NumSets++} = |
join(',',@$array); |
join(',',@$array); |
} |
} |
# |
# |
|
my ($height,$width,$xskip,$bar_width) = (200,120,1,15); |
|
if ($NumBars < 10) { |
|
$width = 120+$NumBars*15; |
|
$xskip = 1; |
|
$bar_width = 15; |
|
} elsif ($NumBars <= 25) { |
|
$width = 120+$NumBars*11; |
|
$xskip = 5; |
|
$bar_width = 8; |
|
} elsif ($NumBars <= 50) { |
|
$width = 120+$NumBars*8; |
|
$xskip = 5; |
|
$bar_width = 4; |
|
} else { |
|
$width = 120+$NumBars*8; |
|
$xskip = 5; |
|
$bar_width = 4; |
|
} |
|
# |
|
my @Labels; |
|
for (my $i=0;$i<@{$Values[0]};$i++) { |
|
push (@Labels,$i+1); |
|
} |
|
# |
$Title = '' if (! defined($Title)); |
$Title = '' if (! defined($Title)); |
$xlabel = '' if (! defined($xlabel)); |
$xlabel = '' if (! defined($xlabel)); |
$ylabel = '' if (! defined($ylabel)); |
$ylabel = '' if (! defined($ylabel)); |
$Title = &Apache::lonnet::escape($Title); |
$ValuesHash{$id.'.title'} = &Apache::lonnet::escape($Title); |
$xlabel = &Apache::lonnet::escape($xlabel); |
$ValuesHash{$id.'.xlabel'} = &Apache::lonnet::escape($xlabel); |
$ylabel = &Apache::lonnet::escape($ylabel); |
$ValuesHash{$id.'.ylabel'} = &Apache::lonnet::escape($ylabel); |
|
$ValuesHash{$id.'.Max'} = $Max; |
|
$ValuesHash{$id.'.NumBars'} = $NumBars; |
|
$ValuesHash{$id.'.NumSets'} = $NumSets; |
|
$ValuesHash{$id.'.PlotType'} = 'bar'; |
|
$ValuesHash{$id.'.Colors'} = join(',',@{$colors}); |
|
$ValuesHash{$id.'.height'} = $height; |
|
$ValuesHash{$id.'.width'} = $width; |
|
$ValuesHash{$id.'.xskip'} = $xskip; |
|
$ValuesHash{$id.'.bar_width'} = $bar_width; |
|
$ValuesHash{$id.'.labels'} = join(',',@Labels); |
# |
# |
$Max = 1 if ($Max < 1); |
$Max = 1 if ($Max < 1); |
if ( int($Max) < $Max ) { |
if ( int($Max) < $Max ) { |
Line 2726 sub DrawBarGraph {
|
Line 2764 sub DrawBarGraph {
|
$Max = int($Max); |
$Max = int($Max); |
} |
} |
# |
# |
&Apache::lonnet::appenv('cgi.'.$identifier.'.title' => $Title, |
&Apache::lonnet::appenv(%ValuesHash); |
'cgi.'.$identifier.'.xlabel' => $xlabel, |
return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />'; |
'cgi.'.$identifier.'.ylabel' => $ylabel, |
} |
'cgi.'.$identifier.'.Max' => $Max, |
|
'cgi.'.$identifier.'.NumBars' => $NumBars, |
############################################################ |
'cgi.'.$identifier.'.NumSets' => $NumSets, |
############################################################ |
'cgi.'.$identifier.'.Colors' => join(',',@{$colors}), |
|
%ValuesHash); |
=pod |
|
|
|
=item DrawXYGraph |
|
|
|
=cut |
|
|
|
############################################################ |
|
############################################################ |
|
sub DrawXYGraph { |
|
my ($Title,$xlabel,$ylabel,$Max,$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.'.Max' => $Max, |
|
$id.'.labels' => join(',',@$Xlabels), |
|
$id.'.PlotType' => 'XY', |
|
$id.'.NumSets' => 2, |
|
); |
|
# |
|
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); |
|
} |
|
# |
|
&Apache::lonnet::appenv(%ValuesHash); |
return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />'; |
return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />'; |
} |
} |
|
|