changelog shortlog tags changeset files revisions annotate raw

scripts/plot/cla.m

changeset 10289: 4b124317dc38
parent:5dd06f19e9be
author: John W. Eaton <jwe@octave.org>
date: Tue Feb 09 20:58:55 2010 -0500 (70 minutes ago)
permissions: -rw-r--r--
description: base_properties::set_children: account for hidden children
1## Copyright (C) 2008, 2009 Ben Abbott
2##
3## This program is free software; you can redistribute it and/or modify
4## it under the terms of the GNU General Public License as published by
5## the Free Software Foundation; either version 2 of the License, or
6## (at your option) any later version.
7##
8## This program is distributed in the hope that it will be useful,
9## but WITHOUT ANY WARRANTY; without even the implied warranty of
10## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11## GNU General Public License for more details.
12##
13## You should have received a copy of the GNU General Public License
14## along with Octave; see the file COPYING. If not, see
15## <http://www.gnu.org/licenses/>.
16
17## -*- texinfo -*-
18## @deftypefn {Function File} {} cla ()
19## @deftypefnx {Function File} {} cla ("reset")
20## @deftypefnx {Function File} {} cla (@var{hax})
21## @deftypefnx {Function File} {} cla (@var{hax}, "reset")
22## Delete the children of the current axes with visible handles.
23## If @var{hax} is specified and is an axes object handle, operate on it
24## instead of the current axes. If the optional argument @code{"reset"}
25## is specified, also delete the children with hidden handles.
26## @seealso{clf}
27## @end deftypefn
28
29## Author: Ben Abbott <bpabbott@mac.com>
30## Created: 2008-10-03
31
32function cla (varargin)
33
34 if (nargin > 2)
35 print_usage ();
36 elseif (nargin > 1)
37 if (ishandle (varargin{1})
38 && strcmp (get (varargin{1}, "type"), "axes")
39 && ischar (varargin{2}) && strcmpi (varargin{2}, "reset"))
40 oldhax = gca;
41 hax = varargin{1};
42 do_reset = true;
43 else
44 print_usage ();
45 endif
46 elseif (nargin == 1)
47 if (ishandle (varargin{1})
48 && strcmp (get (varargin{1}, "type"), "axes"))
49 oldhax = gca;
50 hax = varargin{1};
51 do_reset = false;
52 elseif (ischar (varargin{1}) && strcmpi (varargin{1}, "reset"))
53 hax = gca;
54 oldhax = hax;
55 do_reset = true;
56 else
57 print_usage ();
58 endif
59 else
60 hax = gca;
61 oldhax = hax;
62 do_reset = false;
63 endif
64
65 hc = get (hax, "children");
66
67 if (! do_reset && ! isempty (hc))
68 hc = findobj (hc, "flat", "visible", "on");
69 hc = setdiff (hc, hax);
70 endif
71
72 if (! isempty (hc))
73 ## Delete the children of the axis.
74 delete (hc);
75 endif
76
77 ## FIXME: The defaults should be "reset()" below, but so far there is
78 ## no method to determine the defaults, much less return an object's
79 ## properties to their default values. Instead make a close
80 ## approximation.
81
82 axes (hax);
83 axis auto
84
85 ## Set the current axis back to where it was upon entry.
86 axes (oldhax);
87
88endfunction
89
90%!test
91%! hf = figure (1, "visible", "off");
92%! unwind_protect
93%! clf
94%! plot (1:10)
95%! cla ()
96%! kids = get (gca, "children");
97%! cla ()
98%! unwind_protect_cleanup
99%! close (hf)
100%! end_unwind_protect
101%! assert (numel (kids), 0)