version 1.154, 2012/02/13 11:24:16
|
version 1.160, 2012/07/16 10:09:36
|
Line 98 BEGIN {
|
Line 98 BEGIN {
|
my $max_str_len = 50; # if a label, title, xlabel, or ylabel text |
my $max_str_len = 50; # if a label, title, xlabel, or ylabel text |
# is longer than this, it will be truncated. |
# is longer than this, it will be truncated. |
|
|
my %linetypes = |
my %linetypes = # For png use these linetypes. |
( |
( |
solid => 1, |
solid => 1, |
dashed => 0 |
dashed => 0 |
); |
); |
|
my %ps_linetypes = # For ps the line types are different! |
|
( |
|
solid => 0, |
|
dashed => 7 |
|
); |
|
|
my %linestyles = |
my %linestyles = |
( |
( |
Line 134 my $sml_test = sub {$_[0]=~/^(\d+|
|
Line 139 my $sml_test = sub {$_[0]=~/^(\d+|
|
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~!\@\#\$\%^&\*\(\)-=_\+\[\]\{\}:\;\'<>,\.\/\?\\]+ ?)+$/}; |
|
|
|
my $arrowhead_test = sub{$_[0]=~/^(nohead|head|heads| )+$/}; |
|
my $arrowstyle_test= sub{$_[0]=~/^(filled|empty|nofilled)+$/}; |
|
my $degree_test = sub{&$pos_real_test($_[0]) && ($_[0] <= 360.0)}; |
|
|
################################################################### |
################################################################### |
## ## |
## ## |
## Attribute metadata ## |
## Attribute metadata ## |
Line 528 my %axis_defaults =
|
Line 537 my %axis_defaults =
|
}, |
}, |
); |
); |
|
|
my @curve_edit_order = ('color','name','linestyle','linewidth','linetype','pointtype','pointsize','limit'); |
my @curve_edit_order = ('color','name','linestyle','linewidth','linetype', |
|
'pointtype','pointsize','limit', 'arrowhead', 'arrowstyle', |
|
'arrowlength', 'arrowangle', 'arrowbackangle' |
|
); |
|
|
my %curve_defaults = |
my %curve_defaults = |
( |
( |
Line 589 my %curve_defaults =
|
Line 601 my %curve_defaults =
|
edit_type => 'choice', |
edit_type => 'choice', |
choices => ['above', 'below', 'closed','x1','x2','y1','y2'] |
choices => ['above', 'below', 'closed','x1','x2','y1','y2'] |
}, |
}, |
|
arrowhead => { |
|
default => 'head', |
|
test => $arrowhead_test, |
|
description => 'Vector arrow head type', |
|
edit_type => 'choice', |
|
choices => ['nohead', 'head', 'heads'] |
|
}, |
|
arrowstyle => { |
|
default => 'filled', |
|
test => $arrowstyle_test, |
|
description => 'Vector arrow head style', |
|
edit_type => 'choice', |
|
choices => ['filled', 'empty', 'nofilled'] |
|
}, |
|
arrowlength => { |
|
default => 0.02, |
|
test => $pos_real_test, |
|
description => "Length of vector arrow (only applies to vector plots)", |
|
edit_type => 'entry', |
|
size => '5' |
|
}, |
|
arrowangle => { |
|
default => 10.0, |
|
test => $degree_test, |
|
description => 'Angle of arrow branches to arrow body (only applies to vector plots)', |
|
edit_type => 'entry', |
|
size => '5' |
|
}, |
|
|
|
arrowbackangle => { |
|
default => 90.0, |
|
test => $degree_test, |
|
descripton => 'Angle of arrow back lines to branches.', |
|
edit_type => 'entry', |
|
size => '5' |
|
} |
|
|
); |
); |
|
|
################################################################### |
################################################################### |
Line 624 sub start_gnuplot {
|
Line 673 sub start_gnuplot {
|
} 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)); |
|
|
if ($constructtag) { |
if ($constructtag) { |
|
# |
|
# The color chooser does not prepent x to the color values |
|
# Do that here: |
|
# |
|
foreach my $attribute ('bgcolor', 'fgcolor') { |
|
my $value = $token->[2]{$attribute}; |
|
if (defined $value && !($value =~ /^x/)) { |
|
$token->[2]{$attribute} = 'x' . $value; |
|
} |
|
} |
$result = &Apache::edit::rebuild_tag($token); |
$result = &Apache::edit::rebuild_tag($token); |
} |
} |
} |
} |
Line 1355 sub start_curve {
|
Line 1415 sub start_curve {
|
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) { |
|
# |
|
# Fix up the color attribute as jcolor does not prepend an x |
|
# |
|
my $value = $token->[2]{'color'}; |
|
if (defined $value && !($value =~ /^x/)) { |
|
$token->[2]{'color'} = 'x' . $value; |
|
} |
$result = &Apache::edit::rebuild_tag($token); |
$result = &Apache::edit::rebuild_tag($token); |
} |
} |
} |
} |
Line 1501 sub start_axis {
|
Line 1568 sub start_axis {
|
} 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(%axis_defaults)); |
($token,$parstack,$safeeval,keys(%axis_defaults)); |
|
|
if ($constructtag) { |
if ($constructtag) { |
|
# |
|
# Fix up the color attribute since jchooser does not |
|
# prepend an x to the color: |
|
# |
|
my $value = $token->[2]{'color'}; |
|
if (defined $value && !($value =~ /^x/)) { |
|
$token->[2]{'color'} = 'x' . $value; |
|
} |
|
|
$result = &Apache::edit::rebuild_tag($token); |
$result = &Apache::edit::rebuild_tag($token); |
} |
} |
} |
} |
Line 1594 sub write_gnuplot_file {
|
Line 1671 sub write_gnuplot_file {
|
$curve->{'color'} : |
$curve->{'color'} : |
$Apache::lonplot::plot{'fgcolor'} ); |
$Apache::lonplot::plot{'fgcolor'} ); |
} |
} |
|
|
# set term |
# set term |
if ($target eq 'web') { |
if ($target eq 'web') { |
$gnuplot_input .= 'set terminal png enhanced nocrop '; |
$gnuplot_input .= 'set terminal png enhanced nocrop '; |
Line 1606 sub write_gnuplot_file {
|
Line 1684 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 enhanced $Apache::lonplot::plot{'plotcolor'} solid "; |
$gnuplot_input .= "set term postscript eps enhanced $Apache::lonplot::plot{'plotcolor'} dash "; |
if (!$font_properties->{'tex_no_file'}) { |
if (!$font_properties->{'tex_no_file'}) { |
$gnuplot_input .= |
$gnuplot_input .= |
'fontfile "'.$Apache::lonnet::perlvar{'lonFontsDir'}. |
'fontfile "'.$Apache::lonnet::perlvar{'lonFontsDir'}. |
Line 1619 sub write_gnuplot_file {
|
Line 1697 sub write_gnuplot_file {
|
$gnuplot_input .= "set encoding iso_8859_1\n"; # Get access to extended font. |
$gnuplot_input .= "set encoding iso_8859_1\n"; # Get access to extended font. |
|
|
} |
} |
|
$gnuplot_input .= "set encoding utf8\n"; |
# cartesian or polar plot? |
# 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'.$/; |
Line 1806 sub write_gnuplot_file {
|
Line 1885 sub write_gnuplot_file {
|
$gnuplot_input .="\n"; |
$gnuplot_input .="\n"; |
} |
} |
# curves |
# curves |
$gnuplot_input .= 'plot '; |
# |
|
# Each curve will have its very own linestyle. |
|
# (This should work just fine in web rendition I think). |
|
# The line_xxx variables will hold the elements of the line style. |
|
# type (solid/dashed), color, width |
|
# |
|
my $linestyle_index = 50; |
|
my $line_width = ''; |
|
|
|
# If arrows are needed there will be an arrow style for each as well: |
|
# |
|
|
|
my $arrow_style_index = 50; |
|
|
|
my $plot_command; |
|
my $plot_type; |
|
|
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); |
$plot_command.= ', ' if ($i > 0); |
if ($target eq 'tex') { |
if ($target eq 'tex') { |
$curve->{'linewidth'} *= 2; |
$curve->{'linewidth'} *= 2; |
} |
} |
|
$line_width = $curve->{'linewidth'}; |
if (exists($curve->{'function'})) { |
if (exists($curve->{'function'})) { |
$gnuplot_input.= |
$plot_type = |
$curve->{'function'}.' title "'. |
$curve->{'function'}.' title "'. |
$curve->{'name'}.'" with '. |
$curve->{'name'}.'" with '. |
$curve->{'linestyle'}; |
$curve->{'linestyle'}; |
|
|
if (($curve->{'linestyle'} eq 'points') || |
|
($curve->{'linestyle'} eq 'linespoints') || |
|
($curve->{'linestyle'} eq 'errorbars') || |
|
($curve->{'linestyle'} eq 'xerrorbars') || |
|
($curve->{'linestyle'} eq 'yerrorbars') || |
|
($curve->{'linestyle'} eq 'xyerrorbars')) { |
|
$gnuplot_input.=' pointtype '.$curve->{'pointtype'}; |
|
$gnuplot_input.=' pointsize '.$curve->{'pointsize'}; |
|
} elsif ($curve->{'linestyle'} eq 'filledcurves') { |
|
$gnuplot_input.= ' '.$curve->{'limit'}; |
|
} elsif ($curve->{'linetype'} ne '' && |
|
$curve->{'linestyle'} eq 'lines') { |
|
$gnuplot_input.= ' linetype '; |
|
$gnuplot_input.= $linetypes{$curve->{'linetype'}}; |
|
$gnuplot_input.= ' linecolor rgb "'; |
|
# convert color from xaaaaaa to #aaaaaa |
|
$curve->{'color'} =~ s/^x/#/; |
|
$gnuplot_input.= $curve->{'color'}.'"'; |
|
} |
|
$gnuplot_input.= ' linewidth '.$curve->{'linewidth'}; |
|
|
|
} elsif (exists($curve->{'data'})) { |
} elsif (exists($curve->{'data'})) { |
# Store data values in $datatext |
# Store data values in $datatext |
my $datatext = ''; |
my $datatext = ''; |
Line 1860 sub write_gnuplot_file {
|
Line 1934 sub write_gnuplot_file {
|
print $fh $datatext; |
print $fh $datatext; |
close($fh); |
close($fh); |
# generate gnuplot text |
# generate gnuplot text |
$gnuplot_input.= '"'.$datafilename.'" title "'. |
$plot_type = '"'.$datafilename.'" title "'. |
$curve->{'name'}.'" with '. |
$curve->{'name'}.'" with '. |
$curve->{'linestyle'}; |
$curve->{'linestyle'}; |
if (($curve->{'linestyle'} eq 'points') || |
|
($curve->{'linestyle'} eq 'linespoints') || |
|
($curve->{'linestyle'} eq 'errorbars') || |
|
($curve->{'linestyle'} eq 'xerrorbars') || |
|
($curve->{'linestyle'} eq 'yerrorbars') || |
|
($curve->{'linestyle'} eq 'xyerrorbars')) { |
|
$gnuplot_input.=' pointtype '.$curve->{'pointtype'}; |
|
$gnuplot_input.=' pointsize '.$curve->{'pointsize'}; |
|
} elsif ($curve->{'linestyle'} eq 'filledcurves') { |
|
$gnuplot_input.= ' '.$curve->{'limit'}; |
|
} elsif ($curve->{'linetype'} ne '' && |
|
$curve->{'linestyle'} eq 'lines') { |
|
$gnuplot_input.= ' linetype '; |
|
$gnuplot_input.= $linetypes{$curve->{'linetype'}}; |
|
$gnuplot_input.= ' linecolor rgb "'; |
|
# convert color from xaaaaaa to #aaaaaa |
|
$curve->{'color'} =~ s/^x/#/; |
|
$gnuplot_input.= $curve->{'color'}.'"'; |
|
} |
|
$gnuplot_input.= ' linewidth '.$curve->{'linewidth'}; |
|
} |
} |
|
my $pointtype = ''; |
|
my $pointsize = ''; |
|
|
|
# Figure out the linestyle: |
|
|
|
my $lt = $curve->{'linetype'} ne '' ? $curve->{'linetype'} |
|
: 'solid'; # Line type defaults to solid. |
|
# The mapping of lt -> the actual gnuplot line type depends on the target: |
|
|
|
if ($target eq 'tex') { |
|
$lt = $ps_linetypes{$lt}; |
|
} else { |
|
$lt = $linetypes{$lt} |
|
} |
|
|
|
my $color = $curve->{'color'}; |
|
$color =~ s/^x/#/; # Convert xhex color -> #hex color. |
|
|
|
my $style_command = "set style line $linestyle_index $pointtype $pointsize linetype $lt linewidth $line_width lc rgb '$color'\n"; |
|
$gnuplot_input .= $style_command; |
|
|
|
|
|
|
|
if (($curve->{'linestyle'} eq 'points') || |
|
($curve->{'linestyle'} eq 'linespoints') || |
|
($curve->{'linestyle'} eq 'errorbars') || |
|
($curve->{'linestyle'} eq 'xerrorbars') || |
|
($curve->{'linestyle'} eq 'yerrorbars') || |
|
($curve->{'linestyle'} eq 'xyerrorbars')) { |
|
|
|
$pointtype =' pointtype '.$curve->{'pointtype'}; |
|
$pointsize =' pointsize '.$curve->{'pointsize'}; |
|
} elsif ($curve->{'linestyle'} eq 'filledcurves') { |
|
$plot_command.= ' '.$curve->{'limit'}; |
|
} elsif ($curve->{'linestyle'} eq 'vector') { |
|
|
|
# Create the arrow head style add it to |
|
# $gnuplot_input..and ensure it gets |
|
# Selected in the plot command. |
|
|
|
$gnuplot_input .= "set style arrow $arrow_style_index "; |
|
$gnuplot_input .= ' ' . $curve->{'arrowhead'}; |
|
$gnuplot_input .= ' size ' . $curve->{'arrowlength'}; |
|
$gnuplot_input .= ','.$curve->{'arrowangle'}; |
|
$gnuplot_input .= ',' . $curve->{'arrowbackangle'}; |
|
$gnuplot_input .= ' ' . $curve->{'arrowstyle'} . " ls $linestyle_index\n"; |
|
|
|
|
|
$plot_command .= " arrowstyle $arrow_style_index "; |
|
$arrow_style_index++; |
|
} |
|
|
|
|
|
|
|
|
|
# The condition below is because gnuplot lumps the linestyle in with the |
|
# arrowstyle _sigh_. |
|
|
|
if ($curve->{'linestyle'} ne 'vector') { |
|
$plot_command.= " ls $linestyle_index"; |
|
} |
|
|
|
$gnuplot_input .= 'plot ' . $plot_type . ' ' . $plot_command . "\n"; |
|
$linestyle_index++; # Each curve get a unique linestyle. |
} |
} |
# Write the output to a file. |
# Write the output to a file. |
open (my $fh,">$tmpdir$filename.data"); |
open (my $fh,">$tmpdir$filename.data"); |
binmode($fh, ":utf8"); |
|
print $fh $gnuplot_input; |
print $fh $gnuplot_input; |
close($fh); |
close($fh); |
# That's all folks. |
# That's all folks. |