changeset 17525:76a6d7de4cbc

Fix multiple problem with listeners for contour groups. * scripts/plot/contour.m: Add new %!demo showing use of a single contour line. * scripts/plot/private/__contour__.m: Fix bug with lowest level of contourf showing background through. Use same routines for calculating levels and levelstep in main code and in listeners. Fix linecolor when turning "fill" on and off. Fix "textlist" and "textliststep" properties which were not activating correctly.
author Rik <rik@octave.org>
date Tue, 01 Oct 2013 12:51:04 -0700
parents 797545fa86d0
children 4f1dd8a980df
files scripts/plot/contour.m scripts/plot/private/__contour__.m
diffstat 2 files changed, 38 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/plot/contour.m	Tue Oct 01 00:22:46 2013 -0400
+++ b/scripts/plot/contour.m	Tue Oct 01 12:51:04 2013 -0700
@@ -90,7 +90,6 @@
 %! colormap ('default');
 %! [x, y, z] = peaks ();
 %! contour (x, y, z);
-%! title ('contour() plot of peaks() function');
 %! title ({'contour() plot (isolines of constant Z)'; 'Z = peaks()'});
 
 %!demo
@@ -102,13 +101,20 @@
 %! contour (X, Y, abs (Z), 10);
 %! title ({'contour() plot'; 'polar fcn: Z = sin (2*theta) * (1-r)'});
 
+%!demo
+%! clf;
+%! colormap ('default');
+%! z = peaks ();
+%! contour (z, [0 0]);
+%! title ({'contour() plot with single isoline at Z == 0'; 'Z = peaks()'});
+
 %!test
 %! hf = figure ("visible", "off");
 %! clf (hf);
 %! unwind_protect
 %!   [x, y, z] = peaks ();
 %!   [c, h] = contour (x, y, z);
-%!   levellist = (-6):6;
+%!   levellist = -6:6;
 %!   set (h, "levellist", levellist);
 %!   assert (get (h, "levellist"), levellist)
 %!   assert (get (h, "levellistmode"), "manual")
@@ -126,7 +132,7 @@
 %!   set (h, "levelstep", levelstep);
 %!   assert (get (h, "levelstep"), levelstep)
 %!   assert (get (h, "levelstepmode"), "manual")
-%!   assert (get (h, "levellist"), (-6):levelstep:6)
+%!   assert (get (h, "levellist"), -6:levelstep:6)
 %!   assert (get (h, "levellistmode"), "auto")
 %! unwind_protect_cleanup
 %!   close (hf);
--- a/scripts/plot/private/__contour__.m	Tue Oct 01 00:22:46 2013 -0400
+++ b/scripts/plot/private/__contour__.m	Tue Oct 01 12:51:04 2013 -0700
@@ -90,9 +90,10 @@
     ## FIXME: The levels should be determined similarly to {x,y,z}ticks
     ##        so that they aren't set at extremely odd values.
     lvl = linspace (min (z1(!isinf (z1))), max (z1(!isinf (z1))), vn + 2);
-    lvl = lvl(2:end-1);  # Strip off max, min outliers
+    ## Strip off max outlier, min must stay for contourf hole algorithm.
+    lvl = lvl(1:end-1);
   else
-    lvl = unique (sort (vn));
+    lvl = sort (vn);
   endif
 
   if (strcmpi (filled, "on"))
@@ -164,7 +165,7 @@
   addproperty ("linestyle", hg, "linelinestyle", linespec.linestyle);
   addproperty ("linewidth", hg, "linelinewidth", 0.5);
 
-  addlistener (hg, "fill", @update_data);
+  addlistener (hg, "fill", {@update_data, "fill"});
 
   addlistener (hg, "zlevelmode", @update_zlevel);
   addlistener (hg, "zlevel", @update_zlevel);
@@ -175,9 +176,9 @@
   addlistener (hg, "levelstepmode", @update_data);
 
   addlistener (hg, "labelspacing", @update_text);
-  addlistener (hg, "textlist", @update_text);
+  addlistener (hg, "textlist", {@update_text, "textlist"});
   addlistener (hg, "textlistmode", @update_text);
-  addlistener (hg, "textstep", @update_text);
+  addlistener (hg, "textstep", {@update_text, "textstep"});
   addlistener (hg, "textstepmode", @update_text);
   addlistener (hg, "showtext", @update_text);
 
@@ -301,7 +302,7 @@
         ## patch() doesn't need/want closed contour.  It will do it itself.
         ctmp(:,end) = [];
       endif
-      if (isnan (cont_lev (idx)))
+      if (isnan (cont_lev(idx)))
         fc = get (ca, "color");
         if (strcmp (fc, "none"))
           fc = get (ancestor (ca, "figure"), "color");
@@ -414,6 +415,13 @@
         set (h, "levellistmode", "manual")
       case "levelstep"
         set (h, "levelstepmode", "manual")
+      case "fill"
+        ## Switching from filled ('k' linespec) to unfilled, reset linecolor
+        if (strcmp (get (h, "fill"), "off"))
+          set (h, "linecolor", "auto");
+        else
+          set (h, "linecolor", "black");
+        endif
     endswitch
 
     if (strcmp (get (h, "levellistmode"), "manual")
@@ -432,7 +440,12 @@
       set (h, "levellist", lvl);
       set (h, "levellistmode", "auto");
     else
-      lvl = 10;
+      z = get (h, "zdata");
+      ## FIXME: The levels should be determined similarly to {x,y,z}ticks
+      ##        so that they aren't set at extremely odd values.
+      lvl = linspace (min (z(!isinf (z))), max (z(!isinf (z))), 10 + 2);
+      ## Strip off max outlier, min must stay for contourf hole algorithm.
+      lvl = lvl(1:end-1);
     endif
 
     if (strcmp (get (h, "fill"), "on"))
@@ -464,8 +477,7 @@
       set (h, "levellist", lev);
     else
       set (h, "levellist", lev);
-      z = get (h, "zdata");
-      lvlstep = (max (z(:)) - min (z(:))) / 10;
+      lvlstep = sum (diff (lvl)) / (length (lvl) - 1);
       set (h, "levelstep", lvlstep);
     endif
 
@@ -476,7 +488,7 @@
 
 endfunction
 
-function update_text (h, ~)
+function update_text (h, ~, prop = "")
   persistent recursive = false;
 
   if (! recursive)
@@ -484,6 +496,13 @@
 
     delete (findobj (h, "type", "text"));
 
+    switch (prop)
+      case "textlist"
+        set (h, "textlistmode", "manual")
+      case "textstep"
+        set (h, "textstepmode", "manual")
+    endswitch
+
     if (strcmp (get (h, "textlistmode"), "manual"))
       lvl = get (h, "textlist");
     elseif (strcmp (get (h, "textstepmode"), "manual"))