--- loncom/xml/lonplot.pm 2002/04/25 17:23:10 1.68 +++ loncom/xml/lonplot.pm 2003/01/16 02:55:05 1.80 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Dynamic plot # -# $Id: lonplot.pm,v 1.68 2002/04/25 17:23:10 sakharuk Exp $ +# $Id: lonplot.pm,v 1.80 2003/01/16 02:55:05 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -99,7 +99,7 @@ my $real_test = sub {$_[0]=~s/\s+//g;$_[0]=~/^[+-]?\d*\.?\d*([eE][+-]\d+)?$/}; my $pos_real_test = sub {$_[0]=~s/\s+//g;$_[0]=~/^[+]?\d*\.?\d*([eE][+-]\d+)?$/}; -my $color_test = sub {$_[0]=~s/\s+//g;$_[0]=~/^x[\da-f]{6}$/}; +my $color_test = sub {$_[0]=~s/\s+//g;$_[0]=~/^x[\da-fA-F]{6}$/}; my $onoff_test = sub {$_[0]=~/^(on|off)$/}; my $key_pos_test = sub {$_[0]=~/^(top|bottom|right|left|outside|below| )+$/}; my $sml_test = sub {$_[0]=~/^(small|medium|large)$/}; @@ -112,7 +112,7 @@ my $words_test = sub {$_[0]=~s/\s+/ ## ## ################################################################### 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";
@@ -208,6 +208,13 @@ my %gnuplot_defaults =
edit_type => 'choice',
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 => {
default => 'center',
test => sub {$_[0]=~/^(left|right|center)$/},
@@ -312,7 +319,7 @@ my %axis_defaults =
color => {
default => 'x000000',
test => $color_test,
- description => 'color of axes (x000000)',
+ description => 'color of grid lines (x000000)',
edit_type => 'entry',
size => '10'
},
@@ -484,22 +491,22 @@ sub end_gnuplot {
## Determine filename
my $tmpdir = '/home/httpd/perl/tmp/';
my $filename = $ENV{'user.name'}.'_'.$ENV{'user.domain'}.
- '_'.time.'_'.$$.$randnumber.'_plot.data';
+ '_'.time.'_'.$$.$randnumber.'_plot';
## Write the plot description to the file
&write_gnuplot_file($tmpdir,$filename,$target);
$filename = &Apache::lonnet::escape($filename);
## return image tag for the plot
if ($target eq 'web') {
$result .= <<"ENDIMAGE";
-
ENDIMAGE
} elsif ($target eq 'tex') {
- &Apache::lonnet::ssi("/cgi-bin/plot.gif?file=$filename&output=eps");
- $result = '\\\\ \graphicspath{/home/httpd/perl/tmp/}\fbox{\includegraphics[width=9.0 cm]{'.&Apache::lonnet::unescape($filename).'.eps}} \\\\';
+ &Apache::lonnet::ssi("/cgi-bin/plot.gif?file=$filename.data&output=eps");
+ $result = '\graphicspath{{/home/httpd/perl/tmp/}}\includegraphics{'.&Apache::lonnet::unescape($filename).'.eps}';
}
} elsif ($target eq 'edit') {
$result.=&Apache::edit::tag_end($target,$token);
@@ -990,7 +997,7 @@ sub write_gnuplot_file {
# set output
$gnuplot_input .= "set output\n";
} 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/".
&Apache::lonnet::unescape($filename).".eps\"\n";
}
@@ -1000,6 +1007,8 @@ sub write_gnuplot_file {
$gnuplot_input .= ($plot{'border'} eq 'on'?
'set border'.$/ :
'set noborder'.$/ );
+ # sampling rate for non-data curves
+ $gnuplot_input .= "set samples $plot{'samples'}\n";
# title, xlabel, ylabel
# titles
$gnuplot_input .= "set title \"$title\"\n" if (defined($title)) ;
@@ -1041,6 +1050,10 @@ sub write_gnuplot_file {
$gnuplot_input .= 'set label "'.$label->{'text'}.'" at '.
$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
$gnuplot_input .= 'plot ';
for (my $i = 0;$i<=$#curves;$i++) {
@@ -1050,11 +1063,8 @@ sub write_gnuplot_file {
$gnuplot_input.=
$curve->{'function'}.' title "'.
$curve->{'name'}.'" with '.
- $curve->{'linestyle'};
-#
-# gnuplot's term=gif driver does not handle linewidths :(
-# . ' linewidth '. $curve->{'linewidth'};
-#
+ $curve->{'linestyle'};
+ $gnuplot_input.= ' linewidth 4 ' if ($target eq 'tex');
if (($curve->{'linestyle'} eq 'points') ||
($curve->{'linestyle'} eq 'linespoints') ||
($curve->{'linestyle'} eq 'errorbars') ||
@@ -1068,7 +1078,7 @@ sub write_gnuplot_file {
# Store data values in $datatext
my $datatext = '';
# get new filename
- my $datafilename = "$tmpdir/$filename.$i";
+ my $datafilename = "$tmpdir/$filename.data.$i";
my $fh=Apache::File->new(">$datafilename");
# Compile data
my @Data = @{$curve->{'data'}};
@@ -1087,6 +1097,7 @@ sub write_gnuplot_file {
$gnuplot_input.= '"'.$datafilename.'" title "'.
$curve->{'name'}.'" with '.
$curve->{'linestyle'};
+ $gnuplot_input.= ' linewidth 4 ' if ($target eq 'tex');
if (($curve->{'linestyle'} eq 'points') ||
($curve->{'linestyle'} eq 'linespoints') ||
($curve->{'linestyle'} eq 'errorbars') ||
@@ -1099,7 +1110,7 @@ sub write_gnuplot_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;
close($fh);
# That's all folks.