[LON-CAPA-cvs] cvs: loncom /xml lonplot.pm
albertel
lon-capa-cvs-allow@mail.lon-capa.org
Tue, 19 Jun 2007 01:15:24 -0000
albertel Mon Jun 18 21:15:24 2007 EDT
Modified files:
/loncom/xml lonplot.pm
Log:
- reenable line width setting,
- add code for font point sizes, not actually working yet until ttf fonts are specified
Index: loncom/xml/lonplot.pm
diff -u loncom/xml/lonplot.pm:1.118 loncom/xml/lonplot.pm:1.119
--- loncom/xml/lonplot.pm:1.118 Thu Jun 7 19:42:14 2007
+++ loncom/xml/lonplot.pm Mon Jun 18 21:15:24 2007
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Dynamic plot
#
-# $Id: lonplot.pm,v 1.118 2007/06/07 23:42:14 albertel Exp $
+# $Id: lonplot.pm,v 1.119 2007/06/19 01:15:24 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -117,7 +117,7 @@
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)$/};
+my $sml_test = sub {$_[0]=~/^(\d+|small|medium|large)$/};
my $linestyle_test = sub {exists($linestyles{$_[0]})};
my $words_test = sub {$_[0]=~s/\s+/ /g;$_[0]=~/^([\w~!\@\#\$\%^&\*\(\)-=_\+\[\]\{\}:\;\'<>,\.\/\?\\]+ ?)+$/};
@@ -203,11 +203,11 @@
edit_type => 'onoff'
},
font => {
- default => 'medium',
+ default => '9',
test => $sml_test,
description => 'Size of font to use',
edit_type => 'choice',
- choices => ['small','medium','large']
+ choices => [['5','5 (small)'],'7',['9','9 (medium)'],'10','12',['15','15 (large)']]
},
samples => {
default => '100',
@@ -467,7 +467,7 @@
}
);
-my @curve_edit_order = ('color','name','linestyle','pointtype','pointsize','limit');
+my @curve_edit_order = ('color','name','linestyle','linewidth','pointtype','pointsize','limit');
my %curve_defaults =
(
@@ -492,14 +492,13 @@
edit_type => 'choice',
choices => [keys(%linestyles)]
},
-# gnuplots term=gif driver does not handle linewidth :(
-# linewidth => {
-# default => 1,
-# test => $int_test,
-# description => 'Line width (may not apply to all line styles)',
-# edit_type => 'choice',
-# choices => [1,2,3,4,5,6,7,8,9,10]
-# },
+ linewidth => {
+ default => 4,
+ test => $int_test,
+ description => 'Line width (may not apply to all line styles)',
+ edit_type => 'choice',
+ choices => [1,2,3,4,5,6,7,8,9,10]
+ },
pointsize => {
default => 1,
test => $pos_real_test,
@@ -674,6 +673,24 @@
return $result;
}
+##-----------------------------------------------------------------font
+sub get_font {
+ my ($size);
+ if ( $Apache::lonplot::plot{'font'} =~ /^(small|medium|large)/) {
+ if ( $Apache::lonplot::plot{'font'} eq 'small') {
+ $size = '5';
+ } elsif ( $Apache::lonplot::plot{'font'} eq 'medium') {
+ $size = '9';
+ } elsif ( $Apache::lonplot::plot{'font'} eq 'large') {
+ $size = '15';
+ } else {
+ $size = '9';
+ }
+ } else {
+ $size = $Apache::lonplot::plot{'font'};
+ }
+ return ($size);
+}
##----------------------------------------------------------------- key
sub start_key {
@@ -1102,7 +1119,7 @@
}
# set term
if ($target eq 'web') {
- $gnuplot_input .= 'set term '.$weboutputformat .' ';
+ $gnuplot_input .= 'set term '.$weboutputformat .' enhanced ';
$gnuplot_input .= 'transparent ' if ($Apache::lonplot::plot{'transparent'} eq 'on');
$gnuplot_input .= $Apache::lonplot::plot{'font'} . ' ';
$gnuplot_input .= 'size '.$Apache::lonplot::plot{'width'}.','.$Apache::lonplot::plot{'height'}.' ';
@@ -1110,7 +1127,7 @@
# set output
$gnuplot_input .= "set output\n";
} elsif ($target eq 'tex') {
- $gnuplot_input .= "set term postscript eps $Apache::lonplot::plot{'plotcolor'} solid \"Helvetica\" $pt \n";
+ $gnuplot_input .= "set term postscript eps enhanced $Apache::lonplot::plot{'plotcolor'} solid \"Helvetica\" $pt \n";
$gnuplot_input .= "set output \"/home/httpd/perl/tmp/".
&unescape($filename).".eps\"\n";
}
@@ -1239,12 +1256,16 @@
for (my $i = 0;$i<=$#curves;$i++) {
$curve = $curves[$i];
$gnuplot_input.= ', ' if ($i > 0);
+ if ($target eq 'tex') {
+ $curve->{'linewidth'} *= 2;
+ }
if (exists($curve->{'function'})) {
$gnuplot_input.=
$curve->{'function'}.' title "'.
$curve->{'name'}.'" with '.
$curve->{'linestyle'};
- $gnuplot_input.= ' linewidth 4 ' if ($target eq 'tex');
+ $gnuplot_input.= ' linewidth '.$curve->{'linewidth'};
+
if (($curve->{'linestyle'} eq 'points') ||
($curve->{'linestyle'} eq 'linespoints') ||
($curve->{'linestyle'} eq 'errorbars') ||
@@ -1274,12 +1295,12 @@
}
# write file
print $fh $datatext;
- close ($fh);
+ close($fh);
# generate gnuplot text
$gnuplot_input.= '"'.$datafilename.'" title "'.
$curve->{'name'}.'" with '.
$curve->{'linestyle'};
- $gnuplot_input.= ' linewidth 4 ' if ($target eq 'tex');
+ $gnuplot_input.= ' linewidth '.$curve->{'linewidth'};
if (($curve->{'linestyle'} eq 'points') ||
($curve->{'linestyle'} eq 'linespoints') ||
($curve->{'linestyle'} eq 'errorbars') ||