Mercurial > hg > octave-nkf
annotate scripts/plot/ishold.m @ 17204:d87179b38bcf
doc: Touch up alignment of @multitables in plot, legend, newplot.
* scripts/plot/legend.m, scripts/plot/newplot.m,
scripts/plot/plot.m: Don't use spacer rows between multitable items.
author | Rik <rik@octave.org> |
---|---|
date | Wed, 07 Aug 2013 22:20:32 -0700 |
parents | 327862500f1c |
children |
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 | 2 ## |
3 ## This file is part of Octave. | |
4 ## | |
5 ## Octave is free software; you can redistribute it and/or modify it | |
6 ## under the terms of the GNU General Public License as published by | |
7016 | 7 ## the Free Software Foundation; either version 3 of the License, or (at |
8 ## your option) any later version. | |
5406 | 9 ## |
10 ## Octave is distributed in the hope that it will be useful, but | |
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 ## General Public License for more details. | |
14 ## | |
15 ## You should have received a copy of the GNU General Public License | |
7016 | 16 ## along with Octave; see the file COPYING. If not, see |
17 ## <http://www.gnu.org/licenses/>. | |
5406 | 18 |
19 ## -*- texinfo -*- | |
12546
39ca02387a32
Improve docstrings for a number of functions.
Rik <octave@nomad.inbox5.com>
parents:
11563
diff
changeset
|
20 ## @deftypefn {Command} {} ishold |
17122
eaab03308c0b
doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents:
14363
diff
changeset
|
21 ## @deftypefnx {Function File} {} ishold (@var{hax}) |
eaab03308c0b
doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents:
14363
diff
changeset
|
22 ## @deftypefnx {Function File} {} 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 | 29 ## @end deftypefn |
30 | |
9618
e381f80a5f7a
correctly toggle hold state
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
31 function retval = ishold (h) |
5406 | 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 | 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 |
9618
e381f80a5f7a
correctly toggle hold state
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
41 if (ishandle (h)) |
17130
327862500f1c
ishold.m: Recode to follow modern Octave coding conventions.
Rik <rik@octave.org>
parents:
17122
diff
changeset
|
42 if (strcmp (get (h, "type"), "figure")) |
10549 | 43 fig = h; |
17130
327862500f1c
ishold.m: Recode to follow modern Octave coding conventions.
Rik <rik@octave.org>
parents:
17122
diff
changeset
|
44 ax = get (fig, "currentaxes"); |
327862500f1c
ishold.m: Recode to follow modern Octave coding conventions.
Rik <rik@octave.org>
parents:
17122
diff
changeset
|
45 elseif (strcmp (get (h, "type"), "axes")) |
10549 | 46 ax = h; |
17130
327862500f1c
ishold.m: Recode to follow modern Octave coding conventions.
Rik <rik@octave.org>
parents:
17122
diff
changeset
|
47 fig = get (ax, "parent"); |
9618
e381f80a5f7a
correctly toggle hold state
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
48 else |
17130
327862500f1c
ishold.m: Recode to follow modern Octave coding conventions.
Rik <rik@octave.org>
parents:
17122
diff
changeset
|
49 error ("ishold: H must be an axes or figure graphics handle"); |
9618
e381f80a5f7a
correctly toggle hold state
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
50 endif |
e381f80a5f7a
correctly toggle hold state
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
51 else |
17130
327862500f1c
ishold.m: Recode to follow modern Octave coding conventions.
Rik <rik@octave.org>
parents:
17122
diff
changeset
|
52 error ("ishold: H must be an axes or figure graphics handle"); |
9618
e381f80a5f7a
correctly toggle hold state
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
53 endif |
5406 | 54 endif |
55 | |
17130
327862500f1c
ishold.m: Recode to follow modern Octave coding conventions.
Rik <rik@octave.org>
parents:
17122
diff
changeset
|
56 retval = (strcmp (get (fig, "nextplot"), "add") |
327862500f1c
ishold.m: Recode to follow modern Octave coding conventions.
Rik <rik@octave.org>
parents:
17122
diff
changeset
|
57 && ! isempty (ax) && strcmp (get (ax, "nextplot"), "add")); |
9618
e381f80a5f7a
correctly toggle hold state
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
58 |
5406 | 59 endfunction |
13204 | 60 |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
61 |
13204 | 62 %!test |
63 %! hf = figure ("visible", "off"); | |
64 %! unwind_protect | |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
65 %! assert (! ishold); |
13319
eb0ce6ffefb0
ishold: don't create axes if none exists
John W. Eaton <jwe@octave.org>
parents:
13204
diff
changeset
|
66 %! assert (isempty (get (hf, "currentaxes"))); |
eb0ce6ffefb0
ishold: don't create axes if none exists
John W. Eaton <jwe@octave.org>
parents:
13204
diff
changeset
|
67 %! assert (get (hf, "NextPlot"), "add"); |
13204 | 68 %! 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
|
69 %! assert (! ishold); |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
70 %! assert (! ishold (gca)); |
13204 | 71 %! assert (get (gca, "NextPlot"), "replace"); |
72 %! assert (get (hf, "NextPlot"), "add"); | |
73 %! hold; | |
74 %! assert (ishold); | |
75 %! assert (ishold (gca)); | |
76 %! assert (get (gca, "NextPlot"), "add"); | |
77 %! assert (get (hf, "NextPlot"), "add"); | |
78 %! p = fill ([0 1 1], [0 0 1],"black"); | |
79 %! assert (length (get (hf, "children")), 1); | |
80 %! assert (length (get (gca, "children")), 2); | |
81 %! unwind_protect_cleanup | |
82 %! close (hf); | |
83 %! end_unwind_protect | |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
84 |