changeset 17131:b5d6314314fc

Change various plot functions to take advantage of new isaxes() function. * scripts/geometry/voronoi.m, scripts/image/imagesc.m, scripts/plot/__plt_get_axis_arg__.m, scripts/plot/axes.m, scripts/plot/cla.m, scripts/plot/colorbar.m, scripts/plot/hold.m, scripts/plot/legend.m, scripts/plot/plotmatrix.m, scripts/plot/plotyy.m, scripts/plot/private/__errplot__.m, scripts/plot/private/__plt__.m, scripts/plot/view.m: Use new isaxes function to simplify code. * scripts/plot/shading.m: Use Octave convention for spacing of parentheses. * scripts/plot/zlabel.m: Correct %!test incorrectly calling plot3 with figure handle.
author Rik <rik@octave.org>
date Wed, 31 Jul 2013 16:27:49 -0700
parents 7649779e6ebd
children 26589abbc78d
files scripts/geometry/voronoi.m scripts/image/imagesc.m scripts/plot/__plt_get_axis_arg__.m scripts/plot/axes.m scripts/plot/cla.m scripts/plot/colorbar.m scripts/plot/hold.m scripts/plot/legend.m scripts/plot/plotmatrix.m scripts/plot/plotyy.m scripts/plot/private/__errplot__.m scripts/plot/private/__plt__.m scripts/plot/shading.m scripts/plot/view.m scripts/plot/zlabel.m
diffstat 15 files changed, 58 insertions(+), 69 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/geometry/voronoi.m
+++ b/scripts/geometry/voronoi.m
@@ -74,13 +74,13 @@
 
   narg = 1;
   if (isscalar (varargin{1}) && ishandle (varargin{1}))
-    handl = varargin{1};
-    if (! strcmp (get (handl, "type"), "axes"))
-      error ("voronoi: expecting first argument to be an axes object");
+    hax = varargin{1};
+    if (! isaxes (harg))
+      error ("imagesc: HAX argument must be an axes object");
     endif
     narg++;
   elseif (nargout < 2)
-    handl = gca ();
+    hax = gca ();
   endif
 
   if (nargin < 1 + narg || nargin > 3 + narg)
@@ -154,7 +154,7 @@
   Vvy = reshape (p(edges, 2), size (edges));
 
   if (nargout < 2)
-    h = plot (handl, Vvx, Vvy, linespec{:}, x, y, '+');
+    h = plot (hax, Vvx, Vvy, linespec{:}, x, y, '+');
     lim = [xmin, xmax, ymin, ymax];
     axis (lim + 0.1 * [[-1, 1] * xdelta, [-1, 1] * ydelta]);
     if (nargout == 1)
--- a/scripts/image/imagesc.m
+++ b/scripts/image/imagesc.m
@@ -20,7 +20,7 @@
 ## @deftypefn  {Function File} {} imagesc (@var{img})
 ## @deftypefnx {Function File} {} imagesc (@var{x}, @var{y}, @var{img})
 ## @deftypefnx {Function File} {} imagesc (@dots{}, @var{climits})
-## @deftypefnx {Function File} {} imagesc (@var{h}, @dots{})
+## @deftypefnx {Function File} {} imagesc (@var{hax}, @dots{})
 ## @deftypefnx {Function File} {@var{h} =} imagesc (@dots{})
 ## Display a scaled version of the matrix @var{img} as a color image.  The
 ## colormap is scaled so that the entries of the matrix occupy the entire
@@ -45,14 +45,14 @@
   if (nargin < 1 || nargin > 4)
     print_usage ();
   elseif (isscalar (varargin{1}) && ishandle (varargin{1}))
-    harg = varargin{1};
-    if (! strcmp (get (harg, "type"), "axes"))
-      error ("imagesc: expecting first argument to be an axes object");
+    hax = varargin{1};
+    if (! isaxes (hax))
+      error ("imagesc: HAX argument must be an axes object");
     endif
     oldh = gca ();
     unwind_protect
       axes (h);
-      htmp = __imagesc__ (harg, varargin{2:end});
+      htmp = __imagesc__ (hax, varargin{2:end});
     unwind_protect_cleanup
       axes (oldh);
     end_unwind_protect
--- a/scripts/plot/__plt_get_axis_arg__.m
+++ b/scripts/plot/__plt_get_axis_arg__.m
@@ -28,24 +28,24 @@
   h = [];
   parent = find (strcmpi (varargin, "parent"), 1);
   
-  ## Look for numeric scalar which is a graphics handle but not the
+
+  ## Look for a scalar which is a graphics handle but not the
   ## Root Figure (0) or an ordinary figure (integer).
-  if (numel (varargin) > 0 && isnumeric (varargin{1})
-      && isscalar (varargin{1}) && ishandle (varargin{1})
-      && varargin{1} != 0 && ! isfigure (varargin{1}))
+  if (numel (varargin) > 0 && numel (varargin{1}) == 1
+      && ishandle (varargin{1}) && varargin{1} != 0 && ! isfigure (varargin{1}))
     htmp = varargin{1};
-    obj = get (htmp);
-    if (strcmp (obj.type, "axes") && ! strcmp (obj.tag, "legend"))
+    if (! isaxes (htmp))
+      error ("%s: expecting first argument to be axes handle", caller);
+    endif
+    if (! strcmp (get (htmp, "tag"), "legend"))
       h = htmp;
       varargin(1) = [];
-    else
-      error ("%s: expecting first argument to be axes handle", caller);
     endif
+  ## Look for "parent"/axis prop/value pair
   elseif (numel (varargin) > 1 && ! isempty (parent))
     if (parent < numel (varargin) && ishandle (varargin{parent+1}))
       htmp = varargin{parent+1};
-      obj = get (htmp);
-      if (strcmp (obj.type, "axes") && ! strcmp (obj.tag, "legend"))
+      if (isaxes (htmp) && ! strcmp (get (htmp, "tag"), "legend"))
         h = htmp;
         varargin(parent:parent+1) = [];
       else
--- a/scripts/plot/axes.m
+++ b/scripts/plot/axes.m
@@ -57,8 +57,7 @@
   else
     ## ARG is axes handle.
     htmp = varargin{1};
-    if (isscalar (htmp) && ishandle (htmp)
-        && strcmp (get (htmp, "type"), "axes"))
+    if (isscalar (htmp) && isaxes (htmp))
       if (__is_handle_visible__ (htmp))
         parent = ancestor (htmp, "figure");
         set (0, "currentfigure", parent);
--- a/scripts/plot/cla.m
+++ b/scripts/plot/cla.m
@@ -47,8 +47,7 @@
     hax = gca;
     do_reset = false;
   elseif (nargin == 1)
-    if (isscalar (varargin{1}) && ishandle (varargin{1})
-        && strcmp (get (varargin{1}, "type"), "axes"))
+    if (isscalar (varargin{1}) && isaxes (varargin{1}))
       hax = varargin{1};
       do_reset = false;
     elseif (ischar (varargin{1}) && strcmpi (varargin{1}, "reset"))
@@ -58,8 +57,7 @@
       print_usage ();
     endif
   else
-    if (isscalar (varargin{1}) && ishandle (varargin{1})
-        && strcmp (get (varargin{1}, "type"), "axes")
+    if (isscalar (varargin{1}) && isaxes (varargin{1})
         && ischar (varargin{2}) && strcmpi (varargin{2}, "reset"))
       hax = varargin{1};
       do_reset = true;
--- a/scripts/plot/colorbar.m
+++ b/scripts/plot/colorbar.m
@@ -108,8 +108,7 @@
             error ('colorbar: missing axes handle after "peer"');
           else
             ax = varargin{i++};
-            if (! isscalar (ax) || ! ishandle (ax)
-                || ! strcmp (get (ax, "type"), "axes"))
+            if (! isscalar (ax) && ! isaxes (ax))
               error ('colorbar: expecting an axes handle following "peer"');
             endif
           endif
@@ -253,7 +252,7 @@
 function deletecolorbar (h, d, hc, orig_props)
   ## Don't delete the colorbar and reset the axis size if the
   ## parent figure is being deleted.
-  if (ishandle (hc) && strcmp (get (hc, "type"), "axes")
+  if (isaxes (hc)
       && (isempty (gcbf ()) || strcmp (get (gcbf (), "beingdeleted"), "off")))
     if (strcmp (get (hc, "beingdeleted"), "off"))
       delete (hc);
@@ -272,7 +271,7 @@
 endfunction
 
 function resetaxis (cax, d, ax, orig_props)
-  if (ishandle (ax) && strcmp (get (ax, "type"), "axes"))
+  if (isaxes (ax))
     ## FIXME: Probably don't want to delete everyone's listeners on colormap.
     dellistener (get (ax, "parent"), "colormap");
     dellistener (ax, "clim");
@@ -292,7 +291,7 @@
 endfunction
 
 function update_colorbar_clim (hax, d, hi, vert)
-  if (ishandle (hax) && strcmp (get (hax, "type"), "axes")
+  if (isaxes (hax)
       && (isempty (gcbf ()) || strcmp (get (gcbf (), "beingdeleted"), "off")))
     clen = rows (get (get (hax, "parent"), "colormap"));
     cext = get (hax, "clim");
@@ -331,7 +330,7 @@
 
 function update_colorbar_axis (h, d, cax, orig_props)
 
-  if (ishandle (cax) && strcmp (get (cax, "type"), "axes")
+  if (isaxes (cax)
       && (isempty (gcbf ()) || strcmp (get (gcbf (), "beingdeleted"),"off")))
     loc = get (cax, "location");
     obj = get (h);
--- a/scripts/plot/hold.m
+++ b/scripts/plot/hold.m
@@ -44,9 +44,6 @@
 ## Toggle the current hold state.
 ## @end table
 ##
-## If the first argument @var{hax} is an axes handle, 
-## rather than the current axes returned by @code{gca}.
-##
 ## When given the additional argument @var{hax}, the hold state is modified
 ## for this axis rather than the current axes returned by @code{gca}.
 ##
@@ -56,12 +53,10 @@
 
 function hold (varargin)
 
-  if (nargin > 0 && isscalar (varargin{1}) && ishandle (varargin{1})
-      && strcmp (get (varargin{1}, "type"), "axes"))
-    [hax, varargin, nargs] = __plt_get_axis_arg__ ("hold", varargin{:});
-    if (isempty (hax))
-      hax = gca ();
-    endif
+  if (nargin > 0 && isscalar (varargin{1}) && isaxes (varargin{1}))
+    hax = vargin{1};
+    varargin(1) = [];
+    nargs = numel (varargin);
     ## FIXME: Should this be ancestor (hax, "parent")?
     hfig = get (hax, "parent");
   elseif (nargin > 0 && numel (varargin{1}) > 1 && ishandle (varargin{1}))
@@ -76,19 +71,18 @@
   if (nargs == 0)
     turn_hold_off = ishold (hax);
   elseif (nargs == 1)
-    state = varargin{1};
-    if (ischar (state))
-      if (strcmpi (state, "off"))
+    state = tolower (varargin{1});
+    switch (state)
+      case "off"
         turn_hold_off = true;
-      elseif (strcmpi (state, "all"))
+      case "all"
         turn_hold_off = false;
         hold_all = true;
-      elseif (strcmpi (state, "on"))
+      case "on"
         turn_hold_off = false;
-      else
+      otherwise
         error ("hold: invalid hold STATE");
-      endif
-    endif
+    endswitch
   else
     print_usage ();
   endif
--- a/scripts/plot/legend.m
+++ b/scripts/plot/legend.m
@@ -253,8 +253,8 @@
   hlegend = [];
   fkids = get (fig, "children");
   for i = 1 : numel (fkids)
-    if (ishandle (fkids(i)) && strcmp (get (fkids(i), "type"), "axes")
-        && (strcmp (get (fkids(i), "tag"), "legend")))
+    if (   strcmp (get (fkids(i), "type"), "axes")
+        && strcmp (get (fkids(i), "tag"), "legend"))
       udata = get (fkids(i), "userdata");
       if (! isempty (intersect (udata.handle, ca)))
         hlegend = fkids(i);
@@ -1059,7 +1059,7 @@
   endif
 
   for i = 1 : numel (ca)
-    if (ishandle (ca(i)) && strcmp (get (ca(i), "type"), "axes")
+    if (isaxes (ca(i))
         && (isempty (gcbf ()) || strcmp (get (gcbf (), "beingdeleted"),"off"))
         && strcmp (get (ca(i), "beingdeleted"), "off"))
       units = get (ca(i), "units");
@@ -1078,7 +1078,7 @@
 endfunction
 
 function deletelegend1 (h, d, ca)
-  if (ishandle (ca) && strcmp (get (ca, "type"), "axes")
+  if (isaxes (ca)
       && (isempty (gcbf ()) || strcmp (get (gcbf (), "beingdeleted"), "off"))
       && strcmp (get (ca, "beingdeleted"), "off"))
     delete (ca);
@@ -1087,7 +1087,7 @@
 
 function deletelegend2 (h, d, ca, pos, outpos, t1, hplots)
   for i = 1 : numel (ca)
-    if (ishandle (ca(i)) && strcmp (get (ca(i), "type"), "axes")
+    if (isaxes (ca(i))
         && (isempty (gcbf ()) || strcmp (get (gcbf (), "beingdeleted"), "off"))
         && strcmp (get (ca(i), "beingdeleted"), "off"))
       if (!isempty (pos) && !isempty(outpos))
--- a/scripts/plot/plotmatrix.m
+++ b/scripts/plot/plotmatrix.m
@@ -109,8 +109,7 @@
 function plotmatrixdelete (h, d, ax)
   for i = 1 : numel (ax)
     hc = ax(i);
-    if (ishandle (hc) && strcmp (get (hc, "type"), "axes")
-        && strcmpi (get (hc, "beingdeleted"), "off"))
+    if (isaxes (hc) && strcmpi (get (hc, "beingdeleted"), "off"))
       parent = get (hc, "parent");
       ## If the parent is invalid or being deleted, then do nothing
       if (ishandle (parent) && strcmpi (get (parent, "beingdeleted"), "off"))
--- a/scripts/plot/plotyy.m
+++ b/scripts/plot/plotyy.m
@@ -115,7 +115,7 @@
     [ax, h1, h2] = __plotyy__ (ax, varargin{:});
   unwind_protect_cleanup
     ## Only change back to the old axis if we didn't delete it
-    if (ishandle (oldh) && strcmp (get (oldh, "type"), "axes"))
+    if (isaxes (oldh))
       axes (oldh);
     endif
   end_unwind_protect
@@ -142,7 +142,7 @@
 
   xlim = [min([x1(:); x2(:)]), max([x1(:); x2(:)])];
 
-  if (ishandle (ax(1)) && strcmp (get (ax(1), "type"), "axes"))
+  if (isaxes (ax(1)))
     axes (ax(1));
   else
     ax(1) = axes ();
@@ -157,7 +157,7 @@
   cf = gcf ();
   set (cf, "nextplot", "add");
 
-  if (ishandle (ax(2)) && strcmp (get (ax(2), "type"), "axes"))
+  if (isaxes (ax(2)))
     axes (ax(2));
   else
     ax(2) = axes ();
@@ -289,7 +289,7 @@
 %! ylabel (hax(2), 'Right axis is Green');
 
 function deleteplotyy (h, d, ax2, t2)
-  if (ishandle (ax2) && strcmp (get (ax2, "type"), "axes")
+  if (isaxes (ax2)
       && (isempty (gcbf ()) || strcmp (get (gcbf (), "beingdeleted"),"off"))
       && strcmp (get (ax2, "beingdeleted"), "off"))
     set (t2, "deletefcn", []);
--- a/scripts/plot/private/__errplot__.m
+++ b/scripts/plot/private/__errplot__.m
@@ -198,8 +198,8 @@
     hlegend = [];
     fkids = get (gcf (), "children");
     for i = 1 : numel (fkids)
-      if (ishandle (fkids(i)) && strcmp (get (fkids(i), "type"), "axes")
-          && (strcmp (get (fkids(i), "tag"), "legend")))
+      if (   strcmp (get (fkids(i), "type"), "axes")
+          && strcmp (get (fkids(i), "tag"), "legend"))
         udata = get (fkids(i), "userdata");
         if (! isempty (intersect (udata.handle, gca ())))
           hlegend = fkids (i);
--- a/scripts/plot/private/__plt__.m
+++ b/scripts/plot/private/__plt__.m
@@ -39,11 +39,11 @@
     hlegend = [];
     fkids = get (gcf (), "children");
     for i = 1 : numel (fkids)
-      if (ishandle (fkids (i)) && strcmp (get (fkids (i), "type"), "axes")
-          && (strcmp (get (fkids (i), "tag"), "legend")))
-        udata = get (fkids (i), "userdata");
+      if (   strcmp (get (fkids(i), "type"), "axes")
+          && strcmp (get (fkids(i), "tag"), "legend"))
+        udata = get (fkids(i), "userdata");
         if (! isempty (intersect (udata.handle, gca ())))
-          hlegend = fkids (i);
+          hlegend = fkids(i);
           break;
         endif
       endif
--- a/scripts/plot/shading.m
+++ b/scripts/plot/shading.m
@@ -64,7 +64,7 @@
     types = get (kids, "type");
     hlist = [hlist; kids(strcmp(types, "patch"))];
     hlist = [hlist; kids(strcmp(types, "surface"))];
-    parents = kids(strcmp(types, "axes"));
+    parents = kids(strcmp (types, "axes"));
     hglist = kids(strcmp (types, "hggroup"));
     for i = 1 : numel (hglist)
       props = get (hglist(i));
--- a/scripts/plot/view.m
+++ b/scripts/plot/view.m
@@ -51,7 +51,7 @@
       args = {get(gca (), "view")};
     else
       ax = varargin{1};
-      if (ishandle (ax) && strcmp (get (ax, "type"), "axes"))
+      if (isaxes (ax))
         args = varargin(2:end);
       else
         ax = gca;
--- a/scripts/plot/zlabel.m
+++ b/scripts/plot/zlabel.m
@@ -72,7 +72,7 @@
 
 %!test
 %! hf = figure ("visible", "off");
-%! plot3 (hf, 0, 0, 0);
+%! plot3 (0, 0, 0);
 %! unwind_protect
 %!   z = zlabel ("zlabel_string");
 %!   assert (get (gca, "zlabel"), z);