version 1.67, 2002/04/24 21:24:40
|
version 1.77, 2002/06/13 17:58:47
|
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/alttag bgcolor fgcolor height width font transparent grid border align/; |
qw/alttag bgcolor fgcolor height width font transparent grid samples border align/; |
|
|
my $gnuplot_help_text = <<"ENDPLOTHELP"; |
my $gnuplot_help_text = <<"ENDPLOTHELP"; |
<p> |
<p> |
Line 208 my %gnuplot_defaults =
|
Line 208 my %gnuplot_defaults =
|
edit_type => 'choice', |
edit_type => 'choice', |
choices => ['small','medium','large'] |
choices => ['small','medium','large'] |
}, |
}, |
|
samples => { |
|
default => '100', |
|
test => $int_test, |
|
description => 'Number of samples for non-data plots', |
|
edit_type => 'choice', |
|
choices => ['100','200','500','1000','2000','5000'] |
|
}, |
align => { |
align => { |
default => 'center', |
default => 'center', |
test => sub {$_[0]=~/^(left|right|center)$/}, |
test => sub {$_[0]=~/^(left|right|center)$/}, |
Line 484 sub end_gnuplot {
|
Line 491 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 = "$plot{'alttag'}" /> |
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.data&output=eps"); |
'&output=eps'); |
$result = '\graphicspath{{/home/httpd/perl/tmp/}}\fbox{\includegraphics{'.&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 991 sub write_gnuplot_file {
|
Line 997 sub write_gnuplot_file {
|
# set output |
# set output |
$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 solid\n"; |
$gnuplot_input .= "set output \"/home/httpd/perl/tmp/$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'); |
Line 1000 sub write_gnuplot_file {
|
Line 1007 sub write_gnuplot_file {
|
$gnuplot_input .= ($plot{'border'} eq 'on'? |
$gnuplot_input .= ($plot{'border'} eq 'on'? |
'set border'.$/ : |
'set border'.$/ : |
'set noborder'.$/ ); |
'set noborder'.$/ ); |
|
# sampling rate for non-data curves |
|
$gnuplot_input .= "set samples $plot{'samples'}\n"; |
# title, xlabel, ylabel |
# title, xlabel, ylabel |
# titles |
# titles |
$gnuplot_input .= "set title \"$title\"\n" if (defined($title)) ; |
$gnuplot_input .= "set title \"$title\"\n" if (defined($title)) ; |
Line 1041 sub write_gnuplot_file {
|
Line 1050 sub write_gnuplot_file {
|
$gnuplot_input .= 'set label "'.$label->{'text'}.'" at '. |
$gnuplot_input .= 'set label "'.$label->{'text'}.'" at '. |
$label->{'xpos'}.','.$label->{'ypos'}.' '.$label->{'justify'}.$/ ; |
$label->{'xpos'}.','.$label->{'ypos'}.' '.$label->{'justify'}.$/ ; |
} |
} |
|
if ($target eq 'tex') { |
|
$gnuplot_input .="set size 1,".$plot{'height'}/$plot{'width'}*1.38; |
|
$gnuplot_input .="\n"; |
|
} |
# curves |
# curves |
$gnuplot_input .= 'plot '; |
$gnuplot_input .= 'plot '; |
for (my $i = 0;$i<=$#curves;$i++) { |
for (my $i = 0;$i<=$#curves;$i++) { |
Line 1050 sub write_gnuplot_file {
|
Line 1063 sub write_gnuplot_file {
|
$gnuplot_input.= |
$gnuplot_input.= |
$curve->{'function'}.' title "'. |
$curve->{'function'}.' title "'. |
$curve->{'name'}.'" with '. |
$curve->{'name'}.'" with '. |
$curve->{'linestyle'}; |
$curve->{'linestyle'}; |
# |
$gnuplot_input.= ' linewidth 4 ' if ($target eq 'tex'); |
# gnuplot's term=gif driver does not handle linewidths :( |
|
# . ' linewidth '. $curve->{'linewidth'}; |
|
# |
|
if (($curve->{'linestyle'} eq 'points') || |
if (($curve->{'linestyle'} eq 'points') || |
($curve->{'linestyle'} eq 'linespoints') || |
($curve->{'linestyle'} eq 'linespoints') || |
($curve->{'linestyle'} eq 'errorbars') || |
($curve->{'linestyle'} eq 'errorbars') || |
Line 1068 sub write_gnuplot_file {
|
Line 1078 sub write_gnuplot_file {
|
# Store data values in $datatext |
# Store data values in $datatext |
my $datatext = ''; |
my $datatext = ''; |
# get new filename |
# get new filename |
my $datafilename = "$tmpdir/$filename.$i"; |
my $datafilename = "$tmpdir/$filename.data.$i"; |
my $fh=Apache::File->new(">$datafilename"); |
my $fh=Apache::File->new(">$datafilename"); |
# Compile data |
# Compile data |
my @Data = @{$curve->{'data'}}; |
my @Data = @{$curve->{'data'}}; |
Line 1087 sub write_gnuplot_file {
|
Line 1097 sub write_gnuplot_file {
|
$gnuplot_input.= '"'.$datafilename.'" title "'. |
$gnuplot_input.= '"'.$datafilename.'" title "'. |
$curve->{'name'}.'" with '. |
$curve->{'name'}.'" with '. |
$curve->{'linestyle'}; |
$curve->{'linestyle'}; |
|
$gnuplot_input.= ' linewidth 4 ' if ($target eq 'tex'); |
if (($curve->{'linestyle'} eq 'points') || |
if (($curve->{'linestyle'} eq 'points') || |
($curve->{'linestyle'} eq 'linespoints') || |
($curve->{'linestyle'} eq 'linespoints') || |
($curve->{'linestyle'} eq 'errorbars') || |
($curve->{'linestyle'} eq 'errorbars') || |
Line 1099 sub write_gnuplot_file {
|
Line 1110 sub write_gnuplot_file {
|
} |
} |
} |
} |
# Write the output to a file. |
# Write the output to a file. |
my $fh=Apache::File->new(">$tmpdir$filename"); |
my $fh=Apache::File->new(">$tmpdir$filename.data"); |
print $fh $gnuplot_input; |
print $fh $gnuplot_input; |
close($fh); |
close($fh); |
# That's all folks. |
# That's all folks. |