changeset 17433:95bfa04ab514

Fix bug in colorbar demo #24. set() is broken from deep within listener hierarchy. Workaround it. * scripts/plot/colorbar.m(update_colorbar_clim): Set axis limits in listener and then jiggle the axis position to force a redraw.
author Rik <rik@octave.org>
date Wed, 11 Sep 2013 16:05:40 -0700
parents f58ad514372c
children e89e86e1a551
files scripts/plot/colorbar.m
diffstat 1 files changed, 21 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/plot/colorbar.m
+++ b/scripts/plot/colorbar.m
@@ -299,13 +299,32 @@
     cmin = cext(1) + cdiff;
     cmax = cext(2) - cdiff;
 
+    hiax = get (hi, "parent");
     if (vert)
       set (hi, "ydata", [cmin, cmax]);
-      set (get (hi, "parent"), "ylim", cext);
+      set (hiax, "ylim", cext);
     else
       set (hi, "xdata", [cmin, cmax]);
-      set (get (hi, "parent"), "xlim", cext);
+      set (hiax, "xlim", cext);
     endif
+
+    ## FIXME: Setting xlim or ylim from within a listener callback
+    ##        causes the axis to change size rather than change limits.
+    ##        Workaround it by jiggling the position property which forces
+    ##        a redraw of the axis object.
+    ##
+    ## Debug Example:
+    ## Uncomment the line below.
+    ##   keyboard;
+    ## Now run the the following code.
+    ##   clf; colorbar (); contour (peaks ())
+    ## Once the keyboard command has been hit in the debugger try
+    ##   set (hiax, "ylim", [0 0.5]) 
+    pos = get (hiax, "position");
+    pos(1) += eps;
+    set (hiax, "position", pos);
+    pos(1) -= eps;
+    set (hiax, "position", pos);
   endif
 endfunction
 
@@ -329,7 +348,6 @@
 endfunction
 
 function update_colorbar_axis (h, d, cax, orig_props)
-
   if (isaxes (cax)
       && (isempty (gcbf ()) || strcmp (get (gcbf (), "beingdeleted"),"off")))
     loc = get (cax, "location");