Diff for /loncom/xml/lonplot.pm between versions 1.1 and 1.3

version 1.1, 2001/12/17 21:43:12 version 1.3, 2001/12/18 16:06:01
Line 25 Line 25
 #  #
 # http://www.lon-capa.org/  # http://www.lon-capa.org/
 #  #
 # 2/21 Guy  # 12/15/01 Matthew
   # 12/18 Matthew
 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 106  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 132  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,$tagstack);
     return $result;      return $result;
 }  }
   
Line 195  sub end_ylabel { Line 201  sub end_ylabel {
 sub start_label {  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;
     &get_attributes($label,\%label_defaults,$parstack,$safeeval);      &get_attributes($label,\%label_defaults,$parstack,$safeeval,$tagstack);
     $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 212  sub end_label { Line 218  sub end_label {
 sub start_curve {  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;
     &get_attributes($curve,\%curve_defaults,$parstack,$safeeval);      &get_attributes($curve,\%curve_defaults,$parstack,$safeeval,$tagstack);
     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 269  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,$tagstack);
     return $result;      return $result;
 }  }
   
Line 274  sub end_axis { Line 280  sub end_axis {
 }  }
   
 ##------------------------------------------------------------------- misc  ##------------------------------------------------------------------- misc
 sub newhashref{  sub get_attributes{
     my %hash;      %values   = %{shift};
     return \%hash;      %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__

Removed from v.1.1  
changed lines
  Added in v.1.3


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>