version 1.47, 2002/02/05 15:05:44
|
version 1.58, 2002/03/22 13:45:59
|
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 |
# 01/21 02/05 02/06 2/28Matthew |
|
|
package Apache::lonplot; |
package Apache::lonplot; |
|
|
Line 115 my $words_test = sub {$_[0]=~s/\s+/
|
Line 115 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/bgcolor fgcolor height width font transparent grid border align/; |
|
|
|
my $gnuplot_help_text = <<"ENDPLOTHELP"; |
|
<p> |
|
The <b>gnuplot</b> tag allows an author to design a plot which can |
|
be created on the fly. This is intended for use in homework problems |
|
where each student needs to see a distinct plot. It can be used in |
|
conjunction with a <b>script</b> tag to generate random plots. |
|
</p><p> |
|
A <b>gnuplot</b> tag can contain the following sub-tags: |
|
</p> |
|
<dl> |
|
<dt> Plot Label |
|
<dd> Allows you to place text at a given (x,y) coordinate on the plot. |
|
<dt> Plot Title |
|
<dd> The title of the plot |
|
<dt> Plot Xlabel |
|
<dd> The label on the horizontal axis of the plot |
|
<dt> Plot Ylabel |
|
<dd> The label on the vertical axis of the plot |
|
<dt> Plot Axes |
|
<dd> allows specification of the x and y ranges displayed in the plot |
|
<dt> Plot Key |
|
<dd> Lists the functions displayed in the plot. |
|
<dt> Plot Curve |
|
<dd> Sets the data used in the plot. |
|
<dt> Plot Tics |
|
<dd> Allows specification of the x and y coordinate 'tics' on the axes. |
|
This is mostly used to adjust the grid lines when a grid is displayed. |
|
</dl> |
|
If you are having trouble with your plot, please read the help |
|
available on Plot Curve. |
|
ENDPLOTHELP |
|
|
my %gnuplot_defaults = |
my %gnuplot_defaults = |
( |
( |
height => { |
height => { |
Line 307 my %axis_defaults =
|
Line 340 my %axis_defaults =
|
} |
} |
); |
); |
|
|
|
my $curve_help_text = <<"ENDCURVEHELP"; |
|
The <b>curve</b> tag is where you set the data to be plotted by gnuplot. |
|
There are two ways of entering the information: |
|
<dl> |
|
<dt> Curve Data |
|
<dd> Using a <b>data</b> tag you can specify the numbers used to produce |
|
the plot. |
|
<p> |
|
By default, two <b>data</b> tags will be available in a plot. The |
|
first will specify X coordinates of the data and the second will |
|
give the Y coordinates of the data. When working with a linestyle that |
|
requires more than two data sets, inserting another <b>data</b> tag is |
|
required. Unfortunately, you must make sure the <b>data</b> tags appear |
|
in the order gnuplot expects the data. |
|
</p><p> |
|
Specifying the data should usually be done with a perl variable or array, |
|
such as \@Xdata and \@Ydata. You may also specify numerical data seperated |
|
by commas. Again, the order of the <b>data</b> tags is important. The |
|
first tag will be the X data and the second will be the Y data. |
|
</p> |
|
<dt> Curve Function |
|
<dd> The <b>function</b> tag allows you to specify the curve to be |
|
plotted as a formula that gnuplot can understand. <b>Be careful using this |
|
tag.</b> It is surprisingly easy to give gnuplot a function it cannot deal |
|
with properly. Be explicit: 2*sin(2*3.141592*x/4) will work but |
|
2sin(2*3.141592x/4) will not. If you do not receive any errors in the |
|
gnuplot data but still do not have an image produced, it is likely there |
|
is an error in your <b>function</b> tag. |
|
</dl> |
|
ENDCURVEHELP |
|
|
my %curve_defaults = |
my %curve_defaults = |
( |
( |
color => { |
color => { |
Line 351 sub start_gnuplot {
|
Line 415 sub start_gnuplot {
|
('title','xlabel','ylabel','key','axis','label','curve', |
('title','xlabel','ylabel','key','axis','label','curve', |
'xtics','ytics')); |
'xtics','ytics')); |
push (@Apache::lonxml::namespace,'lonplot'); |
push (@Apache::lonxml::namespace,'lonplot'); |
if ($target eq 'web') { |
if ($target eq 'web' || $target eq 'tex') { |
my $inside = &Apache::lonxml::get_all_text("/gnuplot",$$parser[-1]); |
|
$inside=&Apache::run::evaluate($inside,$safeeval,$$parstack[-1]); |
|
&Apache::lonxml::newparser($parser,\$inside); |
|
&get_attributes(\%plot,\%gnuplot_defaults,$parstack,$safeeval, |
&get_attributes(\%plot,\%gnuplot_defaults,$parstack,$safeeval, |
$tagstack->[-1]); |
$tagstack->[-1]); |
} elsif ($target eq 'edit') { |
} elsif ($target eq 'edit') { |
$result .= &Apache::edit::tag_start($target,$token,'GnuPlot'); |
$result .= &Apache::edit::tag_start($target,$token,'GnuPlot'); |
|
$result .= &make_javascript(); |
|
$result .= &help_win($gnuplot_help_text); |
$result .= &edit_attributes($target,$token,\%gnuplot_defaults, |
$result .= &edit_attributes($target,$token,\%gnuplot_defaults, |
\@gnuplot_edit_order); |
\@gnuplot_edit_order); |
} elsif ($target eq 'modified') { |
} elsif ($target eq 'modified') { |
Line 377 sub end_gnuplot {
|
Line 440 sub end_gnuplot {
|
&Apache::lonxml::deregister('Apache::lonplot', |
&Apache::lonxml::deregister('Apache::lonplot', |
('title','xlabel','ylabel','key','axis','label','curve')); |
('title','xlabel','ylabel','key','axis','label','curve')); |
my $result = ''; |
my $result = ''; |
if ($target eq 'web') { |
my $randnumber; |
|
# need to call rand everytime start_script would evaluate, as the |
|
# safe space rand number generator and the global rand generator |
|
# are not seperate |
|
if ($target eq 'web' || $target eq 'tex' || $target eq 'grade' || |
|
$target eq 'answer') { |
|
$randnumber=int(rand(1000)); |
|
} |
|
if ($target eq 'web' || $target eq 'tex') { |
&check_inputs(); # Make sure we have all the data we need |
&check_inputs(); # Make sure we have all the data we need |
## |
## |
## 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.'_'.$$.int(rand(1000)).'_plot.data'; |
'_'.time.'_'.$$.$randnumber.'_plot.data'; |
## Write the plot description to the file |
## Write the plot description to the file |
&write_gnuplot_file($tmpdir,$filename); |
&write_gnuplot_file($tmpdir,$filename,$target); |
|
$filename = &Apache::lonnet::escape($filename); |
## return image tag for the plot |
## return image tag for the plot |
$result .= <<"ENDIMAGE"; |
if ($target eq 'web') { |
<img src = "/cgi-bin/plot.gif?$filename" |
$result .= <<"ENDIMAGE"; |
|
<img src = "/cgi-bin/plot.gif?file=$filename&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 = "image should be /cgi-bin/plot.gif?$filename" /> |
ENDIMAGE |
ENDIMAGE |
|
} elsif ($target eq 'tex') { |
|
&Apache::lonnet::ssi('cgi-bin/plot.gif?file=$filename'. |
|
'&output=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 405 ENDIMAGE
|
Line 483 ENDIMAGE
|
sub start_xtics { |
sub start_xtics { |
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; |
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; |
my $result=''; |
my $result=''; |
if ($target eq 'web') { |
if ($target eq 'web' || $target eq 'tex') { |
&get_attributes(\%xtics,\%tic_defaults,$parstack,$safeeval, |
&get_attributes(\%xtics,\%tic_defaults,$parstack,$safeeval, |
$tagstack->[-1]); |
$tagstack->[-1]); |
} elsif ($target eq 'edit') { |
} elsif ($target eq 'edit') { |
Line 425 sub start_xtics {
|
Line 503 sub start_xtics {
|
sub end_xtics { |
sub end_xtics { |
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; |
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; |
my $result = ''; |
my $result = ''; |
if ($target eq 'web') { |
if ($target eq 'web' || $target eq 'tex') { |
} elsif ($target eq 'edit') { |
} elsif ($target eq 'edit') { |
$result.=&Apache::edit::tag_end($target,$token); |
$result.=&Apache::edit::tag_end($target,$token); |
} |
} |
Line 436 sub end_xtics {
|
Line 514 sub end_xtics {
|
sub start_ytics { |
sub start_ytics { |
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; |
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; |
my $result=''; |
my $result=''; |
if ($target eq 'web') { |
if ($target eq 'web' || $target eq 'tex') { |
&get_attributes(\%ytics,\%tic_defaults,$parstack,$safeeval, |
&get_attributes(\%ytics,\%tic_defaults,$parstack,$safeeval, |
$tagstack->[-1]); |
$tagstack->[-1]); |
} elsif ($target eq 'edit') { |
} elsif ($target eq 'edit') { |
Line 456 sub start_ytics {
|
Line 534 sub start_ytics {
|
sub end_ytics { |
sub end_ytics { |
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; |
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; |
my $result = ''; |
my $result = ''; |
if ($target eq 'web') { |
if ($target eq 'web' || $target eq 'tex') { |
} elsif ($target eq 'edit') { |
} elsif ($target eq 'edit') { |
$result.=&Apache::edit::tag_end($target,$token); |
$result.=&Apache::edit::tag_end($target,$token); |
} |
} |
Line 468 sub end_ytics {
|
Line 546 sub end_ytics {
|
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=''; |
if ($target eq 'web') { |
if ($target eq 'web' || $target eq 'tex') { |
&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') { |
Line 487 sub start_key {
|
Line 565 sub start_key {
|
sub end_key { |
sub end_key { |
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; |
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; |
my $result = ''; |
my $result = ''; |
if ($target eq 'web') { |
if ($target eq 'web' || $target eq 'tex') { |
} elsif ($target eq 'edit') { |
} elsif ($target eq 'edit') { |
$result.=&Apache::edit::tag_end($target,$token); |
$result.=&Apache::edit::tag_end($target,$token); |
} |
} |
Line 498 sub end_key {
|
Line 576 sub end_key {
|
sub start_title { |
sub start_title { |
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; |
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; |
my $result=''; |
my $result=''; |
if ($target eq 'web') { |
if ($target eq 'web' || $target eq 'tex') { |
$title = &Apache::lonxml::get_all_text("/title",$$parser[-1]); |
$title = &Apache::lonxml::get_all_text("/title",$$parser[-1]); |
|
$title=&Apache::run::evaluate($title,$safeeval,$$parstack[-1]); |
|
$title =~ s/\n/ /g; |
if (length($title) > $max_str_len) { |
if (length($title) > $max_str_len) { |
$title = substr($title,0,$max_str_len); |
$title = substr($title,0,$max_str_len); |
} |
} |
Line 520 sub start_title {
|
Line 600 sub start_title {
|
sub end_title { |
sub end_title { |
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; |
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; |
my $result = ''; |
my $result = ''; |
if ($target eq 'web') { |
if ($target eq 'web' || $target eq 'tex') { |
} elsif ($target eq 'edit') { |
} elsif ($target eq 'edit') { |
$result.=&Apache::edit::tag_end($target,$token); |
$result.=&Apache::edit::tag_end($target,$token); |
} |
} |
Line 530 sub end_title {
|
Line 610 sub end_title {
|
sub start_xlabel { |
sub start_xlabel { |
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; |
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; |
my $result=''; |
my $result=''; |
if ($target eq 'web') { |
if ($target eq 'web' || $target eq 'tex') { |
$xlabel = &Apache::lonxml::get_all_text("/xlabel",$$parser[-1]); |
$xlabel = &Apache::lonxml::get_all_text("/xlabel",$$parser[-1]); |
|
$xlabel=&Apache::run::evaluate($xlabel,$safeeval,$$parstack[-1]); |
|
$xlabel =~ s/\n/ /g; |
if (length($xlabel) > $max_str_len) { |
if (length($xlabel) > $max_str_len) { |
$xlabel = substr($xlabel,0,$max_str_len); |
$xlabel = substr($xlabel,0,$max_str_len); |
} |
} |
Line 552 sub start_xlabel {
|
Line 634 sub start_xlabel {
|
sub end_xlabel { |
sub end_xlabel { |
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; |
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; |
my $result = ''; |
my $result = ''; |
if ($target eq 'web') { |
if ($target eq 'web' || $target eq 'tex') { |
} elsif ($target eq 'edit') { |
} elsif ($target eq 'edit') { |
$result.=&Apache::edit::tag_end($target,$token); |
$result.=&Apache::edit::tag_end($target,$token); |
} |
} |
Line 563 sub end_xlabel {
|
Line 645 sub end_xlabel {
|
sub start_ylabel { |
sub start_ylabel { |
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; |
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; |
my $result=''; |
my $result=''; |
if ($target eq 'web') { |
if ($target eq 'web' || $target eq 'tex') { |
$ylabel = &Apache::lonxml::get_all_text("/ylabel",$$parser[-1]); |
$ylabel = &Apache::lonxml::get_all_text("/ylabel",$$parser[-1]); |
|
$ylabel = &Apache::run::evaluate($ylabel,$safeeval,$$parstack[-1]); |
|
$ylabel =~ s/\n/ /g; |
if (length($ylabel) > $max_str_len) { |
if (length($ylabel) > $max_str_len) { |
$ylabel = substr($ylabel,0,$max_str_len); |
$ylabel = substr($ylabel,0,$max_str_len); |
} |
} |
Line 585 sub start_ylabel {
|
Line 669 sub start_ylabel {
|
sub end_ylabel { |
sub end_ylabel { |
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; |
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; |
my $result = ''; |
my $result = ''; |
if ($target eq 'web') { |
if ($target eq 'web' || $target eq 'tex') { |
} elsif ($target eq 'edit') { |
} elsif ($target eq 'edit') { |
$result.=&Apache::edit::tag_end($target,$token); |
$result.=&Apache::edit::tag_end($target,$token); |
} |
} |
Line 596 sub end_ylabel {
|
Line 680 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=''; |
if ($target eq 'web') { |
if ($target eq 'web' || $target eq 'tex') { |
my %label; |
my %label; |
&get_attributes(\%label,\%label_defaults,$parstack,$safeeval, |
&get_attributes(\%label,\%label_defaults,$parstack,$safeeval, |
$tagstack->[-1]); |
$tagstack->[-1]); |
my $text = &Apache::lonxml::get_all_text("/label",$$parser[-1]); |
my $text = &Apache::lonxml::get_all_text("/label",$$parser[-1]); |
|
$text = &Apache::run::evaluate($text,$safeeval,$$parstack[-1]); |
|
$text =~ s/\n/ /g; |
$text = substr($text,0,$max_str_len) if (length($text) > $max_str_len); |
$text = substr($text,0,$max_str_len) if (length($text) > $max_str_len); |
$label{'text'} = $text; |
$label{'text'} = $text; |
push(@labels,\%label); |
push(@labels,\%label); |
Line 624 sub start_label {
|
Line 710 sub start_label {
|
sub end_label { |
sub end_label { |
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; |
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; |
my $result = ''; |
my $result = ''; |
if ($target eq 'web') { |
if ($target eq 'web' || $target eq 'tex') { |
} elsif ($target eq 'edit') { |
} elsif ($target eq 'edit') { |
$result.=&Apache::edit::tag_end($target,$token); |
$result.=&Apache::edit::tag_end($target,$token); |
} |
} |
Line 637 sub start_curve {
|
Line 723 sub start_curve {
|
my $result=''; |
my $result=''; |
&Apache::lonxml::register('Apache::lonplot',('function','data')); |
&Apache::lonxml::register('Apache::lonplot',('function','data')); |
push (@Apache::lonxml::namespace,'curve'); |
push (@Apache::lonxml::namespace,'curve'); |
if ($target eq 'web') { |
if ($target eq 'web' || $target eq 'tex') { |
my %curve; |
my %curve; |
&get_attributes(\%curve,\%curve_defaults,$parstack,$safeeval, |
&get_attributes(\%curve,\%curve_defaults,$parstack,$safeeval, |
$tagstack->[-1]); |
$tagstack->[-1]); |
push (@curves,\%curve); |
push (@curves,\%curve); |
} elsif ($target eq 'edit') { |
} elsif ($target eq 'edit') { |
$result .= &Apache::edit::tag_start($target,$token,'Curve'); |
$result .= &Apache::edit::tag_start($target,$token,'Curve'); |
|
$result .= &help_win($curve_help_text); |
$result .= &edit_attributes($target,$token,\%curve_defaults); |
$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 |
Line 661 sub end_curve {
|
Line 748 sub end_curve {
|
my $result = ''; |
my $result = ''; |
pop @Apache::lonxml::namespace; |
pop @Apache::lonxml::namespace; |
&Apache::lonxml::deregister('Apache::lonplot',('function','data')); |
&Apache::lonxml::deregister('Apache::lonplot',('function','data')); |
if ($target eq 'web') { |
if ($target eq 'web' || $target eq 'tex') { |
} elsif ($target eq 'edit') { |
} elsif ($target eq 'edit') { |
$result.=&Apache::edit::tag_end($target,$token); |
$result.=&Apache::edit::tag_end($target,$token); |
} |
} |
Line 672 sub end_curve {
|
Line 759 sub end_curve {
|
sub start_function { |
sub start_function { |
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; |
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; |
my $result=''; |
my $result=''; |
if ($target eq 'web') { |
if ($target eq 'web' || $target eq 'tex') { |
if (exists($curves[-1]->{'data'})) { |
if (exists($curves[-1]->{'data'})) { |
&Apache::lonxml::warning('Use of <function> precludes use of <data>. The <data> will be omitted in favor of the <function> declaration.'); |
&Apache::lonxml::warning('Use of <function> precludes use of <data>. The <data> will be omitted in favor of the <function> declaration.'); |
delete $curves[-1]->{'data'} ; |
delete $curves[-1]->{'data'} ; |
} |
} |
$curves[-1]->{'function'} = |
my $function = &Apache::lonxml::get_all_text("/function",$$parser[-1]); |
&Apache::lonxml::get_all_text("/function",$$parser[-1]); |
$function = &Apache::run::evaluate($function,$safeeval,$$parstack[-1]); |
|
$curves[-1]->{'function'} = $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]); |
Line 696 sub start_function {
|
Line 784 sub start_function {
|
sub end_function { |
sub end_function { |
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; |
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; |
my $result = ''; |
my $result = ''; |
if ($target eq 'web') { |
if ($target eq 'web' || $target eq 'tex') { |
} elsif ($target eq 'edit') { |
} elsif ($target eq 'edit') { |
$result .= &Apache::edit::end_table(); |
$result .= &Apache::edit::end_table(); |
} |
} |
Line 707 sub end_function {
|
Line 795 sub end_function {
|
sub start_data { |
sub start_data { |
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; |
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; |
my $result=''; |
my $result=''; |
if ($target eq 'web') { |
if ($target eq 'web' || $target eq 'tex') { |
if (exists($curves[-1]->{'function'})) { |
if (exists($curves[-1]->{'function'})) { |
&Apache::lonxml::warning('Use of <data> precludes use of .'. |
&Apache::lonxml::warning('Use of <data> precludes use of .'. |
'<function>. The <function> will be omitted in favor of '. |
'<function>. The <function> will be omitted in favor of '. |
Line 715 sub start_data {
|
Line 803 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]); |
|
$datatext=&Apache::run::evaluate($datatext,$safeeval,$$parstack[-1]); |
# Deal with cases where we're given an array... |
# Deal with cases where we're given an array... |
if ($datatext =~ /^\@/) { |
if ($datatext =~ /^\@/) { |
$datatext = &Apache::run::run('return "'.$datatext.'"', |
$datatext = &Apache::run::run('return "'.$datatext.'"', |
$safeeval,1); |
$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 |
# is of the same length. |
# is of the same length. |
Line 771 sub start_data {
|
Line 860 sub start_data {
|
sub end_data { |
sub end_data { |
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; |
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; |
my $result = ''; |
my $result = ''; |
if ($target eq 'web') { |
if ($target eq 'web' || $target eq 'tex') { |
} elsif ($target eq 'edit') { |
} elsif ($target eq 'edit') { |
$result .= &Apache::edit::end_table(); |
$result .= &Apache::edit::end_table(); |
} |
} |
Line 782 sub end_data {
|
Line 871 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=''; |
if ($target eq 'web') { |
if ($target eq 'web' || $target eq 'tex') { |
&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') { |
Line 801 sub start_axis {
|
Line 890 sub start_axis {
|
sub end_axis { |
sub end_axis { |
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; |
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; |
my $result = ''; |
my $result = ''; |
if ($target eq 'web') { |
if ($target eq 'web' || $target eq 'tex') { |
} elsif ($target eq 'edit') { |
} elsif ($target eq 'edit') { |
$result.=&Apache::edit::tag_end($target,$token); |
$result.=&Apache::edit::tag_end($target,$token); |
} elsif ($target eq 'modified') { |
} elsif ($target eq 'modified') { |
Line 847 sub get_attributes{
|
Line 936 sub get_attributes{
|
|
|
##------------------------------------------------------- write_gnuplot_file |
##------------------------------------------------------- write_gnuplot_file |
sub write_gnuplot_file { |
sub write_gnuplot_file { |
my ($tmpdir,$filename)= @_; |
my ($tmpdir,$filename,$target)= @_; |
my $gnuplot_input = ''; |
my $gnuplot_input = ''; |
my $curve; |
my $curve; |
# Collect all the colors |
# Collect all the colors |
Line 861 sub write_gnuplot_file {
|
Line 950 sub write_gnuplot_file {
|
$plot{'fgcolor'} ); |
$plot{'fgcolor'} ); |
} |
} |
# set term |
# set term |
$gnuplot_input .= 'set term gif '; |
if ($target eq 'web') { |
$gnuplot_input .= 'transparent ' if ($plot{'transparent'} eq 'on'); |
$gnuplot_input .= 'set term gif '; |
$gnuplot_input .= $plot{'font'} . ' '; |
$gnuplot_input .= 'transparent ' if ($plot{'transparent'} eq 'on'); |
$gnuplot_input .= 'size '.$plot{'width'}.','.$plot{'height'}.' '; |
$gnuplot_input .= $plot{'font'} . ' '; |
$gnuplot_input .= "@Colors\n"; |
$gnuplot_input .= 'size '.$plot{'width'}.','.$plot{'height'}.' '; |
# set output |
$gnuplot_input .= "@Colors\n"; |
$gnuplot_input .= "set output\n"; |
# set output |
|
$gnuplot_input .= "set output\n"; |
|
} elsif ($target eq 'tex') { |
|
$gnuplot_input .= "set term postscript eps monochrome\n"; |
|
$gnuplot_input .= "set output \"$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 |
Line 1020 sub edit_attributes {
|
Line 1114 sub edit_attributes {
|
sub insert_gnuplot { |
sub insert_gnuplot { |
my $result = ''; |
my $result = ''; |
# plot attributes |
# plot attributes |
$result .= "<plot \n"; |
$result .= "<gnuplot \n"; |
foreach my $attr (keys(%gnuplot_defaults)) { |
foreach my $attr (keys(%gnuplot_defaults)) { |
$result .= " $attr=\"$gnuplot_defaults{$attr}->{'default'}\"\n"; |
$result .= " $attr=\"$gnuplot_defaults{$attr}->{'default'}\"\n"; |
} |
} |
Line 1032 sub insert_gnuplot {
|
Line 1126 sub insert_gnuplot {
|
# $result .= &insert_xlabel(); |
# $result .= &insert_xlabel(); |
# $result .= &insert_ylabel(); |
# $result .= &insert_ylabel(); |
$result .= &insert_curve(); |
$result .= &insert_curve(); |
# close up the <plot> |
# close up the <gnuplot> |
$result .= "</plot>\n"; |
$result .= "</gnuplot>\n"; |
return $result; |
return $result; |
} |
} |
|
|
Line 1122 sub insert_data {
|
Line 1216 sub insert_data {
|
} |
} |
|
|
##---------------------------------------------------------------------- |
##---------------------------------------------------------------------- |
|
# Javascript functions to display help for tags |
|
|
|
sub make_javascript { |
|
my $helpwindowwidth = 400; |
|
my $helpwindowheight = 400; |
|
my $result = ''; |
|
$result.=<<"ENDFUNCTION"; |
|
<script language="JavaScript"> |
|
function openWin(text) |
|
{ |
|
newWin = open("", "new_W", "width=$helpwindowwidth,height=$helpwindowheight,resizable=1,scrollbars=1"); |
|
newWin.document.open("text/html", "replace"); |
|
newWin.document.writeln(text); |
|
newWin.document.writeln('<center><a href=\"javascript:window.close()\">close this window</a></center>'); |
|
newWin.document.close(); |
|
} |
|
</script> |
|
ENDFUNCTION |
|
return $result; |
|
} |
|
|
|
sub help_win { |
|
my ($helptext)=@_; |
|
$helptext =~ s/\n/ /g; |
|
$helptext =~ s/\'/\\\'/g; |
|
my $result = ''; |
|
$result.=<<"ENDWIN"; |
|
<table width="100%"><tr><td align="right"> |
|
<a href="javascript:openWin('$helptext')">help</a> |
|
</td></tr></table><hr /> |
|
ENDWIN |
|
return $result; |
|
} |
|
##---------------------------------------------------------------------- |
1; |
1; |
__END__ |
__END__ |
|
|