version 1.62, 2002/03/22 16:56:37
|
version 1.69, 2002/04/25 17:25:36
|
Line 104 my $onoff_test = sub {$_[0]=~/^(on|o
|
Line 104 my $onoff_test = sub {$_[0]=~/^(on|o
|
my $key_pos_test = sub {$_[0]=~/^(top|bottom|right|left|outside|below| )+$/}; |
my $key_pos_test = sub {$_[0]=~/^(top|bottom|right|left|outside|below| )+$/}; |
my $sml_test = sub {$_[0]=~/^(small|medium|large)$/}; |
my $sml_test = sub {$_[0]=~/^(small|medium|large)$/}; |
my $linestyle_test = sub {exists($linestyles{$_[0]})}; |
my $linestyle_test = sub {exists($linestyles{$_[0]})}; |
my $words_test = sub {$_[0]=~s/\s+/ /g;$_[0]=~/^([\w\(\)]+ ?)+$/}; |
my $words_test = sub {$_[0]=~s/\s+/ /g;$_[0]=~/^([\w~!\@\#\$\%^&\*\(\)-=_\+\[\]\{\}:\;\'<>,\.\/\?\\]+ ?)+$/}; |
|
|
################################################################### |
################################################################### |
## ## |
## ## |
Line 112 my $words_test = sub {$_[0]=~s/\s+/
|
Line 112 my $words_test = sub {$_[0]=~s/\s+/
|
## ## |
## ## |
################################################################### |
################################################################### |
my @gnuplot_edit_order = |
my @gnuplot_edit_order = |
qw/bgcolor fgcolor height width font transparent grid border align/; |
qw/alttag bgcolor fgcolor height width font transparent grid border align/; |
|
|
my $gnuplot_help_text = <<"ENDPLOTHELP"; |
my $gnuplot_help_text = <<"ENDPLOTHELP"; |
<p> |
<p> |
Line 148 ENDPLOTHELP
|
Line 148 ENDPLOTHELP
|
|
|
my %gnuplot_defaults = |
my %gnuplot_defaults = |
( |
( |
|
alttag => { |
|
default => 'dynamically generated plot', |
|
test => $words_test, |
|
description => 'brief description of the plot', |
|
edit_type => 'entry', |
|
size => '40' |
|
}, |
height => { |
height => { |
default => 200, |
default => 300, |
test => $int_test, |
test => $int_test, |
description => 'height of image (pixels)', |
description => 'height of image (pixels)', |
edit_type => 'entry', |
edit_type => 'entry', |
size => '10' |
size => '10' |
}, |
}, |
width => { |
width => { |
default => 200, |
default => 400, |
test => $int_test, |
test => $int_test, |
description => 'width of image (pixels)', |
description => 'width of image (pixels)', |
edit_type => 'entry', |
edit_type => 'entry', |
Line 183 my %gnuplot_defaults =
|
Line 190 my %gnuplot_defaults =
|
edit_type => 'onoff' |
edit_type => 'onoff' |
}, |
}, |
grid => { |
grid => { |
default => 'off', |
default => 'on', |
test => $onoff_test, |
test => $onoff_test, |
description => 'Display grid', |
description => 'Display grid', |
edit_type => 'onoff' |
edit_type => 'onoff' |
Line 202 my %gnuplot_defaults =
|
Line 209 my %gnuplot_defaults =
|
choices => ['small','medium','large'] |
choices => ['small','medium','large'] |
}, |
}, |
align => { |
align => { |
default => 'left', |
default => 'center', |
test => sub {$_[0]=~/^(left|right|center)$/}, |
test => sub {$_[0]=~/^(left|right|center)$/}, |
description => 'alignment for image in html', |
description => 'alignment for image in html', |
edit_type => 'choice', |
edit_type => 'choice', |
Line 299 my %tic_defaults =
|
Line 306 my %tic_defaults =
|
}, |
}, |
); |
); |
|
|
|
my @axis_edit_order = ('color','xmin','xmax','ymin','ymax'); |
my %axis_defaults = |
my %axis_defaults = |
( |
( |
color => { |
color => { |
Line 476 sub end_gnuplot {
|
Line 484 sub end_gnuplot {
|
## Determine filename |
## Determine filename |
my $tmpdir = '/home/httpd/perl/tmp/'; |
my $tmpdir = '/home/httpd/perl/tmp/'; |
my $filename = $ENV{'user.name'}.'_'.$ENV{'user.domain'}. |
my $filename = $ENV{'user.name'}.'_'.$ENV{'user.domain'}. |
'_'.time.'_'.$$.$randnumber.'_plot.data'; |
'_'.time.'_'.$$.$randnumber.'_plot'; |
## Write the plot description to the file |
## Write the plot description to the file |
&write_gnuplot_file($tmpdir,$filename,$target); |
&write_gnuplot_file($tmpdir,$filename,$target); |
$filename = &Apache::lonnet::escape($filename); |
$filename = &Apache::lonnet::escape($filename); |
## return image tag for the plot |
## return image tag for the plot |
if ($target eq 'web') { |
if ($target eq 'web') { |
$result .= <<"ENDIMAGE"; |
$result .= <<"ENDIMAGE"; |
<img src = "/cgi-bin/plot.gif?file=$filename&output=gif" |
<img src = "/cgi-bin/plot.gif?file=$filename.data&output=gif" |
width = "$plot{'width'}" |
width = "$plot{'width'}" |
height = "$plot{'height'}" |
height = "$plot{'height'}" |
align = "$plot{'align'}" |
align = "$plot{'align'}" |
alt = "image should be /cgi-bin/plot.gif?$filename" /> |
alt = "$plot{'alttag'}" /> |
ENDIMAGE |
ENDIMAGE |
} elsif ($target eq 'tex') { |
} elsif ($target eq 'tex') { |
&Apache::lonnet::ssi('cgi-bin/plot.gif?file=$filename'. |
&Apache::lonnet::ssi("/cgi-bin/plot.gif?file=$filename&output=eps"); |
'&output=eps'); |
$result = '\\\\ \graphicspath{/home/httpd/perl/tmp/}\fbox{\includegraphics[width=9.0 cm]{'.&Apache::lonnet::unescape($filename).'.eps}} \\\\'; |
$result = "$filename.eps"; |
|
} |
} |
} elsif ($target eq 'edit') { |
} elsif ($target eq 'edit') { |
$result.=&Apache::edit::tag_end($target,$token); |
$result.=&Apache::edit::tag_end($target,$token); |
Line 610 sub start_title {
|
Line 617 sub start_title {
|
my $text=&Apache::lonxml::get_all_text("/title",$$parser[-1]); |
my $text=&Apache::lonxml::get_all_text("/title",$$parser[-1]); |
$result.=&Apache::edit::end_row(). |
$result.=&Apache::edit::end_row(). |
&Apache::edit::start_spanning_row(). |
&Apache::edit::start_spanning_row(). |
&Apache::edit::textfield('',$text,'',60); |
&Apache::edit::editline('',$text,'',60); |
} 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::rebuild_tag($token); |
Line 644 sub start_xlabel {
|
Line 651 sub start_xlabel {
|
my $text=&Apache::lonxml::get_all_text("/xlabel",$$parser[-1]); |
my $text=&Apache::lonxml::get_all_text("/xlabel",$$parser[-1]); |
$result.=&Apache::edit::end_row(). |
$result.=&Apache::edit::end_row(). |
&Apache::edit::start_spanning_row(). |
&Apache::edit::start_spanning_row(). |
&Apache::edit::textfield('',$text,'',60); |
&Apache::edit::editline('',$text,'',60); |
} 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::rebuild_tag($token); |
Line 679 sub start_ylabel {
|
Line 686 sub start_ylabel {
|
my $text = &Apache::lonxml::get_all_text("/ylabel",$$parser[-1]); |
my $text = &Apache::lonxml::get_all_text("/ylabel",$$parser[-1]); |
$result .= &Apache::edit::end_row(). |
$result .= &Apache::edit::end_row(). |
&Apache::edit::start_spanning_row(). |
&Apache::edit::start_spanning_row(). |
&Apache::edit::textfield('',$text,'',60); |
&Apache::edit::editline('',$text,'',60); |
} 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::rebuild_tag($token); |
Line 718 sub start_label {
|
Line 725 sub start_label {
|
my $text = &Apache::lonxml::get_all_text("/label",$$parser[-1]); |
my $text = &Apache::lonxml::get_all_text("/label",$$parser[-1]); |
$result .= &Apache::edit::end_row(). |
$result .= &Apache::edit::end_row(). |
&Apache::edit::start_spanning_row(). |
&Apache::edit::start_spanning_row(). |
&Apache::edit::textfield('',$text,'',60); |
&Apache::edit::editline('',$text,'',60); |
} elsif ($target eq 'modified') { |
} elsif ($target eq 'modified') { |
&Apache::edit::get_new_args |
&Apache::edit::get_new_args |
($token,$parstack,$safeeval,keys(%label_defaults)); |
($token,$parstack,$safeeval,keys(%label_defaults)); |
Line 795 sub start_function {
|
Line 802 sub start_function {
|
my $text = &Apache::lonxml::get_all_text("/function",$$parser[-1]); |
my $text = &Apache::lonxml::get_all_text("/function",$$parser[-1]); |
$result .= &Apache::edit::end_row(). |
$result .= &Apache::edit::end_row(). |
&Apache::edit::start_spanning_row(). |
&Apache::edit::start_spanning_row(). |
&Apache::edit::textfield('',$text,'',60); |
&Apache::edit::editline('',$text,'',60); |
} elsif ($target eq 'modified') { |
} elsif ($target eq 'modified') { |
$result.=&Apache::edit::rebuild_tag($token); |
$result.=&Apache::edit::rebuild_tag($token); |
my $text=$$parser[-1]->get_text("/function"); |
my $text=$$parser[-1]->get_text("/function"); |
Line 871 sub start_data {
|
Line 878 sub start_data {
|
my $text = &Apache::lonxml::get_all_text("/data",$$parser[-1]); |
my $text = &Apache::lonxml::get_all_text("/data",$$parser[-1]); |
$result .= &Apache::edit::end_row(). |
$result .= &Apache::edit::end_row(). |
&Apache::edit::start_spanning_row(). |
&Apache::edit::start_spanning_row(). |
&Apache::edit::textfield('',$text,'',60); |
&Apache::edit::editline('',$text,'',60); |
} elsif ($target eq 'modified') { |
} elsif ($target eq 'modified') { |
$result.=&Apache::edit::rebuild_tag($token); |
$result.=&Apache::edit::rebuild_tag($token); |
my $text=$$parser[-1]->get_text("/data"); |
my $text=$$parser[-1]->get_text("/data"); |
Line 899 sub start_axis {
|
Line 906 sub start_axis {
|
$tagstack->[-1]); |
$tagstack->[-1]); |
} elsif ($target eq 'edit') { |
} elsif ($target eq 'edit') { |
$result .= &Apache::edit::tag_start($target,$token,'Plot Axes'); |
$result .= &Apache::edit::tag_start($target,$token,'Plot Axes'); |
$result .= &edit_attributes($target,$token,\%axis_defaults); |
$result .= &edit_attributes($target,$token,\%axis_defaults, |
|
\@axis_edit_order); |
} 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 983 sub write_gnuplot_file {
|
Line 991 sub write_gnuplot_file {
|
$gnuplot_input .= "set output\n"; |
$gnuplot_input .= "set output\n"; |
} elsif ($target eq 'tex') { |
} elsif ($target eq 'tex') { |
$gnuplot_input .= "set term postscript eps monochrome\n"; |
$gnuplot_input .= "set term postscript eps monochrome\n"; |
$gnuplot_input .= "set output \"$filename.eps\"\n"; |
$gnuplot_input .= "set output \"/home/httpd/perl/tmp/". |
|
&Apache::lonnet::unescape($filename).".eps\"\n"; |
} |
} |
# grid |
# grid |
$gnuplot_input .= 'set grid'.$/ if ($plot{'grid'} eq 'on'); |
$gnuplot_input .= 'set grid'.$/ if ($plot{'grid'} eq 'on'); |
# border |
# border |
$gnuplot_input .= ($plot{'border'} eq 'on'? |
$gnuplot_input .= ($plot{'border'} eq 'on'? |
'set border'.$/ : |
'set border'.$/ : |
'set noborder'.$/ ); # title, xlabel, ylabel |
'set noborder'.$/ ); |
|
# title, xlabel, ylabel |
# titles |
# titles |
$gnuplot_input .= "set title \"$title\"\n" if (defined($title)) ; |
$gnuplot_input .= "set title \"$title\"\n" if (defined($title)) ; |
$gnuplot_input .= "set xlabel \"$xlabel\"\n" if (defined($xlabel)); |
$gnuplot_input .= "set xlabel \"$xlabel\"\n" if (defined($xlabel)); |
Line 1019 sub write_gnuplot_file {
|
Line 1029 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 { |