Mercurial > octave
annotate scripts/plot/util/cla.m @ 27919:1891570abac8
update Octave Project Developers copyright for the new year
In files that have the "Octave Project Developers" copyright notice,
update for 2020.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Mon, 06 Jan 2020 22:29:51 -0500 |
parents | b442ec6dda5c |
children | bd51beb6205e |
rev | line source |
---|---|
27919
1891570abac8
update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents:
27918
diff
changeset
|
1 ## Copyright (C) 2008-2020 The Octave Project Developers |
27918
b442ec6dda5c
use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
2 ## |
b442ec6dda5c
use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
3 ## See the file COPYRIGHT.md in the top-level directory of this distribution |
b442ec6dda5c
use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
4 ## or <https://octave.org/COPYRIGHT.html/>. |
b442ec6dda5c
use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
5 ## |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
6 ## |
11104 | 7 ## This file is part of Octave. |
8 ## | |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
24433
diff
changeset
|
9 ## Octave is free software: you can redistribute it and/or modify it |
11104 | 10 ## 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:
24433
diff
changeset
|
11 ## 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
|
12 ## (at your option) any later version. |
11104 | 13 ## |
14 ## Octave is distributed in the hope that it will be useful, but | |
15 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
16 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
17 ## GNU General Public License for more details. |
11104 | 18 ## |
8199
ec1b4cd5fbbb
cla.m: Add matlab function cla().
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
19 ## You should have received a copy of the GNU General Public License |
ec1b4cd5fbbb
cla.m: Add matlab function cla().
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
20 ## 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:
24433
diff
changeset
|
21 ## <https://www.gnu.org/licenses/>. |
8199
ec1b4cd5fbbb
cla.m: Add matlab function cla().
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
22 |
ec1b4cd5fbbb
cla.m: Add matlab function cla().
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
23 ## -*- texinfo -*- |
20852
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20286
diff
changeset
|
24 ## @deftypefn {} {} cla |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20286
diff
changeset
|
25 ## @deftypefnx {} {} cla reset |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20286
diff
changeset
|
26 ## @deftypefnx {} {} cla (@var{hax}) |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20286
diff
changeset
|
27 ## @deftypefnx {} {} cla (@var{hax}, "reset") |
24433
96a228168986
cla.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents:
24432
diff
changeset
|
28 ## Clear the current or specified (@var{hax}) axes object. |
17122
eaab03308c0b
doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents:
17081
diff
changeset
|
29 ## |
eaab03308c0b
doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents:
17081
diff
changeset
|
30 ## @code{cla} operates by deleting child graphic objects with visible |
24433
96a228168986
cla.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents:
24432
diff
changeset
|
31 ## handles (@code{HandleVisibility} = @qcode{"on"}). This typically clears the |
96a228168986
cla.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents:
24432
diff
changeset
|
32 ## axes of any visual objects, but leaves in place axes limits, tick marks and |
96a228168986
cla.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents:
24432
diff
changeset
|
33 ## labels, camera view, etc. In addition, the automatic coloring and styling |
96a228168986
cla.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents:
24432
diff
changeset
|
34 ## of lines is reset by changing the axes properties @code{ColorOrderIndex}, |
96a228168986
cla.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents:
24432
diff
changeset
|
35 ## @code{LinestyleOrderIndex} to 1. |
17081
86067af51d5e
Truly reset axes so that all properties are set to default.
Rik <rik@octave.org>
parents:
14363
diff
changeset
|
36 ## |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17125
diff
changeset
|
37 ## If the optional argument @qcode{"reset"} is specified, delete all child |
24433
96a228168986
cla.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents:
24432
diff
changeset
|
38 ## objects, including those with hidden handles, and reset all axes properties |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17125
diff
changeset
|
39 ## to their defaults. However, the following properties are not reset: |
24433
96a228168986
cla.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents:
24432
diff
changeset
|
40 ## @code{Position}, @code{Units}. |
17081
86067af51d5e
Truly reset axes so that all properties are set to default.
Rik <rik@octave.org>
parents:
14363
diff
changeset
|
41 ## |
17122
eaab03308c0b
doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents:
17081
diff
changeset
|
42 ## If the first argument @var{hax} is an axes handle, then operate on |
24431
0c6cedafc71e
doc: Use 'axes' rather than 'axis' appropriately in docstrings.
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
43 ## this axes rather than the current axes returned by @code{gca}. |
17443
0aa77acf22f5
doc: Add seealso references between cla, clf, reset functions.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
44 ## @seealso{clf, delete, reset} |
8199
ec1b4cd5fbbb
cla.m: Add matlab function cla().
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
45 ## @end deftypefn |
ec1b4cd5fbbb
cla.m: Add matlab function cla().
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
46 |
ec1b4cd5fbbb
cla.m: Add matlab function cla().
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
47 ## Author: Ben Abbott <bpabbott@mac.com> |
ec1b4cd5fbbb
cla.m: Add matlab function cla().
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
48 ## Created: 2008-10-03 |
ec1b4cd5fbbb
cla.m: Add matlab function cla().
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
49 |
24433
96a228168986
cla.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents:
24432
diff
changeset
|
50 function cla (hax, do_reset = false) |
8199
ec1b4cd5fbbb
cla.m: Add matlab function cla().
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
51 |
ec1b4cd5fbbb
cla.m: Add matlab function cla().
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
52 if (nargin > 2) |
ec1b4cd5fbbb
cla.m: Add matlab function cla().
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
53 print_usage (); |
24433
96a228168986
cla.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents:
24432
diff
changeset
|
54 endif |
96a228168986
cla.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents:
24432
diff
changeset
|
55 |
96a228168986
cla.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents:
24432
diff
changeset
|
56 if (nargin == 0) |
17081
86067af51d5e
Truly reset axes so that all properties are set to default.
Rik <rik@octave.org>
parents:
14363
diff
changeset
|
57 hax = gca; |
8199
ec1b4cd5fbbb
cla.m: Add matlab function cla().
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
58 elseif (nargin == 1) |
24433
96a228168986
cla.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents:
24432
diff
changeset
|
59 if (isscalar (hax) && isaxes (hax)) |
96a228168986
cla.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents:
24432
diff
changeset
|
60 ## Normal case : cla (hax) without reset |
96a228168986
cla.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents:
24432
diff
changeset
|
61 elseif (ischar (hax) && strcmpi (hax, "reset")) |
8199
ec1b4cd5fbbb
cla.m: Add matlab function cla().
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
62 hax = gca; |
ec1b4cd5fbbb
cla.m: Add matlab function cla().
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
63 do_reset = true; |
ec1b4cd5fbbb
cla.m: Add matlab function cla().
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
64 else |
ec1b4cd5fbbb
cla.m: Add matlab function cla().
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
65 print_usage (); |
ec1b4cd5fbbb
cla.m: Add matlab function cla().
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
66 endif |
ec1b4cd5fbbb
cla.m: Add matlab function cla().
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
67 else |
24433
96a228168986
cla.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents:
24432
diff
changeset
|
68 if (isscalar (hax) && isaxes (hax) |
96a228168986
cla.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents:
24432
diff
changeset
|
69 && ischar (do_reset) && strcmpi (do_reset, "reset")) |
17081
86067af51d5e
Truly reset axes so that all properties are set to default.
Rik <rik@octave.org>
parents:
14363
diff
changeset
|
70 do_reset = true; |
86067af51d5e
Truly reset axes so that all properties are set to default.
Rik <rik@octave.org>
parents:
14363
diff
changeset
|
71 else |
86067af51d5e
Truly reset axes so that all properties are set to default.
Rik <rik@octave.org>
parents:
14363
diff
changeset
|
72 print_usage (); |
86067af51d5e
Truly reset axes so that all properties are set to default.
Rik <rik@octave.org>
parents:
14363
diff
changeset
|
73 endif |
8610
85c9906abfd1
use endif and endfor instead of end
John W. Eaton <jwe@octave.org>
parents:
8285
diff
changeset
|
74 endif |
8199
ec1b4cd5fbbb
cla.m: Add matlab function cla().
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
75 |
17081
86067af51d5e
Truly reset axes so that all properties are set to default.
Rik <rik@octave.org>
parents:
14363
diff
changeset
|
76 if (! do_reset) |
86067af51d5e
Truly reset axes so that all properties are set to default.
Rik <rik@octave.org>
parents:
14363
diff
changeset
|
77 delete (get (hax, "children")); |
24433
96a228168986
cla.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents:
24432
diff
changeset
|
78 set (hax, "colororderindex", 1, "linestyleorderindex", 1); |
17081
86067af51d5e
Truly reset axes so that all properties are set to default.
Rik <rik@octave.org>
parents:
14363
diff
changeset
|
79 else |
23013
5dca1727ce94
cla.m, newplot.m: make use of reset function to cleanup listeners (bug #49980).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
22755
diff
changeset
|
80 delete (allchild (hax)); |
5dca1727ce94
cla.m, newplot.m: make use of reset function to cleanup listeners (bug #49980).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
22755
diff
changeset
|
81 reset (hax); |
8264
bca580bbda02
cla.m: Fix error when no children to clear.
Ben Abbott <bpabbott@mac.com>
parents:
8199
diff
changeset
|
82 endif |
8199
ec1b4cd5fbbb
cla.m: Add matlab function cla().
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
83 |
ec1b4cd5fbbb
cla.m: Add matlab function cla().
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
84 endfunction |
8264
bca580bbda02
cla.m: Fix error when no children to clear.
Ben Abbott <bpabbott@mac.com>
parents:
8199
diff
changeset
|
85 |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
86 |
8264
bca580bbda02
cla.m: Fix error when no children to clear.
Ben Abbott <bpabbott@mac.com>
parents:
8199
diff
changeset
|
87 %!test |
13124
2ea1658ad049
Don't use explicit figure number for tests to avoid interference with any figures opened by user.
Kai Habel <kai.habel@gmx.de>
parents:
13111
diff
changeset
|
88 %! hf = figure ("visible", "off"); |
13141
e81ddf9cacd5
maint: untabify and remove trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
13124
diff
changeset
|
89 %! unwind_protect |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
90 %! plot (1:10); |
17122
eaab03308c0b
doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents:
17081
diff
changeset
|
91 %! assert (! isempty (get (gca, "children"))); |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
92 %! cla (); |
17122
eaab03308c0b
doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents:
17081
diff
changeset
|
93 %! assert (isempty (get (gca, "children"))); |
8264
bca580bbda02
cla.m: Fix error when no children to clear.
Ben Abbott <bpabbott@mac.com>
parents:
8199
diff
changeset
|
94 %! unwind_protect_cleanup |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
95 %! close (hf); |
8264
bca580bbda02
cla.m: Fix error when no children to clear.
Ben Abbott <bpabbott@mac.com>
parents:
8199
diff
changeset
|
96 %! end_unwind_protect |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
97 |
17081
86067af51d5e
Truly reset axes so that all properties are set to default.
Rik <rik@octave.org>
parents:
14363
diff
changeset
|
98 %!test |
86067af51d5e
Truly reset axes so that all properties are set to default.
Rik <rik@octave.org>
parents:
14363
diff
changeset
|
99 %! hf = figure ("visible", "off"); |
86067af51d5e
Truly reset axes so that all properties are set to default.
Rik <rik@octave.org>
parents:
14363
diff
changeset
|
100 %! unwind_protect |
86067af51d5e
Truly reset axes so that all properties are set to default.
Rik <rik@octave.org>
parents:
14363
diff
changeset
|
101 %! hax = gca; |
86067af51d5e
Truly reset axes so that all properties are set to default.
Rik <rik@octave.org>
parents:
14363
diff
changeset
|
102 %! plot (hax, 1:10); |
24433
96a228168986
cla.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents:
24432
diff
changeset
|
103 %! assert (get (hax, "colororderindex"), 2); |
20286
42b7d7758c4a
Remove axes "interpreter" property (bug #45388)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19697
diff
changeset
|
104 %! set (hax, "ticklabelinterpreter", "none"); |
17081
86067af51d5e
Truly reset axes so that all properties are set to default.
Rik <rik@octave.org>
parents:
14363
diff
changeset
|
105 %! cla (hax); |
86067af51d5e
Truly reset axes so that all properties are set to default.
Rik <rik@octave.org>
parents:
14363
diff
changeset
|
106 %! kids = get (hax, "children"); |
86067af51d5e
Truly reset axes so that all properties are set to default.
Rik <rik@octave.org>
parents:
14363
diff
changeset
|
107 %! assert (numel (kids), 0); |
24433
96a228168986
cla.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents:
24432
diff
changeset
|
108 %! assert (get (hax, "colororderindex"), 1); |
20286
42b7d7758c4a
Remove axes "interpreter" property (bug #45388)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19697
diff
changeset
|
109 %! assert (get (hax, "ticklabelinterpreter"), "none"); |
24433
96a228168986
cla.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents:
24432
diff
changeset
|
110 %! |
96a228168986
cla.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents:
24432
diff
changeset
|
111 %! hp = plot (hax, 1:10, "handlevisibility", "off"); |
96a228168986
cla.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents:
24432
diff
changeset
|
112 %! cla (hax); |
96a228168986
cla.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents:
24432
diff
changeset
|
113 %! assert (ishghandle (hp), true); |
96a228168986
cla.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents:
24432
diff
changeset
|
114 %! |
17081
86067af51d5e
Truly reset axes so that all properties are set to default.
Rik <rik@octave.org>
parents:
14363
diff
changeset
|
115 %! cla (hax, "reset"); |
86067af51d5e
Truly reset axes so that all properties are set to default.
Rik <rik@octave.org>
parents:
14363
diff
changeset
|
116 %! kids = get (hax, "children"); |
86067af51d5e
Truly reset axes so that all properties are set to default.
Rik <rik@octave.org>
parents:
14363
diff
changeset
|
117 %! assert (numel (kids), 0); |
24433
96a228168986
cla.m: Overhaul function for greater Matlab compatibility.
Rik <rik@octave.org>
parents:
24432
diff
changeset
|
118 %! assert (ishghandle (hp), false); |
20286
42b7d7758c4a
Remove axes "interpreter" property (bug #45388)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
19697
diff
changeset
|
119 %! assert (get (hax, "ticklabelinterpreter"), "tex"); |
17081
86067af51d5e
Truly reset axes so that all properties are set to default.
Rik <rik@octave.org>
parents:
14363
diff
changeset
|
120 %! unwind_protect_cleanup |
86067af51d5e
Truly reset axes so that all properties are set to default.
Rik <rik@octave.org>
parents:
14363
diff
changeset
|
121 %! close (hf); |
86067af51d5e
Truly reset axes so that all properties are set to default.
Rik <rik@octave.org>
parents:
14363
diff
changeset
|
122 %! end_unwind_protect |