[LON-CAPA-cvs] cvs: loncom /xml lonplot.pm

foxr foxr at source.lon-capa.org
Wed Jul 4 07:06:57 EDT 2012


foxr		Wed Jul  4 11:06:57 2012 EDT

  Modified files:              
    /loncom/xml	lonplot.pm 
  Log:
  BZ6588 - First refactor and simplify the generation of gnuplot commands.
         - Second address the bug by associating a linestye with each plot
           and using that to select the plot attributes rather than cramming
           all the attributes into the plot command.
         - Finally, fix the fact that line style numbers differ between
           eps and png drivers so that now dashed lines work in eps output
           where I don't think they did before.
  
  
  
Index: loncom/xml/lonplot.pm
diff -u loncom/xml/lonplot.pm:1.156 loncom/xml/lonplot.pm:1.157
--- loncom/xml/lonplot.pm:1.156	Tue Jul  3 11:29:57 2012
+++ loncom/xml/lonplot.pm	Wed Jul  4 11:06:57 2012
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Dynamic plot
 #
-# $Id: lonplot.pm,v 1.156 2012/07/03 11:29:57 foxr Exp $
+# $Id: lonplot.pm,v 1.157 2012/07/04 11:06:57 foxr Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -98,11 +98,16 @@
 my $max_str_len = 50;    # if a label, title, xlabel, or ylabel text
                          # is longer than this, it will be truncated.
 
-my %linetypes =
+my %linetypes =			# For png use these linetypes.
     (
      solid          => 1,
      dashed         => 0
     );
+my %ps_linetypes = 		# For ps the line types are different!
+   (
+    solid          => 0,
+    dashed         => 7
+   );
 
 my %linestyles = 
     (
@@ -1842,8 +1847,6 @@
     #  type (solid/dashed), color, width
     #
     my $linestyle_index = 50;
-    my $line_type    = '';     
-    my $line_color   = '';
     my $line_width   = '';
 
     my $plot_command;
@@ -1855,6 +1858,7 @@
 	if ($target eq 'tex') {
 	    $curve->{'linewidth'} *= 2;
 	}
+	$line_width = $curve->{'linewidth'};
 	if (exists($curve->{'function'})) {
 	    $plot_type    = 
 		$curve->{'function'}.' title "'.
@@ -1884,27 +1888,55 @@
 		$curve->{'name'}.'" with '.
 		$curve->{'linestyle'};
 	}
+	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')) {
-	    $plot_command.=' pointtype '.$curve->{'pointtype'};
-	    $plot_command.=' pointsize '.$curve->{'pointsize'};
+	    
+	    $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'}.'"';
+	} 
+
+#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}
 	}
-	$plot_command.= ' linewidth '.$curve->{'linewidth'};
+
+	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.
     open (my $fh,">$tmpdir$filename.data");




More information about the LON-CAPA-cvs mailing list