# HG changeset patch # User Rik # Date 1378940740 25200 # Node ID 95bfa04ab514737bd4f64560107b637923072e70 # Parent f58ad514372ccf7df0a6adf8e5f2e5279ef199ae 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. diff -r f58ad514372c -r 95bfa04ab514 scripts/plot/colorbar.m --- a/scripts/plot/colorbar.m Wed Sep 11 15:44:20 2013 -0700 +++ b/scripts/plot/colorbar.m Wed Sep 11 16:05:40 2013 -0700 @@ -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");