version 1.38, 2002/01/10 19:45:51
|
version 1.43, 2002/01/21 17:23:31
|
Line 29
|
Line 29
|
# 12/17 12/18 12/19 12/20 12/21 12/27 12/28 12/30 12/31 Matthew |
# 12/17 12/18 12/19 12/20 12/21 12/27 12/28 12/30 12/31 Matthew |
# 01/01/02 Matthew |
# 01/01/02 Matthew |
# 01/02 01/03 01/04 01/07 01/08 01/09 Matthew |
# 01/02 01/03 01/04 01/07 01/08 01/09 Matthew |
|
# 01/21 Matthew |
|
|
# Current issues |
|
# 1. Gnuplot is unable to vary the color or linestyle of <data> plots. |
|
# The key does not know this so it is misleading for the user. |
|
# Multiple <function>s can be plotted with varying line styles and |
|
# colors. |
|
# |
|
package Apache::lonplot; |
package Apache::lonplot; |
|
|
use strict; |
use strict; |
Line 330 sub start_plot {
|
Line 325 sub start_plot {
|
($token,$parstack,$safeeval,keys(%plot_defaults)); |
($token,$parstack,$safeeval,keys(%plot_defaults)); |
if ($constructtag) { |
if ($constructtag) { |
$result = &Apache::edit::rebuild_tag($token); |
$result = &Apache::edit::rebuild_tag($token); |
# $result.= &Apache::edit::handle_insert(); |
|
} |
} |
} |
} |
return $result; |
return $result; |
Line 351 sub end_plot {
|
Line 345 sub end_plot {
|
my $filename = $ENV{'user.name'}.'_'.$ENV{'user.domain'}. |
my $filename = $ENV{'user.name'}.'_'.$ENV{'user.domain'}. |
'_'.time.'_'.$$.int(rand(1000)).'_plot.data'; |
'_'.time.'_'.$$.int(rand(1000)).'_plot.data'; |
## Write the plot description to the file |
## Write the plot description to the file |
my $fh=Apache::File->new(">$tmpdir$filename"); |
&write_gnuplot_file($tmpdir,$filename); |
print $fh &write_gnuplot_file(); |
|
close($fh); |
|
## return image tag for the plot |
## return image tag for the plot |
$result .= <<"ENDIMAGE"; |
$result .= <<"ENDIMAGE"; |
<img src = "/cgi-bin/plot.gif?$filename" |
<img src = "/cgi-bin/plot.gif?$filename" |
Line 383 sub start_key {
|
Line 375 sub start_key {
|
($token,$parstack,$safeeval,keys(%key_defaults)); |
($token,$parstack,$safeeval,keys(%key_defaults)); |
if ($constructtag) { |
if ($constructtag) { |
$result = &Apache::edit::rebuild_tag($token); |
$result = &Apache::edit::rebuild_tag($token); |
$result.= &Apache::edit::handle_insert(); |
|
} |
} |
} |
} |
return $result; |
return $result; |
Line 411 sub start_title {
|
Line 402 sub start_title {
|
} elsif ($target eq 'edit') { |
} elsif ($target eq 'edit') { |
$result.=&Apache::edit::tag_start($target,$token,'Plot Title'); |
$result.=&Apache::edit::tag_start($target,$token,'Plot Title'); |
my $text=&Apache::lonxml::get_all_text("/title",$$parser[-1]); |
my $text=&Apache::lonxml::get_all_text("/title",$$parser[-1]); |
$result.='</td></tr><tr><td colspan="3">'. |
$result.=&Apache::edit::end_row(). |
|
&Apache::edit::start_spanning_row(). |
&Apache::edit::editfield('',$text,'',60,1); |
&Apache::edit::editfield('',$text,'',60,1); |
} elsif ($target eq 'modified') { |
} elsif ($target eq 'modified') { |
my $text=$$parser[-1]->get_text("/title"); |
my $text=$$parser[-1]->get_text("/title"); |
|
$result.=&Apache::edit::rebuild_tag($token); |
$result.=&Apache::edit::modifiedfield($token); |
$result.=&Apache::edit::modifiedfield($token); |
} |
} |
return $result; |
return $result; |
Line 441 sub start_xlabel {
|
Line 434 sub start_xlabel {
|
} elsif ($target eq 'edit') { |
} elsif ($target eq 'edit') { |
$result.=&Apache::edit::tag_start($target,$token,'Plot Xlabel'); |
$result.=&Apache::edit::tag_start($target,$token,'Plot Xlabel'); |
my $text=&Apache::lonxml::get_all_text("/xlabel",$$parser[-1]); |
my $text=&Apache::lonxml::get_all_text("/xlabel",$$parser[-1]); |
$result.='</td></tr><tr><td colspan="3">'. |
$result.=&Apache::edit::end_row(). |
|
&Apache::edit::start_spanning_row(). |
&Apache::edit::editfield('',$text,'',60,1); |
&Apache::edit::editfield('',$text,'',60,1); |
} elsif ($target eq 'modified') { |
} elsif ($target eq 'modified') { |
my $text=$$parser[-1]->get_text("/xlabel"); |
my $text=$$parser[-1]->get_text("/xlabel"); |
|
$result.=&Apache::edit::rebuild_tag($token); |
$result.=&Apache::edit::modifiedfield($token); |
$result.=&Apache::edit::modifiedfield($token); |
} |
} |
return $result; |
return $result; |
Line 472 sub start_ylabel {
|
Line 467 sub start_ylabel {
|
} elsif ($target eq 'edit') { |
} elsif ($target eq 'edit') { |
$result .= &Apache::edit::tag_start($target,$token,'Plot Ylabel'); |
$result .= &Apache::edit::tag_start($target,$token,'Plot Ylabel'); |
my $text = &Apache::lonxml::get_all_text("/ylabel",$$parser[-1]); |
my $text = &Apache::lonxml::get_all_text("/ylabel",$$parser[-1]); |
$result .= '</td></tr><tr><td colspan="3">'. |
$result .= &Apache::edit::end_row(). |
|
&Apache::edit::start_spanning_row(). |
&Apache::edit::editfield('',$text,'',60,1); |
&Apache::edit::editfield('',$text,'',60,1); |
} elsif ($target eq 'modified') { |
} elsif ($target eq 'modified') { |
my $text=$$parser[-1]->get_text("/ylabel"); |
my $text=$$parser[-1]->get_text("/ylabel"); |
|
$result.=&Apache::edit::rebuild_tag($token); |
$result.=&Apache::edit::modifiedfield($token); |
$result.=&Apache::edit::modifiedfield($token); |
} |
} |
return $result; |
return $result; |
Line 507 sub start_label {
|
Line 504 sub start_label {
|
$result .= &Apache::edit::tag_start($target,$token,'Plot Label'); |
$result .= &Apache::edit::tag_start($target,$token,'Plot Label'); |
$result .= &edit_attributes($target,$token,\%label_defaults); |
$result .= &edit_attributes($target,$token,\%label_defaults); |
my $text = &Apache::lonxml::get_all_text("/label",$$parser[-1]); |
my $text = &Apache::lonxml::get_all_text("/label",$$parser[-1]); |
$result .= '</td></tr><tr><td colspan="3">'. |
$result .= &Apache::edit::end_row(). |
|
&Apache::edit::start_spanning_row(). |
&Apache::edit::editfield('',$text,'',60,1); |
&Apache::edit::editfield('',$text,'',60,1); |
} elsif ($target eq 'modified') { |
} elsif ($target eq 'modified') { |
my $constructtag=&Apache::edit::get_new_args |
&Apache::edit::get_new_args |
($token,$parstack,$safeeval,keys(%label_defaults)); |
($token,$parstack,$safeeval,keys(%label_defaults)); |
if ($constructtag) { |
$result.=&Apache::edit::rebuild_tag($token); |
$result = &Apache::edit::rebuild_tag($token); |
|
$result.= &Apache::edit::handle_insert(); |
|
} |
|
my $text=$$parser[-1]->get_text("/label"); |
my $text=$$parser[-1]->get_text("/label"); |
$result.=&Apache::edit::modifiedfield($token); |
$result.=&Apache::edit::modifiedfield($token); |
} |
} |
Line 583 sub start_function {
|
Line 578 sub start_function {
|
} elsif ($target eq 'edit') { |
} elsif ($target eq 'edit') { |
$result .= &Apache::edit::tag_start($target,$token,'Gnuplot compatible curve function'); |
$result .= &Apache::edit::tag_start($target,$token,'Gnuplot compatible curve function'); |
my $text = &Apache::lonxml::get_all_text("/function",$$parser[-1]); |
my $text = &Apache::lonxml::get_all_text("/function",$$parser[-1]); |
$result .= '</td></tr><tr><td colspan="3">'. |
$result .= &Apache::edit::end_row(). |
|
&Apache::edit::start_spanning_row(). |
&Apache::edit::editfield('',$text,'',60,1); |
&Apache::edit::editfield('',$text,'',60,1); |
} elsif ($target eq 'modified') { |
} elsif ($target eq 'modified') { |
# Why do I do this? |
$result.=&Apache::edit::rebuild_tag($token); |
my $text=$$parser[-1]->get_text("/function"); |
my $text=$$parser[-1]->get_text("/function"); |
$result.=&Apache::edit::modifiedfield($token); |
$result.=&Apache::edit::modifiedfield($token); |
} |
} |
Line 615 sub start_data {
|
Line 611 sub start_data {
|
delete($curves[-1]->{'function'}); |
delete($curves[-1]->{'function'}); |
} |
} |
my $datatext = &Apache::lonxml::get_all_text("/data",$$parser[-1]); |
my $datatext = &Apache::lonxml::get_all_text("/data",$$parser[-1]); |
|
# Deal with cases where we're given an array... |
|
if ($datatext =~ /^\@/) { |
|
$datatext = &Apache::run::run('return "'.$datatext.'"', |
|
$safeeval,1); |
|
} |
$datatext =~ s/\s+/ /g; |
$datatext =~ s/\s+/ /g; |
# Need to do some error checking on the @data array - |
# Need to do some error checking on the @data array - |
# make sure it's all numbers and make sure each array |
# make sure it's all numbers and make sure each array |
Line 652 sub start_data {
|
Line 653 sub start_data {
|
} elsif ($target eq 'edit') { |
} elsif ($target eq 'edit') { |
$result .= &Apache::edit::tag_start($target,$token,'Comma or space deliminated curve data'); |
$result .= &Apache::edit::tag_start($target,$token,'Comma or space deliminated curve data'); |
my $text = &Apache::lonxml::get_all_text("/data",$$parser[-1]); |
my $text = &Apache::lonxml::get_all_text("/data",$$parser[-1]); |
$result .= '</td></tr><tr><td colspan="3">'. |
$result .= &Apache::edit::end_row(). |
|
&Apache::edit::start_spanning_row(). |
&Apache::edit::editfield('',$text,'',60,1); |
&Apache::edit::editfield('',$text,'',60,1); |
} elsif ($target eq 'modified') { |
} elsif ($target eq 'modified') { |
|
$result.=&Apache::edit::rebuild_tag($token); |
my $text=$$parser[-1]->get_text("/data"); |
my $text=$$parser[-1]->get_text("/data"); |
$result.=&Apache::edit::modifiedfield($token); |
$result.=&Apache::edit::modifiedfield($token); |
} |
} |
Line 686 sub start_axis {
|
Line 689 sub start_axis {
|
($token,$parstack,$safeeval,keys(%axis_defaults)); |
($token,$parstack,$safeeval,keys(%axis_defaults)); |
if ($constructtag) { |
if ($constructtag) { |
$result = &Apache::edit::rebuild_tag($token); |
$result = &Apache::edit::rebuild_tag($token); |
$result.= &Apache::edit::handle_insert(); |
|
} |
} |
} |
} |
return $result; |
return $result; |
Line 738 sub get_attributes{
|
Line 740 sub get_attributes{
|
} |
} |
return ; |
return ; |
} |
} |
|
|
##------------------------------------------------------- write_gnuplot_file |
##------------------------------------------------------- write_gnuplot_file |
sub write_gnuplot_file { |
sub write_gnuplot_file { |
|
my ($tmpdir,$filename)= @_; |
my $gnuplot_input = ''; |
my $gnuplot_input = ''; |
my $curve; |
my $curve; |
# Collect all the colors |
# Collect all the colors |
Line 776 sub write_gnuplot_file {
|
Line 780 sub write_gnuplot_file {
|
if (%key) { |
if (%key) { |
$gnuplot_input .= 'set key '.$key{'pos'}.' '; |
$gnuplot_input .= 'set key '.$key{'pos'}.' '; |
if ($key{'title'} ne '') { |
if ($key{'title'} ne '') { |
$gnuplot_input .= 'title "'.$key{'title'}.'" '; |
$gnuplot_input .= 'title " '.$key{'title'}.'" '; |
} |
} |
$gnuplot_input .= ($key{'box'} eq 'on' ? 'box ' : 'nobox ').$/; |
$gnuplot_input .= ($key{'box'} eq 'on' ? 'box ' : 'nobox ').$/; |
} else { |
} else { |
Line 790 sub write_gnuplot_file {
|
Line 794 sub write_gnuplot_file {
|
} |
} |
# curves |
# curves |
$gnuplot_input .= 'plot '; |
$gnuplot_input .= 'plot '; |
my $datatext = ''; |
|
for (my $i = 0;$i<=$#curves;$i++) { |
for (my $i = 0;$i<=$#curves;$i++) { |
$curve = $curves[$i]; |
$curve = $curves[$i]; |
$gnuplot_input.= ', ' if ($i > 0); |
$gnuplot_input.= ', ' if ($i > 0); |
Line 800 sub write_gnuplot_file {
|
Line 803 sub write_gnuplot_file {
|
$curve->{'name'}.'" with '. |
$curve->{'name'}.'" with '. |
$curve->{'linestyle'}; |
$curve->{'linestyle'}; |
} elsif (exists($curve->{'data'})) { |
} elsif (exists($curve->{'data'})) { |
$gnuplot_input.= '\'-\' title "'. |
# Store data values in $datatext |
$curve->{'name'}.'" with '. |
my $datatext = ''; |
$curve->{'linestyle'}; |
# get new filename |
|
my $datafilename = "$tmpdir/$filename.$i"; |
|
my $fh=Apache::File->new(">$datafilename"); |
|
# Compile data |
my @Data = @{$curve->{'data'}}; |
my @Data = @{$curve->{'data'}}; |
my @Data0 = @{$Data[0]}; |
my @Data0 = @{$Data[0]}; |
for (my $i =0; $i<=$#Data0; $i++) { |
for (my $i =0; $i<=$#Data0; $i++) { |
Line 812 sub write_gnuplot_file {
|
Line 818 sub write_gnuplot_file {
|
} |
} |
$datatext .= $/; |
$datatext .= $/; |
} |
} |
$datatext .=$/; |
# write file |
|
print $fh $datatext; |
|
close ($fh); |
|
# generate gnuplot text |
|
$gnuplot_input.= '"'.$datafilename.'" title "'. |
|
$curve->{'name'}.'" with '. |
|
$curve->{'linestyle'}; |
} |
} |
} |
} |
$gnuplot_input .= $/.$datatext; |
# Write the output to a file. |
return $gnuplot_input; |
my $fh=Apache::File->new(">$tmpdir$filename"); |
|
print $fh $gnuplot_input; |
|
close($fh); |
|
# That's all folks. |
|
return ; |
} |
} |
|
|
#---------------------------------------------- check_inputs |
#---------------------------------------------- check_inputs |
Line 937 sub insert_label {
|
Line 953 sub insert_label {
|
|
|
sub insert_curve { |
sub insert_curve { |
my $result; |
my $result; |
$result .= ' <curve '; |
$result .= "\n <curve "; |
foreach my $attr (keys(%curve_defaults)) { |
foreach my $attr (keys(%curve_defaults)) { |
$result .= ' '.$attr.'="'. |
$result .= ' '.$attr.'="'. |
$curve_defaults{$attr}->{'default'}."\"\n"; |
$curve_defaults{$attr}->{'default'}."\"\n"; |
} |
} |
$result .= " ></curve>\n"; |
$result .= " >\n"; |
|
$result .= &insert_data().&insert_data()."</curve>\n"; |
} |
} |
|
|
sub insert_function { |
sub insert_function { |