version 1.20, 2001/12/27 22:30:01
|
version 1.21, 2001/12/28 15:49:38
|
Line 63 sub BEGIN {
|
Line 63 sub BEGIN {
|
## $curves[$i]->{'data'} = [ [x1,x2,x3,x4], |
## $curves[$i]->{'data'} = [ [x1,x2,x3,x4], |
## [y1,y2,y3,y4] ] |
## [y1,y2,y3,y4] ] |
## |
## |
##------------------------------------------------------------ |
|
## |
################################################################### |
## Tests used in checking the validitity of input |
## ## |
## |
## Tests used in checking the validitity of input ## |
|
## ## |
|
################################################################### |
my $int_test = sub {$_[0]=~s/\s+//g;$_[0]=~/^\d+$/}; |
my $int_test = sub {$_[0]=~s/\s+//g;$_[0]=~/^\d+$/}; |
my $real_test = |
my $real_test = |
sub {$_[0]=~s/\s+//g;$_[0]=~/^[+-]?\d*\.?\d*([eE][+-]\d+)?$/}; |
sub {$_[0]=~s/\s+//g;$_[0]=~/^[+-]?\d*\.?\d*([eE][+-]\d+)?$/}; |
Line 76 my $key_pos_test = sub {$_[0]=~/^(top|
|
Line 78 my $key_pos_test = sub {$_[0]=~/^(top|
|
my $sml_test = sub {$_[0]=~/^(small|medium|large)$/}; |
my $sml_test = sub {$_[0]=~/^(small|medium|large)$/}; |
my $linestyle_test = sub {$_[0]=~/^(lines|linespoints|dots|points|steps)$/}; |
my $linestyle_test = sub {$_[0]=~/^(lines|linespoints|dots|points|steps)$/}; |
my $words_test = sub {$_[0]=~s/\s+/ /g;$_[0]=~/^([\w\(\)]+ ?)+$/}; |
my $words_test = sub {$_[0]=~s/\s+/ /g;$_[0]=~/^([\w\(\)]+ ?)+$/}; |
## |
|
## Attribute metadata |
################################################################### |
## |
## ## |
|
## Attribute metadata ## |
|
## ## |
|
################################################################### |
my %plot_defaults = |
my %plot_defaults = |
( |
( |
height => { |
height => { |
Line 250 my %curve_defaults =
|
Line 255 my %curve_defaults =
|
} |
} |
); |
); |
|
|
## |
################################################################### |
## End of defaults |
## ## |
## |
## parsing and edit rendering ## |
|
## ## |
|
################################################################### |
my (%plot,%key,%axis,$title,$xlabel,$ylabel,@labels,@curves); |
my (%plot,%key,%axis,$title,$xlabel,$ylabel,@labels,@curves); |
|
|
sub start_plot { |
sub start_plot { |
Line 274 sub start_plot {
|
Line 281 sub start_plot {
|
&get_attributes(\%plot,\%plot_defaults,$parstack,$safeeval, |
&get_attributes(\%plot,\%plot_defaults,$parstack,$safeeval, |
$tagstack->[-1]); |
$tagstack->[-1]); |
} elsif ($target eq 'edit') { |
} elsif ($target eq 'edit') { |
|
$result .= &Apache::edit::tag_start($target,$token); |
|
$result .= &edit_attributes($target,$token,\%plot_defaults); |
} elsif ($target eq 'modified') { |
} elsif ($target eq 'modified') { |
my $constructtag=&Apache::edit::get_new_args |
my $constructtag=&Apache::edit::get_new_args |
($token,$parstack,$safeeval,keys %plot_defaults); |
($token,$parstack,$safeeval,keys %plot_defaults); |
Line 282 sub start_plot {
|
Line 291 sub start_plot {
|
$result.= &Apache::edit::handle_insert(); |
$result.= &Apache::edit::handle_insert(); |
} |
} |
} |
} |
return ''; |
return $result; |
} |
} |
|
|
sub end_plot { |
sub end_plot { |
Line 292 sub end_plot {
|
Line 301 sub end_plot {
|
('title','xlabel','ylabel','key','axis','label','curve')); |
('title','xlabel','ylabel','key','axis','label','curve')); |
my $result = ''; |
my $result = ''; |
if ($target eq 'web') { |
if ($target eq 'web') { |
## |
&check_inputs(); # Make sure we have all the data we need |
## Make sure we have all the input we need: |
|
if (! defined(%plot )) { &set_defaults(\%plot,\%plot_defaults); } |
|
if (! defined(%key )) {} # No key for this plot |
|
if (! defined(%axis )) { &set_defaults(\%axis,\%axis_defaults); } |
|
if (! defined($title )) {} # No title for this plot |
|
if (! defined($xlabel)) {} # No xlabel for this plot |
|
if (! defined($ylabel)) {} # No ylabel for this plot |
|
if ($#labels < 0) { } # No labels for this plot |
|
if ($#curves < 0) { |
|
&Apache::lonxml::warning("No curves specified for plot!!!!"); |
|
return ''; |
|
} |
|
my $curve; |
|
foreach $curve (@curves) { |
|
if (!defined($curve->{'function'})&&!defined($curve->{'data'})){ |
|
&Apache::lonxml::warning("One of the curves specified did not contain any <data> or <function> declarations\n"); |
|
return ''; |
|
} |
|
} |
|
## |
## |
## Determine filename |
## Determine filename |
my $tmpdir = '/home/httpd/perl/tmp/'; |
my $tmpdir = '/home/httpd/perl/tmp/'; |
Line 330 sub end_plot {
|
Line 320 sub end_plot {
|
alt = "/cgi-bin/plot.gif?$filename" /> |
alt = "/cgi-bin/plot.gif?$filename" /> |
ENDIMAGE |
ENDIMAGE |
} elsif ($target eq 'edit') { |
} elsif ($target eq 'edit') { |
} elsif ($target eq 'modified') { |
$result.=&Apache::edit::tag_end($target,$token); |
} |
} |
return $result; |
return $result; |
} |
} |
Line 343 sub start_key {
|
Line 333 sub start_key {
|
&get_attributes(\%key,\%key_defaults,$parstack,$safeeval, |
&get_attributes(\%key,\%key_defaults,$parstack,$safeeval, |
$tagstack->[-1]); |
$tagstack->[-1]); |
} elsif ($target eq 'edit') { |
} elsif ($target eq 'edit') { |
|
$result .= &Apache::edit::tag_start($target,$token); |
|
$result .= &edit_attributes($target,$token,\%key_defaults); |
} elsif ($target eq 'modified') { |
} elsif ($target eq 'modified') { |
my $constructtag=&Apache::edit::get_new_args |
my $constructtag=&Apache::edit::get_new_args |
($token,$parstack,$safeeval,keys %key_defaults); |
($token,$parstack,$safeeval,keys %key_defaults); |
Line 359 sub end_key {
|
Line 351 sub end_key {
|
my $result = ''; |
my $result = ''; |
if ($target eq 'web') { |
if ($target eq 'web') { |
} elsif ($target eq 'edit') { |
} elsif ($target eq 'edit') { |
} elsif ($target eq 'modified') { |
$result.=&Apache::edit::tag_end($target,$token); |
} |
} |
return $result; |
return $result; |
} |
} |
|
|
##------------------------------------------------------------------- title |
##------------------------------------------------------------------- title |
sub start_title { |
sub start_title { |
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; |
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; |
Line 371 sub start_title {
|
Line 364 sub start_title {
|
$title = &Apache::lonxml::get_all_text("/title",$$parser[-1]); |
$title = &Apache::lonxml::get_all_text("/title",$$parser[-1]); |
} elsif ($target eq 'edit') { |
} elsif ($target eq 'edit') { |
} elsif ($target eq 'modified') { |
} elsif ($target eq 'modified') { |
|
my $text=$$parser[-1]->get_text("/function"); |
|
$result.=&Apache::edit::modifiedfield($token); |
} |
} |
return $result; |
return $result; |
} |
} |
Line 380 sub end_title {
|
Line 375 sub end_title {
|
my $result = ''; |
my $result = ''; |
if ($target eq 'web') { |
if ($target eq 'web') { |
} elsif ($target eq 'edit') { |
} elsif ($target eq 'edit') { |
} elsif ($target eq 'modified') { |
|
} |
} |
return $result; |
return $result; |
} |
} |
Line 392 sub start_xlabel {
|
Line 386 sub start_xlabel {
|
$xlabel = &Apache::lonxml::get_all_text("/xlabel",$$parser[-1]); |
$xlabel = &Apache::lonxml::get_all_text("/xlabel",$$parser[-1]); |
} elsif ($target eq 'edit') { |
} elsif ($target eq 'edit') { |
} elsif ($target eq 'modified') { |
} elsif ($target eq 'modified') { |
|
my $text=$$parser[-1]->get_text("/function"); |
|
$result.=&Apache::edit::modifiedfield($token); |
} |
} |
return $result; |
return $result; |
} |
} |
Line 401 sub end_xlabel {
|
Line 397 sub end_xlabel {
|
my $result = ''; |
my $result = ''; |
if ($target eq 'web') { |
if ($target eq 'web') { |
} elsif ($target eq 'edit') { |
} elsif ($target eq 'edit') { |
} elsif ($target eq 'modified') { |
|
} |
} |
return $result; |
return $result; |
} |
} |
|
|
##------------------------------------------------------------------- ylabel |
##------------------------------------------------------------------- ylabel |
sub start_ylabel { |
sub start_ylabel { |
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; |
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; |
Line 413 sub start_ylabel {
|
Line 409 sub start_ylabel {
|
$ylabel = &Apache::lonxml::get_all_text("/ylabel",$$parser[-1]); |
$ylabel = &Apache::lonxml::get_all_text("/ylabel",$$parser[-1]); |
} elsif ($target eq 'edit') { |
} elsif ($target eq 'edit') { |
} elsif ($target eq 'modified') { |
} elsif ($target eq 'modified') { |
|
my $text=$$parser[-1]->get_text("/function"); |
|
$result.=&Apache::edit::modifiedfield($token); |
} |
} |
return $result; |
return $result; |
} |
} |
Line 422 sub end_ylabel {
|
Line 420 sub end_ylabel {
|
my $result = ''; |
my $result = ''; |
if ($target eq 'web') { |
if ($target eq 'web') { |
} elsif ($target eq 'edit') { |
} elsif ($target eq 'edit') { |
} elsif ($target eq 'modified') { |
|
} |
} |
return $result; |
return $result; |
} |
} |
|
|
##------------------------------------------------------------------- label |
##------------------------------------------------------------------- label |
sub start_label { |
sub start_label { |
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; |
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; |
Line 441 sub start_label {
|
Line 439 sub start_label {
|
} |
} |
push(@labels,\%label); |
push(@labels,\%label); |
} elsif ($target eq 'edit') { |
} elsif ($target eq 'edit') { |
|
$result .= &Apache::edit::tag_start($target,$token); |
|
$result .= &edit_attributes($target,$token,\%label_defaults); |
} elsif ($target eq 'modified') { |
} elsif ($target eq 'modified') { |
my $constructtag=&Apache::edit::get_new_args |
my $constructtag=&Apache::edit::get_new_args |
($token,$parstack,$safeeval,keys %label_defaults); |
($token,$parstack,$safeeval,keys %label_defaults); |
Line 448 sub start_label {
|
Line 448 sub start_label {
|
$result = &Apache::edit::rebuild_tag($token); |
$result = &Apache::edit::rebuild_tag($token); |
$result.= &Apache::edit::handle_insert(); |
$result.= &Apache::edit::handle_insert(); |
} |
} |
|
my $text=$$parser[-1]->get_text("/function"); |
|
$result.=&Apache::edit::modifiedfield($token); |
} |
} |
return $result; |
return $result; |
} |
} |
Line 457 sub end_label {
|
Line 459 sub end_label {
|
my $result = ''; |
my $result = ''; |
if ($target eq 'web') { |
if ($target eq 'web') { |
} elsif ($target eq 'edit') { |
} elsif ($target eq 'edit') { |
} elsif ($target eq 'modified') { |
$result.=&Apache::edit::tag_end($target,$token); |
} |
} |
return $result; |
return $result; |
} |
} |
Line 474 sub start_curve {
|
Line 476 sub start_curve {
|
&Apache::lonxml::register('Apache::lonplot',('function','data')); |
&Apache::lonxml::register('Apache::lonplot',('function','data')); |
push (@Apache::lonxml::namespace,'curve'); |
push (@Apache::lonxml::namespace,'curve'); |
} elsif ($target eq 'edit') { |
} elsif ($target eq 'edit') { |
|
$result .= &Apache::edit::tag_start($target,$token); |
|
$result .= &edit_attributes($target,$token,\%curve_defaults); |
} elsif ($target eq 'modified') { |
} elsif ($target eq 'modified') { |
my $constructtag=&Apache::edit::get_new_args |
my $constructtag=&Apache::edit::get_new_args |
($token,$parstack,$safeeval,keys %label_defaults); |
($token,$parstack,$safeeval,keys %label_defaults); |
Line 492 sub end_curve {
|
Line 496 sub end_curve {
|
pop @Apache::lonxml::namespace; |
pop @Apache::lonxml::namespace; |
&Apache::lonxml::deregister('Apache::lonplot',('function','data')); |
&Apache::lonxml::deregister('Apache::lonplot',('function','data')); |
} elsif ($target eq 'edit') { |
} elsif ($target eq 'edit') { |
} elsif ($target eq 'modified') { |
$result.=&Apache::edit::tag_end($target,$token); |
} |
} |
return $result; |
return $result; |
} |
} |
|
|
##------------------------------------------------------------ curve function |
##------------------------------------------------------------ curve function |
sub start_function { |
sub start_function { |
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; |
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; |
Line 526 sub end_function {
|
Line 531 sub end_function {
|
my $result = ''; |
my $result = ''; |
if ($target eq 'web') { |
if ($target eq 'web') { |
} elsif ($target eq 'edit') { |
} elsif ($target eq 'edit') { |
} elsif ($target eq 'modified') { |
|
} |
} |
return $result; |
return $result; |
} |
} |
|
|
##------------------------------------------------------------ curve data |
##------------------------------------------------------------ curve data |
sub start_data { |
sub start_data { |
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; |
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; |
Line 571 sub start_data {
|
Line 576 sub start_data {
|
push @{$curves[-1]->{'data'}},\@data; |
push @{$curves[-1]->{'data'}},\@data; |
} elsif ($target eq 'edit') { |
} elsif ($target eq 'edit') { |
} elsif ($target eq 'modified') { |
} elsif ($target eq 'modified') { |
|
my $text=$$parser[-1]->get_text("/data"); |
|
$result.=&Apache::edit::modifiedfield($token); |
} |
} |
return $result; |
return $result; |
} |
} |
Line 580 sub end_data {
|
Line 587 sub end_data {
|
my $result = ''; |
my $result = ''; |
if ($target eq 'web') { |
if ($target eq 'web') { |
} elsif ($target eq 'edit') { |
} elsif ($target eq 'edit') { |
} elsif ($target eq 'modified') { |
|
} |
} |
return $result; |
return $result; |
} |
} |
Line 593 sub start_axis {
|
Line 599 sub start_axis {
|
&get_attributes(\%axis,\%axis_defaults,$parstack,$safeeval, |
&get_attributes(\%axis,\%axis_defaults,$parstack,$safeeval, |
$tagstack->[-1]); |
$tagstack->[-1]); |
} elsif ($target eq 'edit') { |
} elsif ($target eq 'edit') { |
|
$result .= &Apache::edit::tag_start($target,$token); |
|
$result .= &edit_attributes($target,$token,\%axis_defaults); |
} elsif ($target eq 'modified') { |
} elsif ($target eq 'modified') { |
} |
} |
return $result; |
return $result; |
Line 603 sub end_axis {
|
Line 611 sub end_axis {
|
my $result = ''; |
my $result = ''; |
if ($target eq 'web') { |
if ($target eq 'web') { |
} elsif ($target eq 'edit') { |
} elsif ($target eq 'edit') { |
|
$result.=&Apache::edit::tag_end($target,$token); |
} elsif ($target eq 'modified') { |
} elsif ($target eq 'modified') { |
my $constructtag=&Apache::edit::get_new_args |
my $constructtag=&Apache::edit::get_new_args |
($token,$parstack,$safeeval,keys %axis_defaults); |
($token,$parstack,$safeeval,keys %axis_defaults); |
Line 614 sub end_axis {
|
Line 623 sub end_axis {
|
return $result; |
return $result; |
} |
} |
|
|
|
################################################################### |
|
## ## |
|
## Utility Functions ## |
|
## ## |
|
################################################################### |
|
|
##----------------------------------------------------------- set_defaults |
##----------------------------------------------------------- set_defaults |
sub set_defaults { |
sub set_defaults { |
my $var = shift; |
my ($var,$defaults) = @_; |
my $defaults = shift; |
|
my $key; |
my $key; |
foreach $key (keys %$defaults) { |
foreach $key (keys %$defaults) { |
$var->{$key} = $defaults->{$key}->{'default'}; |
$var->{$key} = $defaults->{$key}->{'default'}; |
Line 626 sub set_defaults {
|
Line 640 sub set_defaults {
|
|
|
##------------------------------------------------------------------- misc |
##------------------------------------------------------------------- misc |
sub get_attributes{ |
sub get_attributes{ |
my $values = shift; |
my ($values,$defaults,$parstack,$safeeval,$tag) = @_; |
my $defaults = shift; |
|
my $parstack = shift; |
|
my $safeeval = shift; |
|
my $tag = shift; |
|
foreach my $attr (keys %{$defaults}) { |
foreach my $attr (keys %{$defaults}) { |
$values->{$attr} = |
$values->{$attr} = |
&Apache::lonxml::get_param($attr,$parstack,$safeeval); |
&Apache::lonxml::get_param($attr,$parstack,$safeeval); |
Line 728 sub write_gnuplot_file {
|
Line 738 sub write_gnuplot_file {
|
$gnuplot_input .= $/.$datatext; |
$gnuplot_input .= $/.$datatext; |
return $gnuplot_input; |
return $gnuplot_input; |
} |
} |
|
|
|
#---------------------------------------------- check_inputs |
|
sub check_inputs { |
|
## Note: no inputs, no outputs - this acts only on global variables. |
|
## Make sure we have all the input we need: |
|
if (! defined(%plot )) { &set_defaults(\%plot,\%plot_defaults); } |
|
if (! defined(%key )) {} # No key for this plot, thats okay |
|
if (! defined(%axis )) { &set_defaults(\%axis,\%axis_defaults); } |
|
if (! defined($title )) {} # No title for this plot, thats okay |
|
if (! defined($xlabel)) {} # No xlabel for this plot, thats okay |
|
if (! defined($ylabel)) {} # No ylabel for this plot, thats okay |
|
if ($#labels < 0) { } # No labels for this plot, thats okay |
|
if ($#curves < 0) { |
|
&Apache::lonxml::warning("No curves specified for plot!!!!"); |
|
return ''; |
|
} |
|
my $curve; |
|
foreach $curve (@curves) { |
|
if (!defined($curve->{'function'})&&!defined($curve->{'data'})){ |
|
&Apache::lonxml::warning("One of the curves specified did not contain any <data> or <function> declarations\n"); |
|
return ''; |
|
} |
|
} |
|
} |
|
|
#------------------------------------------------ make_edit |
#------------------------------------------------ make_edit |
sub edit_attributes { |
sub edit_attributes { |
my $target = shift; |
my ($target,$token,$defaults) = @_; |
my $token = shift; |
|
my $defaults = shift; |
|
my $result; |
my $result; |
foreach my $attr (%{$token->[2]}) { |
foreach my $attr (%$defaults) { |
if ($defaults->{$attr}->{'edit_type'} eq 'entry') { |
if ($defaults->{$attr}->{'edit_type'} eq 'entry') { |
$result .= &Apache::edit::text_arg( |
$result .= &Apache::edit::text_arg( |
$defaults->{$attr}->{'description'}, |
$defaults->{$attr}->{'description'}, |
Line 751 sub edit_attributes {
|
Line 784 sub edit_attributes {
|
return $result; |
return $result; |
} |
} |
|
|
|
|
|
################################################################### |
|
## ## |
|
## Insertion functions for editing plots ## |
|
## ## |
|
################################################################### |
|
|
#------------------------------------------------ insert_xxxxxxx |
#------------------------------------------------ insert_xxxxxxx |
sub insert_plot { |
sub insert_plot { |
my $result; |
my $result; |
Line 832 sub insert_data {
|
Line 872 sub insert_data {
|
return $result; |
return $result; |
} |
} |
|
|
|
##---------------------------------------------------------------------- |
1; |
1; |
__END__ |
__END__ |
|
|