--- loncom/xml/lonplot.pm 2001/12/17 21:43:12 1.1 +++ loncom/xml/lonplot.pm 2001/12/18 15:33:47 1.2 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Dynamic plot # -# $Id: lonplot.pm,v 1.1 2001/12/17 21:43:12 matthew Exp $ +# $Id: lonplot.pm,v 1.2 2001/12/18 15:33:47 matthew Exp $ # # Copyright Michigan State University Board of Trustees # @@ -29,6 +29,8 @@ package Apache::lonplot; use strict; use Apache::response; +use Apache::lonxml; +use Digest::MD5 qw(md5 md5_hex md5_base64); sub BEGIN { &Apache::lonxml::register('Apache::lonplot',('plot')); @@ -103,30 +105,25 @@ sub start_plot { %plot = ''; %key=''; %axis=''; $title=''; $xlabel=''; $ylabel=''; @labels = ''; @curves=''; + my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; my $result=''; - # &Apache::lonxml::register('Apache::plot', ('title','xlabel','ylabel','key','axis','label','curve')); push (@Apache::lonxml::namespace,'plot'); - &get_attributes(\%plot,\%plot_defaults,$parstack,$safeeval); - return ''; -} - -sub get_attributes{ - %values = %{$_[0]}; - %defaults = %{$_[1]}; - $parstack = $_[2]; - $safeeval = $_[3]; - 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} ); + ##------------------------------------------------------- + ## How do I do this? I need to "eval" and I need to keep the info + ## available for the parser. + ## + my $inside = &Apache::lonxml::get_all_text("/plot",$$parser[-1]); + my $eval=&Apache::lonxml::get_param('eval',$parstack,$safeeval); + if ($eval eq 'on') { + $inside=&Apache::run::evaluate($inside,$safeeval,$$parstack[-1]); + #&Apache::lonxml::debug("M is evaulated to:$inside:"); } - return ; + ##------------------------------------------------------- + &get_attributes(\%plot,\%plot_defaults,$parstack,$safeeval,'plot'); + return ''; } sub end_plot { @@ -134,16 +131,24 @@ sub end_plot { pop @Apache::lonxml::namespace; my $result; ## 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 + my $fh=&Apache::File->new('/home/httpd/perl/tmp/'.$realname); + ## Ack! ## return image tag for the plot + $result = '{'text'} = &Apache::lonxml::get_all_text("/label",$$parser[-1]); push(@labels,$label); return $result; @@ -213,7 +218,7 @@ sub start_curve { my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; my $result=''; my $curve = &newhashref(); - &get_attributes($curve,\%curve_defaults,$parstack,$safeeval); + &get_attributes($curve,\%curve_defaults,$parstack,$safeeval,'curve'); push (@curves,$curve); &Apache::lonxml::register('Apache::plot',('function','data')); @@ -263,7 +268,7 @@ sub end_data { sub start_axis { my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; my $result=''; - &get_attributes(\%axis,\%label_defaults,$parstack,$safeeval); + &get_attributes(\%axis,\%label_defaults,$parstack,$safeeval,'axis'); return $result; } @@ -279,6 +284,22 @@ sub newhashref{ 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; __END__