version 1.1, 2001/12/17 21:43:12
|
version 1.2, 2001/12/18 15:33:47
|
Line 29
|
Line 29
|
package Apache::lonplot; |
package Apache::lonplot; |
use strict; |
use strict; |
use Apache::response; |
use Apache::response; |
|
use Apache::lonxml; |
|
use Digest::MD5 qw(md5 md5_hex md5_base64); |
|
|
sub BEGIN { |
sub BEGIN { |
&Apache::lonxml::register('Apache::lonplot',('plot')); |
&Apache::lonxml::register('Apache::lonplot',('plot')); |
Line 103 sub start_plot {
|
Line 105 sub start_plot {
|
%plot = ''; %key=''; %axis=''; |
%plot = ''; %key=''; %axis=''; |
$title=''; $xlabel=''; $ylabel=''; |
$title=''; $xlabel=''; $ylabel=''; |
@labels = ''; @curves=''; |
@labels = ''; @curves=''; |
|
|
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; |
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; |
my $result=''; |
my $result=''; |
# |
|
&Apache::lonxml::register('Apache::plot', |
&Apache::lonxml::register('Apache::plot', |
('title','xlabel','ylabel','key','axis','label','curve')); |
('title','xlabel','ylabel','key','axis','label','curve')); |
push (@Apache::lonxml::namespace,'plot'); |
push (@Apache::lonxml::namespace,'plot'); |
&get_attributes(\%plot,\%plot_defaults,$parstack,$safeeval); |
##------------------------------------------------------- |
return ''; |
## How do I do this? I need to "eval" and I need to keep the info |
} |
## available for the parser. |
|
## |
sub get_attributes{ |
my $inside = &Apache::lonxml::get_all_text("/plot",$$parser[-1]); |
%values = %{$_[0]}; |
my $eval=&Apache::lonxml::get_param('eval',$parstack,$safeeval); |
%defaults = %{$_[1]}; |
if ($eval eq 'on') { |
$parstack = $_[2]; |
$inside=&Apache::run::evaluate($inside,$safeeval,$$parstack[-1]); |
$safeeval = $_[3]; |
#&Apache::lonxml::debug("M is evaulated to:$inside:"); |
my $attr; |
|
foreach $attr (keys %defaults) { |
|
$values{$attr} = &Apache::lonxml::get_param($attr,$parstack,$safeeval); |
|
my $test = $defaults{$attr}->{'test'}; |
|
$values{$attr} = (&$test($values{$attr}) ? |
|
$values{$attr} : |
|
$defaults{$attr} ); |
|
} |
} |
return ; |
##------------------------------------------------------- |
|
&get_attributes(\%plot,\%plot_defaults,$parstack,$safeeval,'plot'); |
|
return ''; |
} |
} |
|
|
sub end_plot { |
sub end_plot { |
Line 134 sub end_plot {
|
Line 131 sub end_plot {
|
pop @Apache::lonxml::namespace; |
pop @Apache::lonxml::namespace; |
my $result; |
my $result; |
## Determine filename |
## Determine filename |
my $filename = |
my $tmpdir = '/home/httpd/perl/tmp/'; |
|
my $filename = $tmpdir.$ENV{'user.name'}.'_'.$ENV{'user.domain'}. |
|
'_plot.data'; |
|
my $usersees=md5_base64($filename.'_'.$ENV{'REMOTE_ADDR'}); |
|
|
## Write the plot description to the file |
## Write the plot description to the file |
|
my $fh=&Apache::File->new('/home/httpd/perl/tmp/'.$realname); |
|
## Ack! |
## return image tag for the plot |
## return image tag for the plot |
|
$result = '<img src=\"/cgi-bin/plot.cgi?'.$usersees.'"'; |
return $result; |
return $result; |
} |
} |
|
|
##----------------------------------------------------------------- key |
##----------------------------------------------------------------- key |
sub start_key { |
sub start_key { |
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; |
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; |
my $result=''; |
my $result=''; |
&get_attributes(\%key,\%key_defaults,$parstack,$safeeval); |
&get_attributes(\%key,\%key_defaults,$parstack,$safeeval,'key'); |
return $result; |
return $result; |
} |
} |
|
|
Line 196 sub start_label {
|
Line 201 sub start_label {
|
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; |
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; |
my $result=''; |
my $result=''; |
my $label = &newhashref(); |
my $label = &newhashref(); |
&get_attributes($label,\%label_defaults,$parstack,$safeeval); |
&get_attributes($label,\%label_defaults,$parstack,$safeeval,'label'); |
$label->{'text'} = &Apache::lonxml::get_all_text("/label",$$parser[-1]); |
$label->{'text'} = &Apache::lonxml::get_all_text("/label",$$parser[-1]); |
push(@labels,$label); |
push(@labels,$label); |
return $result; |
return $result; |
Line 213 sub start_curve {
|
Line 218 sub start_curve {
|
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; |
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; |
my $result=''; |
my $result=''; |
my $curve = &newhashref(); |
my $curve = &newhashref(); |
&get_attributes($curve,\%curve_defaults,$parstack,$safeeval); |
&get_attributes($curve,\%curve_defaults,$parstack,$safeeval,'curve'); |
push (@curves,$curve); |
push (@curves,$curve); |
|
|
&Apache::lonxml::register('Apache::plot',('function','data')); |
&Apache::lonxml::register('Apache::plot',('function','data')); |
Line 263 sub end_data {
|
Line 268 sub end_data {
|
sub start_axis { |
sub start_axis { |
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; |
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; |
my $result=''; |
my $result=''; |
&get_attributes(\%axis,\%label_defaults,$parstack,$safeeval); |
&get_attributes(\%axis,\%label_defaults,$parstack,$safeeval,'axis'); |
return $result; |
return $result; |
} |
} |
|
|
Line 279 sub newhashref{
|
Line 284 sub newhashref{
|
return \%hash; |
return \%hash; |
} |
} |
|
|
|
sub get_attributes{ |
|
%values = %{shift}; |
|
%defaults = %{shift}; |
|
$parstack = shift; |
|
$safeeval = shift; |
|
$tag = shift; |
|
my $attr; |
|
foreach $attr (keys %defaults) { |
|
$values{$attr} = &Apache::lonxml::get_param($attr,$parstack,$safeeval); |
|
my $test = $defaults{$attr}->{'test'}; |
|
if (! &$test($values{$attr})) { |
|
&Apache::lonxml::warning($tag.':'.$attr.': Bad value. Replacing your value with : '.$defaults{$attr}); |
|
$values{$attr} = $defaults{$attr}; |
|
} |
|
return ; |
|
} |
|
|
1; |
1; |
__END__ |
__END__ |