changeset 17015:761d2be77e78

__plt_get_axis_arg__.m: Simplify code for finding parent in axis PROP/VAL pairs. * scripts/plot/__plt_get_axis_arg__.m: Use find and strcmpi to simplify finding 'parent' attribute. Simplify test for axes handle input. Add comments to code. * scripts/plot/line.m: Remove unneeded test empty axis. Rewrite docstring.
author Rik <rik@octave.org>
date Thu, 18 Jul 2013 22:56:13 -0700
parents 4d9862d9fce5
children a3f6790df115
files scripts/plot/__plt_get_axis_arg__.m scripts/plot/line.m
diffstat 2 files changed, 34 insertions(+), 35 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/plot/__plt_get_axis_arg__.m	Tue Jul 16 20:41:20 2013 +0200
+++ b/scripts/plot/__plt_get_axis_arg__.m	Thu Jul 18 22:56:13 2013 -0700
@@ -25,6 +25,8 @@
 
 function [h, varargin, narg] = __plt_get_axis_arg__ (caller, varargin)
 
+  ## First argument can be a boolean which determines whether a new
+  ## axis will be created if none exists.
   if (islogical (caller))
     nogca = caller;
     caller = varargin{1};
@@ -33,38 +35,31 @@
     nogca = false;
   endif
 
-
   ## Search for parent property
-  charargs = cellfun (@ischar,varargin);
-  isparent = strcmp (lower (varargin(charargs)), "parent");
+  parent = find (strcmpi (varargin, "parent"), 1);
   
-  ## Figure handles are integers, but object handles are non-integer,
-  ## therefore ignore integer scalars.
-  if (nargin > 1 && length (varargin) > 0 && isnumeric (varargin{1})
-      && numel (varargin{1}) == 1 && ishandle (varargin{1}(1))
-      && varargin{1}(1) != 0 && ! isfigure (varargin{1}(1)))
-    tmp = varargin{1};
-    obj = get (tmp);
+  ## Look for numeric 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}))
+    htmp = varargin{1};
+    obj = get (htmp);
     if ((strcmp (obj.type, "axes") && ! strcmp (obj.tag, "legend"))
         || strcmp (obj.type, "hggroup"))
-      h = ancestor (tmp, "axes");
+      h = ancestor (htmp, "axes");
       varargin(1) = [];
-      if (isempty (varargin))
-        varargin = {};
-      endif
     else
       error ("%s: expecting first argument to be axes handle", caller);
     endif
-  elseif (numel (varargin) > 1 && any (isparent))
-    tmp = find (charargs);
-    idx = tmp(isparent)(1);
-    if (idx < numel (varargin) && ishandle (varargin{idx+1}))
-      tmp = varargin{idx+1};
-      obj = get (tmp);
+  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"))
           || strcmp (obj.type, "hggroup"))
-        h = ancestor (tmp, "axes");
-        varargin(idx:idx+1) = [];
+        h = ancestor (htmp, "axes");
+        varargin(parent:parent+1) = [];
       else
         error ("%s: expecting parent value to be axes handle", caller);
       endif
@@ -72,6 +67,7 @@
       error ("%s: expecting parent value to be axes handle", caller);
     endif
   else
+    ## No axis specified.  Use current axis or create one as necessary.
     f = get (0, "currentfigure");
     if (isempty (f))
       h = [];
--- a/scripts/plot/line.m	Tue Jul 16 20:41:20 2013 +0200
+++ b/scripts/plot/line.m	Thu Jul 18 22:56:13 2013 -0700
@@ -19,31 +19,34 @@
 ## -*- texinfo -*-
 ## @deftypefn  {Function File} {} line ()
 ## @deftypefnx {Function File} {} line (@var{x}, @var{y})
+## @deftypefnx {Function File} {} line (@var{x}, @var{y}, @var{property}, @var{value}, @dots{}))
 ## @deftypefnx {Function File} {} line (@var{x}, @var{y}, @var{z})
 ## @deftypefnx {Function File} {} line (@var{x}, @var{y}, @var{z}, @var{property}, @var{value}, @dots{})
-## Create line object from @var{x} and @var{y} and insert in current
-## axes object.  Return a handle (or vector of handles) to the line
-## objects created.
+## @deftypefnx {Function File} {} line (@var{property}, @var{value}, @dots{})
+## @deftypefnx {Function File} {@var{h} =} line (@dots{})
+## Create line object from @var{x} and @var{y} (and possibly @var{z}) and
+## insert in the current axes.
 ##
-## Multiple property-value pairs may be specified for the line, but they
+## Multiple property-value pairs may be specified for the line object, but they
 ## must appear in pairs.
+##
+## The optional return value @var{h} is a graphics handle (or vector of handles)
+## to the line objects created.
+##
+## @seealso{image, patch, rectangle, surface, text}
 ## @end deftypefn
 
 ## Author: jwe
 
 function h = line (varargin)
 
-  ## make a default line object, and make it the current axes for
-  ## the current figure.
-  [ax, varargin] = __plt_get_axis_arg__ ("line", varargin{:});
-  if (isempty (ax))
-    ax = gca ();
-  endif
-  
-  tmp = __line__ (ax, varargin{:});
+  ## Get any axis argument which may be in a 'parent' PROP/VAL pair
+  [hax, varargin] = __plt_get_axis_arg__ ("line", varargin{:});
+
+  htmp = __line__ (hax, varargin{:});
 
   if (nargout > 0)
-    h = tmp;
+    h = htmp;
   endif
 
 endfunction