annotate scripts/plot/ishold.m @ 14138:72c96de7a403 stable

maint: update copyright notices for 2012
author John W. Eaton <jwe@octave.org>
date Mon, 02 Jan 2012 14:25:41 -0500
parents eb0ce6ffefb0
children f3d52523cde1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
14138
72c96de7a403 maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents: 13319
diff changeset
1 ## Copyright (C) 2005-2012 John W. Eaton
5406
c49aec8a9080 [project @ 2005-07-08 15:25:43 by jwe]
jwe
parents:
diff changeset
2 ##
c49aec8a9080 [project @ 2005-07-08 15:25:43 by jwe]
jwe
parents:
diff changeset
3 ## This file is part of Octave.
c49aec8a9080 [project @ 2005-07-08 15:25:43 by jwe]
jwe
parents:
diff changeset
4 ##
c49aec8a9080 [project @ 2005-07-08 15:25:43 by jwe]
jwe
parents:
diff changeset
5 ## Octave is free software; you can redistribute it and/or modify it
c49aec8a9080 [project @ 2005-07-08 15:25:43 by jwe]
jwe
parents:
diff changeset
6 ## under the terms of the GNU General Public License as published by
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6895
diff changeset
7 ## the Free Software Foundation; either version 3 of the License, or (at
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6895
diff changeset
8 ## your option) any later version.
5406
c49aec8a9080 [project @ 2005-07-08 15:25:43 by jwe]
jwe
parents:
diff changeset
9 ##
c49aec8a9080 [project @ 2005-07-08 15:25:43 by jwe]
jwe
parents:
diff changeset
10 ## Octave is distributed in the hope that it will be useful, but
c49aec8a9080 [project @ 2005-07-08 15:25:43 by jwe]
jwe
parents:
diff changeset
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
c49aec8a9080 [project @ 2005-07-08 15:25:43 by jwe]
jwe
parents:
diff changeset
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
c49aec8a9080 [project @ 2005-07-08 15:25:43 by jwe]
jwe
parents:
diff changeset
13 ## General Public License for more details.
c49aec8a9080 [project @ 2005-07-08 15:25:43 by jwe]
jwe
parents:
diff changeset
14 ##
c49aec8a9080 [project @ 2005-07-08 15:25:43 by jwe]
jwe
parents:
diff changeset
15 ## You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6895
diff changeset
16 ## along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6895
diff changeset
17 ## <http://www.gnu.org/licenses/>.
5406
c49aec8a9080 [project @ 2005-07-08 15:25:43 by jwe]
jwe
parents:
diff changeset
18
c49aec8a9080 [project @ 2005-07-08 15:25:43 by jwe]
jwe
parents:
diff changeset
19 ## -*- texinfo -*-
12546
39ca02387a32 Improve docstrings for a number of functions.
Rik <octave@nomad.inbox5.com>
parents: 11563
diff changeset
20 ## @deftypefn {Command} {} ishold
39ca02387a32 Improve docstrings for a number of functions.
Rik <octave@nomad.inbox5.com>
parents: 11563
diff changeset
21 ## @deftypefnx {Function File} {} ishold (@var{h})
11431
0d9640d755b1 Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents: 10635
diff changeset
22 ## Return true if the next plot will be added to the current plot, or
0d9640d755b1 Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents: 10635
diff changeset
23 ## false if the plot device will be cleared before drawing the next plot.
12546
39ca02387a32 Improve docstrings for a number of functions.
Rik <octave@nomad.inbox5.com>
parents: 11563
diff changeset
24 ##
39ca02387a32 Improve docstrings for a number of functions.
Rik <octave@nomad.inbox5.com>
parents: 11563
diff changeset
25 ## Optionally, operate on the graphics handle @var{h} rather than the current
39ca02387a32 Improve docstrings for a number of functions.
Rik <octave@nomad.inbox5.com>
parents: 11563
diff changeset
26 ## plot.
11431
0d9640d755b1 Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents: 10635
diff changeset
27 ## @seealso{hold}
5406
c49aec8a9080 [project @ 2005-07-08 15:25:43 by jwe]
jwe
parents:
diff changeset
28 ## @end deftypefn
c49aec8a9080 [project @ 2005-07-08 15:25:43 by jwe]
jwe
parents:
diff changeset
29
9618
e381f80a5f7a correctly toggle hold state
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
30 function retval = ishold (h)
5406
c49aec8a9080 [project @ 2005-07-08 15:25:43 by jwe]
jwe
parents:
diff changeset
31
c49aec8a9080 [project @ 2005-07-08 15:25:43 by jwe]
jwe
parents:
diff changeset
32 if (nargin == 0)
9618
e381f80a5f7a correctly toggle hold state
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
33 fig = gcf ();
13319
eb0ce6ffefb0 ishold: don't create axes if none exists
John W. Eaton <jwe@octave.org>
parents: 13204
diff changeset
34 ax = get (fig, "currentaxes");
9618
e381f80a5f7a correctly toggle hold state
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
35 elseif (nargin == 1)
e381f80a5f7a correctly toggle hold state
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
36 if (ishandle (h))
e381f80a5f7a correctly toggle hold state
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
37 if (isfigure (h))
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9618
diff changeset
38 ax = get (h, "currentaxes");
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9618
diff changeset
39 fig = h;
9618
e381f80a5f7a correctly toggle hold state
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
40 elseif (strcmpi (get (h, "type"), "axes"))
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9618
diff changeset
41 ax = h;
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9618
diff changeset
42 fig = get (h, "parent");
9618
e381f80a5f7a correctly toggle hold state
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
43 else
10635
d1978e7364ad Print name of function in error() string messages.
Rik <octave@nomad.inbox5.com>
parents: 10549
diff changeset
44 error ("ishold: expecting argument to be axes or figure graphics handle");
9618
e381f80a5f7a correctly toggle hold state
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
45 endif
e381f80a5f7a correctly toggle hold state
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
46 else
10635
d1978e7364ad Print name of function in error() string messages.
Rik <octave@nomad.inbox5.com>
parents: 10549
diff changeset
47 error ("ishold: expecting argument to be axes or figure graphics handle");
9618
e381f80a5f7a correctly toggle hold state
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
48 endif
5406
c49aec8a9080 [project @ 2005-07-08 15:25:43 by jwe]
jwe
parents:
diff changeset
49 else
6046
34f96dd5441b [project @ 2006-10-10 16:10:25 by jwe]
jwe
parents: 5406
diff changeset
50 print_usage ();
5406
c49aec8a9080 [project @ 2005-07-08 15:25:43 by jwe]
jwe
parents:
diff changeset
51 endif
c49aec8a9080 [project @ 2005-07-08 15:25:43 by jwe]
jwe
parents:
diff changeset
52
9618
e381f80a5f7a correctly toggle hold state
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
53 retval = (strcmpi (get (fig, "nextplot"), "add")
13319
eb0ce6ffefb0 ishold: don't create axes if none exists
John W. Eaton <jwe@octave.org>
parents: 13204
diff changeset
54 && ! isempty (ax) && strcmpi (get (ax, "nextplot"), "add"));
9618
e381f80a5f7a correctly toggle hold state
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
55
5406
c49aec8a9080 [project @ 2005-07-08 15:25:43 by jwe]
jwe
parents:
diff changeset
56 endfunction
13204
be7bfd59300a Add tests for scripts/plot
Kai Habel <kai.habel@gmx.de>
parents: 12546
diff changeset
57
be7bfd59300a Add tests for scripts/plot
Kai Habel <kai.habel@gmx.de>
parents: 12546
diff changeset
58 %!test
be7bfd59300a Add tests for scripts/plot
Kai Habel <kai.habel@gmx.de>
parents: 12546
diff changeset
59 %! hf = figure ("visible", "off");
be7bfd59300a Add tests for scripts/plot
Kai Habel <kai.habel@gmx.de>
parents: 12546
diff changeset
60 %! unwind_protect
13319
eb0ce6ffefb0 ishold: don't create axes if none exists
John W. Eaton <jwe@octave.org>
parents: 13204
diff changeset
61 %! assert (!ishold);
eb0ce6ffefb0 ishold: don't create axes if none exists
John W. Eaton <jwe@octave.org>
parents: 13204
diff changeset
62 %! assert (isempty (get (hf, "currentaxes")));
eb0ce6ffefb0 ishold: don't create axes if none exists
John W. Eaton <jwe@octave.org>
parents: 13204
diff changeset
63 %! assert (get (hf, "NextPlot"), "add");
13204
be7bfd59300a Add tests for scripts/plot
Kai Habel <kai.habel@gmx.de>
parents: 12546
diff changeset
64 %! l = plot ([0 1]);
be7bfd59300a Add tests for scripts/plot
Kai Habel <kai.habel@gmx.de>
parents: 12546
diff changeset
65 %! assert (!ishold);
be7bfd59300a Add tests for scripts/plot
Kai Habel <kai.habel@gmx.de>
parents: 12546
diff changeset
66 %! assert (!ishold (gca));
be7bfd59300a Add tests for scripts/plot
Kai Habel <kai.habel@gmx.de>
parents: 12546
diff changeset
67 %! assert (get (gca, "NextPlot"), "replace");
be7bfd59300a Add tests for scripts/plot
Kai Habel <kai.habel@gmx.de>
parents: 12546
diff changeset
68 %! assert (get (hf, "NextPlot"), "add");
be7bfd59300a Add tests for scripts/plot
Kai Habel <kai.habel@gmx.de>
parents: 12546
diff changeset
69 %! hold;
be7bfd59300a Add tests for scripts/plot
Kai Habel <kai.habel@gmx.de>
parents: 12546
diff changeset
70 %! assert (ishold);
be7bfd59300a Add tests for scripts/plot
Kai Habel <kai.habel@gmx.de>
parents: 12546
diff changeset
71 %! assert (ishold (gca));
be7bfd59300a Add tests for scripts/plot
Kai Habel <kai.habel@gmx.de>
parents: 12546
diff changeset
72 %! assert (get (gca, "NextPlot"), "add");
be7bfd59300a Add tests for scripts/plot
Kai Habel <kai.habel@gmx.de>
parents: 12546
diff changeset
73 %! assert (get (hf, "NextPlot"), "add");
be7bfd59300a Add tests for scripts/plot
Kai Habel <kai.habel@gmx.de>
parents: 12546
diff changeset
74 %! p = fill ([0 1 1], [0 0 1],"black");
be7bfd59300a Add tests for scripts/plot
Kai Habel <kai.habel@gmx.de>
parents: 12546
diff changeset
75 %! assert (length (get (hf, "children")), 1);
be7bfd59300a Add tests for scripts/plot
Kai Habel <kai.habel@gmx.de>
parents: 12546
diff changeset
76 %! assert (length (get (gca, "children")), 2);
be7bfd59300a Add tests for scripts/plot
Kai Habel <kai.habel@gmx.de>
parents: 12546
diff changeset
77 %! unwind_protect_cleanup
be7bfd59300a Add tests for scripts/plot
Kai Habel <kai.habel@gmx.de>
parents: 12546
diff changeset
78 %! close (hf);
be7bfd59300a Add tests for scripts/plot
Kai Habel <kai.habel@gmx.de>
parents: 12546
diff changeset
79 %! end_unwind_protect