changeset 26320:92c88ff62055 stable

__plt_get_axis_arg__.m: Accept multiple "parent" properties correctly. * __plt_get_axis_arg__.m: Use "! isempty" rather than "numel () > 0" for clarity. Use "isscalar" rather than "numel () == 1" for clarity. Change find call to locate "parent" property to start from the end so that the final value, the one that will actually be used, is detected if there are multiple "parent" properties present. * test/bug-55322/bug-55322.tst: Remove failing non-essential test.
author Rik <rik@octave.org>
date Sat, 29 Dec 2018 22:36:11 -0800
parents 4764e9c0face
children cb96d4ba6daa 74368b4f9d8c
files scripts/plot/util/__plt_get_axis_arg__.m test/bug-55322/bug-55322.tst
diffstat 2 files changed, 12 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/plot/util/__plt_get_axis_arg__.m	Sat Dec 29 18:59:33 2018 -0800
+++ b/scripts/plot/util/__plt_get_axis_arg__.m	Sat Dec 29 22:36:11 2018 -0800
@@ -26,12 +26,12 @@
 function [h, varargin, narg] = __plt_get_axis_arg__ (caller, varargin)
 
   h = [];
-  parent = find (strcmpi (varargin, "parent"), 1);
 
   ## Look for a scalar which is a graphics handle but not the
   ## Root Figure (0) or an ordinary figure (integer).
-  if (numel (varargin) > 0 && numel (varargin{1}) == 1
-      && ishghandle (varargin{1}) && varargin{1} != 0 && ! isfigure (varargin{1}))
+  if (! isempty (varargin) && isscalar (varargin{1})
+      && ishghandle (varargin{1}) && varargin{1} != 0
+      && ! isfigure (varargin{1}))
     htmp = varargin{1};
     if (! isaxes (htmp))
       error ("%s: first argument must be axes handle", caller);
@@ -41,18 +41,22 @@
       varargin(1) = [];
     endif
   ## Look for "parent"/axis prop/value pair
-  elseif (numel (varargin) > 1 && ! isempty (parent))
-    if (parent < numel (varargin) && ishghandle (varargin{parent+1}))
+  elseif (numel (varargin) > 1)
+    ## FIXME: This can be fooled by any string "parent" such as
+    ##        the prop/val pair "tag"/"parent".
+    parent = find (strcmpi (varargin, "parent"), 1, "last");
+    if (! isempty (parent))
+      if (parent == numel (varargin) || ! ishghandle (varargin{parent+1}))
+        error ('%s: "parent" value must be an axes handle', caller);
+      endif
       htmp = varargin{parent+1};
       if (isaxes (htmp) && ! strcmp (get (htmp, "tag"), "legend"))
         h = htmp;
         varargin(parent:parent+1) = [];
       else
-        ## 'parent' property for some other type like hggroup
+        ## "parent" property for some other type like hggroup
         h = [ancestor(htmp, "axes"), htmp];
       endif
-    else
-      error ("%s: parent value must be an axes handle", caller);
     endif
   endif
 
--- a/test/bug-55322/bug-55322.tst	Sat Dec 29 18:59:33 2018 -0800
+++ b/test/bug-55322/bug-55322.tst	Sat Dec 29 22:36:11 2018 -0800
@@ -27,13 +27,3 @@
 %! unwind_protect_cleanup
 %!   close (hf);
 %! end_unwind_protect
-
-%!test
-%! hf = figure ("visible", "off");
-%! unwind_protect
-%!   hax = axes ();
-%!   hg = hggroup ();
-%!   hl = line ([0, 1], [1, 1], "tag", "parent", "color", "r");
-%! unwind_protect_cleanup
-%!   close (hf);
-%! end_unwind_protect