changeset 22920:c9ef5571e11a

colorbar.m: Disallow log scale and emit an error as Matlab does (bug #42311). * colorbar.m: Add listener on yscale property of colorbar. In callback, prevent any change to yscale property and emit an error.
author Rik <rik@octave.org>
date Fri, 16 Dec 2016 13:13:18 -0800
parents eb064b1b4269
children b28801182c08
files scripts/plot/draw/colorbar.m
diffstat 1 files changed, 12 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/plot/draw/colorbar.m	Fri Dec 16 14:13:37 2016 -0500
+++ b/scripts/plot/draw/colorbar.m	Fri Dec 16 13:13:18 2016 -0800
@@ -238,6 +238,7 @@
 
     set (cax, "deletefcn", {@resetaxis, ax, obj});
 
+    addlistener (cax, "yscale", @error_if_logscale);
     addlistener (hpar, "colormap", {@update_colorbar_cmap, hi, vertical, clen});
     addlistener (ax, "clim", {@update_colorbar_clim, hi, vertical});
     addlistener (ax, "dataaspectratio", {@update_colorbar_axis, cax, obj});
@@ -254,7 +255,7 @@
 
 endfunction
 
-function deletecolorbar (h, d, hc, orig_props)
+function deletecolorbar (h, ~, hc, orig_props)
   ## Don't delete the colorbar and reset the axis size
   ## if the parent figure is being deleted.
   if (isaxes (hc)
@@ -276,7 +277,14 @@
 
 endfunction
 
-function resetaxis (cax, d, ax, orig_props)
+function error_if_logscale (cax, ~)
+  if (strcmp (get (cax, "yscale"), "log"))
+    set (cax, "yscale", "linear");
+    error ("colorbar: Only linear colorbars are possible");
+  endif
+endfunction
+
+function resetaxis (cax, ~, ax, orig_props)
 
   if (isaxes (ax))
     ## FIXME: Probably don't want to delete everyone's listeners on colormap.
@@ -298,7 +306,7 @@
 
 endfunction
 
-function update_colorbar_clim (hax, d, hi, vert)
+function update_colorbar_clim (hax, ~, hi, vert)
 
   if (isaxes (hax)
       && (isempty (gcbf ()) || strcmp (get (gcbf (), "beingdeleted"), "off")))
@@ -340,7 +348,7 @@
 
 endfunction
 
-function update_colorbar_axis (h, d, cax, orig_props)
+function update_colorbar_axis (h, ~, cax, orig_props)
 
   if (isaxes (cax)
       && (isempty (gcbf ()) || strcmp (get (gcbf (), "beingdeleted"),"off")))