version 1.114, 2006/09/06 19:26:15
|
version 1.119, 2007/06/19 01:15:24
|
Line 117 my $pos_real_test =
|
Line 117 my $pos_real_test =
|
my $color_test = sub {$_[0]=~s/\s+//g;$_[0]=~/^x[\da-fA-F]{6}$/}; |
my $color_test = sub {$_[0]=~s/\s+//g;$_[0]=~/^x[\da-fA-F]{6}$/}; |
my $onoff_test = sub {$_[0]=~/^(on|off)$/}; |
my $onoff_test = sub {$_[0]=~/^(on|off)$/}; |
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]=~/^(\d+|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 128 my $words_test = sub {$_[0]=~s/\s+/
|
Line 128 my $words_test = sub {$_[0]=~s/\s+/
|
################################################################### |
################################################################### |
my @gnuplot_edit_order = |
my @gnuplot_edit_order = |
qw/alttag bgcolor fgcolor height width font transparent grid samples |
qw/alttag bgcolor fgcolor height width font transparent grid samples |
border align texwidth texfont plotcolor plottype lmargin rmargin tmargin |
border align texwidth texfont plotcolor plottype gridtype lmargin rmargin |
bmargin major_ticscale minor_ticscale boxwidth gridlayer fillstyle |
tmargin bmargin major_ticscale minor_ticscale boxwidth gridlayer fillstyle |
pattern solid/; |
pattern solid/; |
|
|
my $margin_choices = ['default',0..20]; |
my $margin_choices = ['default',0..20]; |
Line 203 my %gnuplot_defaults =
|
Line 203 my %gnuplot_defaults =
|
edit_type => 'onoff' |
edit_type => 'onoff' |
}, |
}, |
font => { |
font => { |
default => 'medium', |
default => '9', |
test => $sml_test, |
test => $sml_test, |
description => 'Size of font to use', |
description => 'Size of font to use', |
edit_type => 'choice', |
edit_type => 'choice', |
choices => ['small','medium','large'] |
choices => [['5','5 (small)'],'7',['9','9 (medium)'],'10','12',['15','15 (large)']] |
}, |
}, |
samples => { |
samples => { |
default => '100', |
default => '100', |
Line 217 my %gnuplot_defaults =
|
Line 217 my %gnuplot_defaults =
|
choices => ['100','200','500','1000','2000','5000'] |
choices => ['100','200','500','1000','2000','5000'] |
}, |
}, |
align => { |
align => { |
default => 'center', |
default => 'middle', |
test => sub {$_[0]=~/^(left|right|center)$/}, |
test => sub {$_[0]=~/^(left|right|middle|center)$/}, |
description => 'alignment for image in html', |
description => 'alignment for image in html', |
edit_type => 'choice', |
edit_type => 'choice', |
choices => ['left','right','center'] |
choices => ['left','right','middle'] |
}, |
}, |
texwidth => { |
texwidth => { |
default => '93', |
default => '93', |
Line 272 my %gnuplot_defaults =
|
Line 272 my %gnuplot_defaults =
|
edit_type => 'choice', |
edit_type => 'choice', |
choices => ['Cartesian','Polar'] |
choices => ['Cartesian','Polar'] |
}, |
}, |
|
gridtype => { |
|
default => 'Cartesian', |
|
test => sub {$_[0]=~/^(Polar|Cartesian|Linear-Log|Log-Linear|Log-Log)$/}, |
|
description => 'Grid type:', |
|
edit_type => 'choice', |
|
choices => ['Cartesian','Polar','Linear-Log','Log-Linear','Log-Log'] |
|
}, |
lmargin => { |
lmargin => { |
default => 'default', |
default => 'default', |
test => sub {$_[0]=~/^(default|\d+)$/}, |
test => sub {$_[0]=~/^(default|\d+)$/}, |
Line 460 my %axis_defaults =
|
Line 467 my %axis_defaults =
|
} |
} |
); |
); |
|
|
my @curve_edit_order = ('color','name','linestyle','pointtype','pointsize','limit'); |
my @curve_edit_order = ('color','name','linestyle','linewidth','pointtype','pointsize','limit'); |
|
|
my %curve_defaults = |
my %curve_defaults = |
( |
( |
Line 485 my %curve_defaults =
|
Line 492 my %curve_defaults =
|
edit_type => 'choice', |
edit_type => 'choice', |
choices => [keys(%linestyles)] |
choices => [keys(%linestyles)] |
}, |
}, |
# gnuplots term=gif driver does not handle linewidth :( |
linewidth => { |
# linewidth => { |
default => 4, |
# default => 1, |
test => $int_test, |
# test => $int_test, |
description => 'Line width (may not apply to all line styles)', |
# description => 'Line width (may not apply to all line styles)', |
edit_type => 'choice', |
# edit_type => 'choice', |
choices => [1,2,3,4,5,6,7,8,9,10] |
# choices => [1,2,3,4,5,6,7,8,9,10] |
}, |
# }, |
|
pointsize => { |
pointsize => { |
default => 1, |
default => 1, |
test => $pos_real_test, |
test => $pos_real_test, |
Line 543 sub start_gnuplot {
|
Line 549 sub start_gnuplot {
|
} 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 .= &edit_attributes($target,$token,\%gnuplot_defaults, |
$result .= &edit_attributes($target,$token,\%gnuplot_defaults, |
\@gnuplot_edit_order); |
\@gnuplot_edit_order) |
|
.&Apache::edit::end_row() |
|
.&Apache::edit::start_spanning_row(); |
} 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(%gnuplot_defaults)); |
($token,$parstack,$safeeval,keys(%gnuplot_defaults)); |
Line 665 sub end_ytics {
|
Line 673 sub end_ytics {
|
return $result; |
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 |
##----------------------------------------------------------------- key |
sub start_key { |
sub start_key { |
Line 710 sub start_title {
|
Line 736 sub start_title {
|
} elsif ($target eq 'edit') { |
} elsif ($target eq 'edit') { |
$result.=&Apache::edit::tag_start($target,$token,'Plot Title'); |
$result.=&Apache::edit::tag_start($target,$token,'Plot Title'); |
my $text=&Apache::lonxml::get_all_text("/title",$parser,$style); |
my $text=&Apache::lonxml::get_all_text("/title",$parser,$style); |
$result.=&Apache::edit::end_row(). |
$result.=&Apache::edit::editline('',$text,'',60); |
&Apache::edit::start_spanning_row(). |
|
&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); |
$result.=&Apache::edit::modifiedfield("/title",$parser); |
$result.=&Apache::edit::modifiedfield("/title",$parser); |
Line 743 sub start_xlabel {
|
Line 767 sub start_xlabel {
|
} elsif ($target eq 'edit') { |
} elsif ($target eq 'edit') { |
$result.=&Apache::edit::tag_start($target,$token,'Plot Xlabel'); |
$result.=&Apache::edit::tag_start($target,$token,'Plot Xlabel'); |
my $text=&Apache::lonxml::get_all_text("/xlabel",$parser,$style); |
my $text=&Apache::lonxml::get_all_text("/xlabel",$parser,$style); |
$result.=&Apache::edit::end_row(). |
$result.=&Apache::edit::editline('',$text,'',60); |
&Apache::edit::start_spanning_row(). |
|
&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); |
$result.=&Apache::edit::modifiedfield("/xlabel",$parser); |
$result.=&Apache::edit::modifiedfield("/xlabel",$parser); |
Line 777 sub start_ylabel {
|
Line 799 sub start_ylabel {
|
} elsif ($target eq 'edit') { |
} elsif ($target eq 'edit') { |
$result .= &Apache::edit::tag_start($target,$token,'Plot Ylabel'); |
$result .= &Apache::edit::tag_start($target,$token,'Plot Ylabel'); |
my $text = &Apache::lonxml::get_all_text("/ylabel",$parser,$style); |
my $text = &Apache::lonxml::get_all_text("/ylabel",$parser,$style); |
$result .= &Apache::edit::end_row(). |
$result .= &Apache::edit::editline('',$text,'',60); |
&Apache::edit::start_spanning_row(). |
|
&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); |
$result.=&Apache::edit::modifiedfield("/ylabel",$parser); |
$result.=&Apache::edit::modifiedfield("/ylabel",$parser); |
Line 851 sub start_curve {
|
Line 871 sub start_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 .= &edit_attributes($target,$token,\%curve_defaults, |
$result .= &edit_attributes($target,$token,\%curve_defaults, |
\@curve_edit_order); |
\@curve_edit_order) |
|
.&Apache::edit::end_row() |
|
.&Apache::edit::start_spanning_row(); |
|
|
} 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(%curve_defaults)); |
($token,$parstack,$safeeval,keys(%curve_defaults)); |
if ($constructtag) { |
if ($constructtag) { |
$result = &Apache::edit::rebuild_tag($token); |
$result = &Apache::edit::rebuild_tag($token); |
$result.= &Apache::edit::handle_insert(); |
|
} |
} |
} |
} |
return $result; |
return $result; |
Line 895 sub start_function {
|
Line 917 sub start_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,$style); |
my $text = &Apache::lonxml::get_all_text("/function",$parser,$style); |
$result .= &Apache::edit::end_row(). |
$result .= &Apache::edit::editline('',$text,'',60); |
&Apache::edit::start_spanning_row(). |
|
&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); |
$result.=&Apache::edit::modifiedfield("/function",$parser); |
$result.=&Apache::edit::modifiedfield("/function",$parser); |
Line 972 sub start_data {
|
Line 992 sub start_data {
|
} elsif ($target eq 'edit') { |
} elsif ($target eq 'edit') { |
$result .= &Apache::edit::tag_start($target,$token,'Comma or space deliminated curve data'); |
$result .= &Apache::edit::tag_start($target,$token,'Comma or space deliminated curve data'); |
my $text = &Apache::lonxml::get_all_text("/data",$parser,$style); |
my $text = &Apache::lonxml::get_all_text("/data",$parser,$style); |
$result .= &Apache::edit::end_row(). |
$result .= &Apache::edit::editline('',$text,'',60); |
&Apache::edit::start_spanning_row(). |
|
&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); |
$result.=&Apache::edit::modifiedfield("/data",$parser); |
$result.=&Apache::edit::modifiedfield("/data",$parser); |
Line 1101 sub write_gnuplot_file {
|
Line 1119 sub write_gnuplot_file {
|
} |
} |
# set term |
# set term |
if ($target eq 'web') { |
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 .= 'transparent ' if ($Apache::lonplot::plot{'transparent'} eq 'on'); |
$gnuplot_input .= $Apache::lonplot::plot{'font'} . ' '; |
$gnuplot_input .= $Apache::lonplot::plot{'font'} . ' '; |
$gnuplot_input .= 'size '.$Apache::lonplot::plot{'width'}.','.$Apache::lonplot::plot{'height'}.' '; |
$gnuplot_input .= 'size '.$Apache::lonplot::plot{'width'}.','.$Apache::lonplot::plot{'height'}.' '; |
Line 1109 sub write_gnuplot_file {
|
Line 1127 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 $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/". |
$gnuplot_input .= "set output \"/home/httpd/perl/tmp/". |
&unescape($filename).".eps\"\n"; |
&unescape($filename).".eps\"\n"; |
} |
} |
# cartesian or polar? |
# cartesian or polar plot? |
if (lc($Apache::lonplot::plot{'plottype'}) eq 'polar') { |
if (lc($Apache::lonplot::plot{'plottype'}) eq 'polar') { |
$gnuplot_input .= 'set polar'.$/; |
$gnuplot_input .= 'set polar'.$/; |
} else { |
} else { |
# Assume Cartesian |
# Assume Cartesian |
} |
} |
|
# cartesian or polar grid? |
|
if (lc($Apache::lonplot::plot{'gridtype'}) eq 'polar') { |
|
$gnuplot_input .= 'set grid polar'.$/; |
|
} elsif (lc($Apache::lonplot::plot{'gridtype'}) eq 'linear-log') { |
|
$gnuplot_input .= 'set logscale x'.$/; |
|
} elsif (lc($Apache::lonplot::plot{'gridtype'}) eq 'log-linear') { |
|
$gnuplot_input .= 'set logscale y'.$/; |
|
} elsif (lc($Apache::lonplot::plot{'gridtype'}) eq 'log-log') { |
|
$gnuplot_input .= 'set logscale x'.$/; |
|
$gnuplot_input .= 'set logscale y'.$/; |
|
} else { |
|
# Assume Cartesian |
|
} |
# solid or pattern for boxes? |
# solid or pattern for boxes? |
if (lc($Apache::lonplot::plot{'fillstyle'}) eq 'solid') { |
if (lc($Apache::lonplot::plot{'fillstyle'}) eq 'solid') { |
$gnuplot_input .= 'set style fill solid '. |
$gnuplot_input .= 'set style fill solid '. |
Line 1225 sub write_gnuplot_file {
|
Line 1256 sub write_gnuplot_file {
|
for (my $i = 0;$i<=$#curves;$i++) { |
for (my $i = 0;$i<=$#curves;$i++) { |
$curve = $curves[$i]; |
$curve = $curves[$i]; |
$gnuplot_input.= ', ' if ($i > 0); |
$gnuplot_input.= ', ' if ($i > 0); |
|
if ($target eq 'tex') { |
|
$curve->{'linewidth'} *= 2; |
|
} |
if (exists($curve->{'function'})) { |
if (exists($curve->{'function'})) { |
$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_input.= ' 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 1260 sub write_gnuplot_file {
|
Line 1295 sub write_gnuplot_file {
|
} |
} |
# write file |
# write file |
print $fh $datatext; |
print $fh $datatext; |
close ($fh); |
close($fh); |
# generate gnuplot text |
# generate gnuplot text |
$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'); |
$gnuplot_input.= ' 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') || |