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

foxr foxr at source.lon-capa.org
Tue Jul 17 06:49:53 EDT 2012


foxr		Tue Jul 17 10:49:53 2012 EDT

  Modified files:              
    /loncom/xml	lonplot.pm 
  Log:
  Factor out common code to generate tic specifications.
  
  
Index: loncom/xml/lonplot.pm
diff -u loncom/xml/lonplot.pm:1.161 loncom/xml/lonplot.pm:1.162
--- loncom/xml/lonplot.pm:1.161	Tue Jul 17 09:54:48 2012
+++ loncom/xml/lonplot.pm	Tue Jul 17 10:49:53 2012
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Dynamic plot
 #
-# $Id: lonplot.pm,v 1.161 2012/07/17 09:54:48 foxr Exp $
+# $Id: lonplot.pm,v 1.162 2012/07/17 10:49:53 foxr Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -1636,6 +1636,48 @@
     }
     return ;
 }
+##
+# Generate tic mark specifications.
+# 
+# @param type - type of tics (xtics or ytics).
+# @param spec - Reference to a hash that contains the tic specification.
+# @param target - 'tex' if hard copy target.
+#
+# @return string - the tic specification command.
+#
+sub generate_tics {
+    my ($type, $spec, $target) = @_;
+    my $result   = '';
+
+
+    if (defined %$spec) {
+
+
+
+	# Major tics:
+
+	$result .= "set $type $spec->{'location'}  ";
+	$result .= ($spec->{'mirror'} eq 'on') ? 'mirror ' : 'nomirror ';
+	$result .= "$spec->{'start'}, ";
+	$result .= "$spec->{'increment'}, ";
+	$result .= "$spec->{'end'} ";
+	if ($target eq 'tex' ) {
+	    $result .= 'font "Helvetica,22"';
+	}
+	$result .= "\n";
+
+	# minor frequency:
+
+	if ($spec->{'minorfreq'} != 0) {
+	    $result .= "set m$type $spec->{'minorfreq'}\n";
+	}
+    } else {
+	$result .= "set $type font " . '"Helvetica,22"' ."\n";
+    }
+
+
+    return $result;
+}
 
 ##------------------------------------------------------- write_gnuplot_file
 sub write_gnuplot_file {
@@ -1778,42 +1820,10 @@
         $gnuplot_input .= "set ylabel \"$ylabel\" $extra_space_y \n" if (defined($ylabel));
     }
     # tics
-    if (%xtics) {    
-	$gnuplot_input .= "set xtics $xtics{'location'} ";
-	$gnuplot_input .= ( $xtics{'mirror'} eq 'on'?"mirror ":"nomirror ");
-	$gnuplot_input .= "$xtics{'start'}, ";
-	$gnuplot_input .= "$xtics{'increment'}, ";
-	$gnuplot_input .= "$xtics{'end'} ";
-	if ($target eq 'tex') {
-	    $gnuplot_input .= 'font "Helvetica,22"';     # Needed in iso 8859-1 enc.
-	}
-	$gnuplot_input .= "\n";
-        if ($xtics{'minorfreq'} != 0) {
-            $gnuplot_input .= "set mxtics ".$xtics{'minorfreq'}."\n";
-        } 
-    } else {
-	if ($target eq 'tex') {
-	    $gnuplot_input .= 'set xtics font "Helvetica,22"'."\n"; # needed in iso 8859-1 enc
-	}
-    }
-    if (%ytics) {    
-	$gnuplot_input .= "set ytics $ytics{'location'} ";
-	$gnuplot_input .= ( $ytics{'mirror'} eq 'on'?"mirror ":"nomirror ");
-	$gnuplot_input .= "$ytics{'start'}, ";
-	$gnuplot_input .= "$ytics{'increment'}, ";
-        $gnuplot_input .= "$ytics{'end'} ";
-        if ($target eq 'tex') {
-            $gnuplot_input .= 'font "Helvetica,22"'; # Needed in iso-8859-1 encoding.
-        }
-        $gnuplot_input .= "\n";
-        if ($ytics{'minorfreq'} != 0) {
-            $gnuplot_input .= "set mytics ".$ytics{'minorfreq'}."\n";
-        } 
-    } else {
-	if ($target eq 'tex') {
-	    $gnuplot_input .= 'set ytics font "Helvetica,22"'."\n"; # Needed for iso 8859-1 enc.
-	}
-    }
+    $gnuplot_input .= &generate_tics('xtics', \%xtics, $target);
+
+    $gnuplot_input .= &generate_tics('ytics', \%ytics, $target);
+
     # axis
     if (%axis) {
         if ($axis{'xformat'} ne 'on') {
@@ -2004,6 +2014,7 @@
 	$linestyle_index++;	# Each curve get a unique linestyle.
     }
     # Write the output to a file.
+    &Apache::lonnet::logthis($gnuplot_input);
     open (my $fh, "> $tmpdir$filename.data");
     binmode($fh, ':utf8');
     print $fh $gnuplot_input;




More information about the LON-CAPA-cvs mailing list