version 1.155, 2012/02/22 10:16:39
|
version 1.157, 2012/07/04 11:06:57
|
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 1635 sub write_gnuplot_file {
|
Line 1640 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 1835 sub write_gnuplot_file {
|
Line 1840 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 = ''; |
|
|
|
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 1889 sub write_gnuplot_file {
|
Line 1884 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 = ''; |
|
|
|
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->{'linetype'} ne '' && |
|
# $curve->{'linestyle'} eq 'lines') |
|
# |
|
# |
|
# $plot_command.= ' linetype '; |
|
# $plot_command.= $linetypes{$curve->{'linetype'}}; |
|
# $plot_command.= ' linecolor rgb "'; |
|
# # convert color from xaaaaaa to #aaaaaa |
|
# $curve->{'color'} =~ s/^x/#/; |
|
# $plot_command.= $curve->{'color'}.'"'; |
|
# } |
|
|
|
# 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; |
|
|
|
$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"); |