annotate scripts/plot/util/ishold.m @ 26376:00f796120a6d stable

maint: Update copyright dates in all source files.
author John W. Eaton <jwe@octave.org>
date Wed, 02 Jan 2019 16:32:43 -0500
parents 6652d3823428
children b442ec6dda5c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
26376
00f796120a6d maint: Update copyright dates in all source files.
John W. Eaton <jwe@octave.org>
parents: 25054
diff changeset
1 ## Copyright (C) 2005-2019 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 ##
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 24423
diff changeset
5 ## Octave is free software: you can redistribute it and/or modify it
5406
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
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 24423
diff changeset
7 ## the Free Software Foundation, either version 3 of the License, or
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22323
diff changeset
8 ## (at 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
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22323
diff changeset
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22323
diff changeset
13 ## GNU General Public License for more details.
5406
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
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 24423
diff changeset
17 ## <https://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 -*-
20852
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 19880
diff changeset
20 ## @deftypefn {} {} ishold
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 19880
diff changeset
21 ## @deftypefnx {} {} ishold (@var{hax})
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 19880
diff changeset
22 ## @deftypefnx {} {} ishold (@var{hfig})
11431
0d9640d755b1 Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents: 10635
diff changeset
23 ## 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
24 ## 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
25 ##
17122
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 14363
diff changeset
26 ## If the first argument is an axes handle @var{hax} or figure handle
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 14363
diff changeset
27 ## @var{hfig} then operate on this plot rather than the current one.
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 14363
diff changeset
28 ## @seealso{hold, newplot}
5406
c49aec8a9080 [project @ 2005-07-08 15:25:43 by jwe]
jwe
parents:
diff changeset
29 ## @end deftypefn
c49aec8a9080 [project @ 2005-07-08 15:25:43 by jwe]
jwe
parents:
diff changeset
30
9618
e381f80a5f7a correctly toggle hold state
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
31 function retval = ishold (h)
5406
c49aec8a9080 [project @ 2005-07-08 15:25:43 by jwe]
jwe
parents:
diff changeset
32
17130
327862500f1c ishold.m: Recode to follow modern Octave coding conventions.
Rik <rik@octave.org>
parents: 17122
diff changeset
33 if (nargin > 1)
327862500f1c ishold.m: Recode to follow modern Octave coding conventions.
Rik <rik@octave.org>
parents: 17122
diff changeset
34 print_usage ();
327862500f1c ishold.m: Recode to follow modern Octave coding conventions.
Rik <rik@octave.org>
parents: 17122
diff changeset
35 endif
327862500f1c ishold.m: Recode to follow modern Octave coding conventions.
Rik <rik@octave.org>
parents: 17122
diff changeset
36
5406
c49aec8a9080 [project @ 2005-07-08 15:25:43 by jwe]
jwe
parents:
diff changeset
37 if (nargin == 0)
9618
e381f80a5f7a correctly toggle hold state
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
38 fig = gcf ();
13319
eb0ce6ffefb0 ishold: don't create axes if none exists
John W. Eaton <jwe@octave.org>
parents: 13204
diff changeset
39 ax = get (fig, "currentaxes");
17130
327862500f1c ishold.m: Recode to follow modern Octave coding conventions.
Rik <rik@octave.org>
parents: 17122
diff changeset
40 else
24423
1d52db450db4 Change ishandle to return true for Java objects for Matlab compatibility.
Rik <rik@octave.org>
parents: 23220
diff changeset
41 if (! ishghandle (h))
22069
9121d6584f6a Overhaul graphics implementation of hold() (bug #43559).
Rik <rik@octave.org>
parents: 20852
diff changeset
42 error ("ishold: H must be an axes or figure graphics handle");
9121d6584f6a Overhaul graphics implementation of hold() (bug #43559).
Rik <rik@octave.org>
parents: 20852
diff changeset
43 endif
9121d6584f6a Overhaul graphics implementation of hold() (bug #43559).
Rik <rik@octave.org>
parents: 20852
diff changeset
44
9121d6584f6a Overhaul graphics implementation of hold() (bug #43559).
Rik <rik@octave.org>
parents: 20852
diff changeset
45 switch (get (h, "type"))
9121d6584f6a Overhaul graphics implementation of hold() (bug #43559).
Rik <rik@octave.org>
parents: 20852
diff changeset
46 case "figure"
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9618
diff changeset
47 fig = h;
17130
327862500f1c ishold.m: Recode to follow modern Octave coding conventions.
Rik <rik@octave.org>
parents: 17122
diff changeset
48 ax = get (fig, "currentaxes");
22069
9121d6584f6a Overhaul graphics implementation of hold() (bug #43559).
Rik <rik@octave.org>
parents: 20852
diff changeset
49
9121d6584f6a Overhaul graphics implementation of hold() (bug #43559).
Rik <rik@octave.org>
parents: 20852
diff changeset
50 case "axes"
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9618
diff changeset
51 ax = h;
19880
f25fe5369022 Don't assume axes parent is a figure (bug #44394)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 19697
diff changeset
52 fig = ancestor (ax, "figure");
22069
9121d6584f6a Overhaul graphics implementation of hold() (bug #43559).
Rik <rik@octave.org>
parents: 20852
diff changeset
53
9121d6584f6a Overhaul graphics implementation of hold() (bug #43559).
Rik <rik@octave.org>
parents: 20852
diff changeset
54 otherwise
17130
327862500f1c ishold.m: Recode to follow modern Octave coding conventions.
Rik <rik@octave.org>
parents: 17122
diff changeset
55 error ("ishold: H must be an axes or figure graphics handle");
22069
9121d6584f6a Overhaul graphics implementation of hold() (bug #43559).
Rik <rik@octave.org>
parents: 20852
diff changeset
56
9121d6584f6a Overhaul graphics implementation of hold() (bug #43559).
Rik <rik@octave.org>
parents: 20852
diff changeset
57 endswitch
5406
c49aec8a9080 [project @ 2005-07-08 15:25:43 by jwe]
jwe
parents:
diff changeset
58 endif
c49aec8a9080 [project @ 2005-07-08 15:25:43 by jwe]
jwe
parents:
diff changeset
59
17130
327862500f1c ishold.m: Recode to follow modern Octave coding conventions.
Rik <rik@octave.org>
parents: 17122
diff changeset
60 retval = (strcmp (get (fig, "nextplot"), "add")
327862500f1c ishold.m: Recode to follow modern Octave coding conventions.
Rik <rik@octave.org>
parents: 17122
diff changeset
61 && ! isempty (ax) && strcmp (get (ax, "nextplot"), "add"));
9618
e381f80a5f7a correctly toggle hold state
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
62
5406
c49aec8a9080 [project @ 2005-07-08 15:25:43 by jwe]
jwe
parents:
diff changeset
63 endfunction
13204
be7bfd59300a Add tests for scripts/plot
Kai Habel <kai.habel@gmx.de>
parents: 12546
diff changeset
64
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
65
13204
be7bfd59300a Add tests for scripts/plot
Kai Habel <kai.habel@gmx.de>
parents: 12546
diff changeset
66 %!test
be7bfd59300a Add tests for scripts/plot
Kai Habel <kai.habel@gmx.de>
parents: 12546
diff changeset
67 %! hf = figure ("visible", "off");
be7bfd59300a Add tests for scripts/plot
Kai Habel <kai.habel@gmx.de>
parents: 12546
diff changeset
68 %! unwind_protect
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
69 %! assert (! ishold);
13319
eb0ce6ffefb0 ishold: don't create axes if none exists
John W. Eaton <jwe@octave.org>
parents: 13204
diff changeset
70 %! assert (isempty (get (hf, "currentaxes")));
eb0ce6ffefb0 ishold: don't create axes if none exists
John W. Eaton <jwe@octave.org>
parents: 13204
diff changeset
71 %! assert (get (hf, "NextPlot"), "add");
13204
be7bfd59300a Add tests for scripts/plot
Kai Habel <kai.habel@gmx.de>
parents: 12546
diff changeset
72 %! l = plot ([0 1]);
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
73 %! assert (! ishold);
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
74 %! assert (! ishold (gca));
13204
be7bfd59300a Add tests for scripts/plot
Kai Habel <kai.habel@gmx.de>
parents: 12546
diff changeset
75 %! assert (get (gca, "NextPlot"), "replace");
be7bfd59300a Add tests for scripts/plot
Kai Habel <kai.habel@gmx.de>
parents: 12546
diff changeset
76 %! assert (get (hf, "NextPlot"), "add");
be7bfd59300a Add tests for scripts/plot
Kai Habel <kai.habel@gmx.de>
parents: 12546
diff changeset
77 %! hold;
be7bfd59300a Add tests for scripts/plot
Kai Habel <kai.habel@gmx.de>
parents: 12546
diff changeset
78 %! assert (ishold);
be7bfd59300a Add tests for scripts/plot
Kai Habel <kai.habel@gmx.de>
parents: 12546
diff changeset
79 %! assert (ishold (gca));
be7bfd59300a Add tests for scripts/plot
Kai Habel <kai.habel@gmx.de>
parents: 12546
diff changeset
80 %! assert (get (gca, "NextPlot"), "add");
be7bfd59300a Add tests for scripts/plot
Kai Habel <kai.habel@gmx.de>
parents: 12546
diff changeset
81 %! assert (get (hf, "NextPlot"), "add");
be7bfd59300a Add tests for scripts/plot
Kai Habel <kai.habel@gmx.de>
parents: 12546
diff changeset
82 %! 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
83 %! assert (length (get (hf, "children")), 1);
be7bfd59300a Add tests for scripts/plot
Kai Habel <kai.habel@gmx.de>
parents: 12546
diff changeset
84 %! assert (length (get (gca, "children")), 2);
be7bfd59300a Add tests for scripts/plot
Kai Habel <kai.habel@gmx.de>
parents: 12546
diff changeset
85 %! unwind_protect_cleanup
be7bfd59300a Add tests for scripts/plot
Kai Habel <kai.habel@gmx.de>
parents: 12546
diff changeset
86 %! close (hf);
be7bfd59300a Add tests for scripts/plot
Kai Habel <kai.habel@gmx.de>
parents: 12546
diff changeset
87 %! end_unwind_protect