Mercurial > hg > octave-nkf
annotate scripts/plot/util/linkprop.m @ 18888:e68788478aa1
linkprop.m: Overhaul function for performance and Matlab compatibility.
* NEWS: Announce changes in linkprop behavior.
* linkprop.m: Redo docstring. Add more input validation. When linking, set
property values to be that of the first object in the list (missing Matlab
compatibility). Use onCleanup instead of an hggroup in order for 'clear hlink'
command to correctly unlink properties. For performance, avoid for loops in
update_prop and use set() with multiple handles. Add %!demo, %!test, and
%!error code to verify function.
author | Rik <rik@octave.org> |
---|---|
date | Sat, 03 May 2014 16:51:00 -0700 |
parents | d63878346099 |
children | d1750be79dee |
rev | line source |
---|---|
17744
d63878346099
maint: Update copyright notices for release.
John W. Eaton <jwe@octave.org>
parents:
17572
diff
changeset
|
1 ## Copyright (C) 2008-2013 David Bateman |
8070
3b53b25e2550
Add data sources and line series
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2 ## |
3b53b25e2550
Add data sources and line series
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3 ## This file is part of Octave. |
3b53b25e2550
Add data sources and line series
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
4 ## |
3b53b25e2550
Add data sources and line series
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
5 ## Octave is free software; you can redistribute it and/or modify it |
3b53b25e2550
Add data sources and line series
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
6 ## under the terms of the GNU General Public License as published by |
3b53b25e2550
Add data sources and line series
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
7 ## the Free Software Foundation; either version 3 of the License, or (at |
3b53b25e2550
Add data sources and line series
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
8 ## your option) any later version. |
3b53b25e2550
Add data sources and line series
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
9 ## |
3b53b25e2550
Add data sources and line series
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
10 ## Octave is distributed in the hope that it will be useful, but |
3b53b25e2550
Add data sources and line series
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
3b53b25e2550
Add data sources and line series
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
3b53b25e2550
Add data sources and line series
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
13 ## General Public License for more details. |
3b53b25e2550
Add data sources and line series
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
14 ## |
3b53b25e2550
Add data sources and line series
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
15 ## You should have received a copy of the GNU General Public License |
3b53b25e2550
Add data sources and line series
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
16 ## along with Octave; see the file COPYING. If not, see |
3b53b25e2550
Add data sources and line series
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
17 ## <http://www.gnu.org/licenses/>. |
3b53b25e2550
Add data sources and line series
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
18 |
3b53b25e2550
Add data sources and line series
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
19 ## -*- texinfo -*- |
18888
e68788478aa1
linkprop.m: Overhaul function for performance and Matlab compatibility.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
20 ## @deftypefn {Function File} {@var{hlink} =} linkprop (@var{h}, "@var{prop}") |
e68788478aa1
linkprop.m: Overhaul function for performance and Matlab compatibility.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
21 ## @deftypefnx {Function File} {@var{hlink} =} linkprop (@var{h}, @{"@var{prop1}", "@var{prop2}", @dots{}@}) |
e68788478aa1
linkprop.m: Overhaul function for performance and Matlab compatibility.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
22 ## Link graphic object properties, such that a change in one is propagated to |
e68788478aa1
linkprop.m: Overhaul function for performance and Matlab compatibility.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
23 ## the others. |
e68788478aa1
linkprop.m: Overhaul function for performance and Matlab compatibility.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
24 ## |
e68788478aa1
linkprop.m: Overhaul function for performance and Matlab compatibility.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
25 ## The input @var{h} is a vector of graphic handles to link. |
8070
3b53b25e2550
Add data sources and line series
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
26 ## |
18888
e68788478aa1
linkprop.m: Overhaul function for performance and Matlab compatibility.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
27 ## @var{prop} may be a string when linking a single property, or a cell array |
e68788478aa1
linkprop.m: Overhaul function for performance and Matlab compatibility.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
28 ## of strings for multiple properties. During the linking process all |
e68788478aa1
linkprop.m: Overhaul function for performance and Matlab compatibility.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
29 ## properties in @var{prop} will initially be set to the values that exist on |
e68788478aa1
linkprop.m: Overhaul function for performance and Matlab compatibility.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
30 ## the first object in the list @var{h}. |
e68788478aa1
linkprop.m: Overhaul function for performance and Matlab compatibility.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
31 ## |
e68788478aa1
linkprop.m: Overhaul function for performance and Matlab compatibility.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
32 ## The function returns @var{hlink} which is a special object describing the |
e68788478aa1
linkprop.m: Overhaul function for performance and Matlab compatibility.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
33 ## link. As long as the reference @var{hlink} exists the link between graphic |
e68788478aa1
linkprop.m: Overhaul function for performance and Matlab compatibility.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
34 ## objects will be active. This means that @var{hlink} must be preserved in |
e68788478aa1
linkprop.m: Overhaul function for performance and Matlab compatibility.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
35 ## a workspace variable, a global variable, or otherwise stored using a |
e68788478aa1
linkprop.m: Overhaul function for performance and Matlab compatibility.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
36 ## function such as @code{setappdata}, @code{guidata}. To unlink properties, |
e68788478aa1
linkprop.m: Overhaul function for performance and Matlab compatibility.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
37 ## execute @code{clear @var{hlink}}. |
17122
eaab03308c0b
doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents:
14327
diff
changeset
|
38 ## |
eaab03308c0b
doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents:
14327
diff
changeset
|
39 ## An example of the use of @code{linkprop} is |
8070
3b53b25e2550
Add data sources and line series
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
40 ## |
3b53b25e2550
Add data sources and line series
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
41 ## @example |
3b53b25e2550
Add data sources and line series
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
42 ## @group |
3b53b25e2550
Add data sources and line series
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
43 ## x = 0:0.1:10; |
14327
4d917a6a858b
doc: Use Octave coding conventions in @example blocks of docstrings.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
44 ## subplot (1,2,1); |
8070
3b53b25e2550
Add data sources and line series
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
45 ## h1 = plot (x, sin (x)); |
14327
4d917a6a858b
doc: Use Octave coding conventions in @example blocks of docstrings.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
46 ## subplot (1,2,2); |
8070
3b53b25e2550
Add data sources and line series
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
47 ## h2 = plot (x, cos (x)); |
3b53b25e2550
Add data sources and line series
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
48 ## hlink = linkprop ([h1, h2], @{"color","linestyle"@}); |
3b53b25e2550
Add data sources and line series
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
49 ## set (h1, "color", "green"); |
3b53b25e2550
Add data sources and line series
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
50 ## set (h2, "linestyle", "--"); |
3b53b25e2550
Add data sources and line series
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
51 ## @end group |
3b53b25e2550
Add data sources and line series
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
52 ## @end example |
3b53b25e2550
Add data sources and line series
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
53 ## |
18888
e68788478aa1
linkprop.m: Overhaul function for performance and Matlab compatibility.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
54 ## @seealso{linkaxes} |
8070
3b53b25e2550
Add data sources and line series
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
55 ## @end deftypefn |
3b53b25e2550
Add data sources and line series
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
56 |
3b53b25e2550
Add data sources and line series
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
57 function hlink = linkprop (h, prop) |
18888
e68788478aa1
linkprop.m: Overhaul function for performance and Matlab compatibility.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
58 |
e68788478aa1
linkprop.m: Overhaul function for performance and Matlab compatibility.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
59 if (nargin != 2) |
e68788478aa1
linkprop.m: Overhaul function for performance and Matlab compatibility.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
60 print_usage (); |
e68788478aa1
linkprop.m: Overhaul function for performance and Matlab compatibility.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
61 endif |
e68788478aa1
linkprop.m: Overhaul function for performance and Matlab compatibility.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
62 |
e68788478aa1
linkprop.m: Overhaul function for performance and Matlab compatibility.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
63 if (numel (h) < 2) |
e68788478aa1
linkprop.m: Overhaul function for performance and Matlab compatibility.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
64 error ("linkprop: H must contain at least 2 handles"); |
e68788478aa1
linkprop.m: Overhaul function for performance and Matlab compatibility.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
65 elseif (! all (ishandle (h(:)))) |
e68788478aa1
linkprop.m: Overhaul function for performance and Matlab compatibility.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
66 error ("linkprop: invalid graphic handle in input H"); |
e68788478aa1
linkprop.m: Overhaul function for performance and Matlab compatibility.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
67 endif |
e68788478aa1
linkprop.m: Overhaul function for performance and Matlab compatibility.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
68 |
8070
3b53b25e2550
Add data sources and line series
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
69 if (ischar (prop)) |
3b53b25e2550
Add data sources and line series
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
70 prop = {prop}; |
18888
e68788478aa1
linkprop.m: Overhaul function for performance and Matlab compatibility.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
71 elseif (! iscellstr (prop)) |
e68788478aa1
linkprop.m: Overhaul function for performance and Matlab compatibility.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
72 error ("linkprop: PROP must be a string or cell string array"); |
8070
3b53b25e2550
Add data sources and line series
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
73 endif |
3b53b25e2550
Add data sources and line series
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
74 |
18888
e68788478aa1
linkprop.m: Overhaul function for performance and Matlab compatibility.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
75 h = h(:)'; # set() prefers column vectors |
e68788478aa1
linkprop.m: Overhaul function for performance and Matlab compatibility.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
76 ## Match all objects to the first one in the list before linking |
e68788478aa1
linkprop.m: Overhaul function for performance and Matlab compatibility.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
77 for j = 1 : numel (prop) |
e68788478aa1
linkprop.m: Overhaul function for performance and Matlab compatibility.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
78 set (h(2:end), prop{j}, get (h(1), prop{j})); |
e68788478aa1
linkprop.m: Overhaul function for performance and Matlab compatibility.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
79 endfor |
e68788478aa1
linkprop.m: Overhaul function for performance and Matlab compatibility.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
80 |
e68788478aa1
linkprop.m: Overhaul function for performance and Matlab compatibility.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
81 ## Add listeners to all objects |
8070
3b53b25e2550
Add data sources and line series
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
82 for i = 1 : numel (h) |
3b53b25e2550
Add data sources and line series
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
83 for j = 1 : numel (prop) |
18888
e68788478aa1
linkprop.m: Overhaul function for performance and Matlab compatibility.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
84 addlistener (h(i), prop{j}, |
e68788478aa1
linkprop.m: Overhaul function for performance and Matlab compatibility.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
85 {@update_prop, [h(1:i-1),h(i+1:end)], prop{j}}); |
8070
3b53b25e2550
Add data sources and line series
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
86 endfor |
3b53b25e2550
Add data sources and line series
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
87 endfor |
3b53b25e2550
Add data sources and line series
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
88 |
18888
e68788478aa1
linkprop.m: Overhaul function for performance and Matlab compatibility.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
89 hlink = onCleanup (@() delete_linkprop (h, prop)); |
e68788478aa1
linkprop.m: Overhaul function for performance and Matlab compatibility.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
90 |
8070
3b53b25e2550
Add data sources and line series
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
91 endfunction |
3b53b25e2550
Add data sources and line series
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
92 |
18888
e68788478aa1
linkprop.m: Overhaul function for performance and Matlab compatibility.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
93 function update_prop (h, ~, hlist, prop) |
8070
3b53b25e2550
Add data sources and line series
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
94 persistent recursion = false; |
3b53b25e2550
Add data sources and line series
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
95 |
3b53b25e2550
Add data sources and line series
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
96 ## Don't allow recursion |
3b53b25e2550
Add data sources and line series
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
97 if (! recursion) |
3b53b25e2550
Add data sources and line series
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
98 unwind_protect |
3b53b25e2550
Add data sources and line series
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
99 recursion = true; |
18888
e68788478aa1
linkprop.m: Overhaul function for performance and Matlab compatibility.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
100 set (hlist(ishandle (hlist)), prop, get (h, prop)); |
8070
3b53b25e2550
Add data sources and line series
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
101 unwind_protect_cleanup |
3b53b25e2550
Add data sources and line series
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
102 recursion = false; |
3b53b25e2550
Add data sources and line series
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
103 end_unwind_protect |
3b53b25e2550
Add data sources and line series
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
104 endif |
3b53b25e2550
Add data sources and line series
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
105 endfunction |
3b53b25e2550
Add data sources and line series
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
106 |
18888
e68788478aa1
linkprop.m: Overhaul function for performance and Matlab compatibility.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
107 function delete_linkprop (hlist, prop) |
e68788478aa1
linkprop.m: Overhaul function for performance and Matlab compatibility.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
108 |
e68788478aa1
linkprop.m: Overhaul function for performance and Matlab compatibility.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
109 for i = 1 : numel (hlist) |
e68788478aa1
linkprop.m: Overhaul function for performance and Matlab compatibility.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
110 if (ishandle (hlist(i))) |
e68788478aa1
linkprop.m: Overhaul function for performance and Matlab compatibility.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
111 for j = 1 : numel (prop) |
e68788478aa1
linkprop.m: Overhaul function for performance and Matlab compatibility.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
112 dellistener (hlist(i), prop{j}), |
e68788478aa1
linkprop.m: Overhaul function for performance and Matlab compatibility.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
113 endfor |
8070
3b53b25e2550
Add data sources and line series
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
114 endif |
3b53b25e2550
Add data sources and line series
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
115 endfor |
18888
e68788478aa1
linkprop.m: Overhaul function for performance and Matlab compatibility.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
116 |
8070
3b53b25e2550
Add data sources and line series
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
117 endfunction |
17338
1c89599167a6
maint: End m-files with 1 blank line.
Rik <rik@octave.org>
parents:
17122
diff
changeset
|
118 |
18888
e68788478aa1
linkprop.m: Overhaul function for performance and Matlab compatibility.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
119 |
e68788478aa1
linkprop.m: Overhaul function for performance and Matlab compatibility.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
120 %!demo |
e68788478aa1
linkprop.m: Overhaul function for performance and Matlab compatibility.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
121 %! clf; |
e68788478aa1
linkprop.m: Overhaul function for performance and Matlab compatibility.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
122 %! x = 0:0.1:10; |
e68788478aa1
linkprop.m: Overhaul function for performance and Matlab compatibility.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
123 %! subplot (1,2,1); |
e68788478aa1
linkprop.m: Overhaul function for performance and Matlab compatibility.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
124 %! h1 = plot (x, sin (x), "r"); |
e68788478aa1
linkprop.m: Overhaul function for performance and Matlab compatibility.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
125 %! subplot (1,2,2); |
e68788478aa1
linkprop.m: Overhaul function for performance and Matlab compatibility.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
126 %! h2 = plot (x, cos (x), "b"); |
e68788478aa1
linkprop.m: Overhaul function for performance and Matlab compatibility.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
127 %! input ("Type <RETURN> to link plots"); |
e68788478aa1
linkprop.m: Overhaul function for performance and Matlab compatibility.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
128 %! hlink = linkprop ([h1, h2], {"color", "linestyle"}); |
e68788478aa1
linkprop.m: Overhaul function for performance and Matlab compatibility.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
129 %! input ("Type <RETURN> to change color"); |
e68788478aa1
linkprop.m: Overhaul function for performance and Matlab compatibility.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
130 %! set (h1, "color", "green"); |
e68788478aa1
linkprop.m: Overhaul function for performance and Matlab compatibility.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
131 %! input ("Type <RETURN> to change linestyle"); |
e68788478aa1
linkprop.m: Overhaul function for performance and Matlab compatibility.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
132 %! set (h2, "linestyle", "--"); |
e68788478aa1
linkprop.m: Overhaul function for performance and Matlab compatibility.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
133 |
e68788478aa1
linkprop.m: Overhaul function for performance and Matlab compatibility.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
134 %!test |
e68788478aa1
linkprop.m: Overhaul function for performance and Matlab compatibility.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
135 %! hf1 = figure ("visible", "off"); |
e68788478aa1
linkprop.m: Overhaul function for performance and Matlab compatibility.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
136 %! hl1 = plot (1:10, "or"); |
e68788478aa1
linkprop.m: Overhaul function for performance and Matlab compatibility.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
137 %! hf2 = figure ("visible", "off"); |
e68788478aa1
linkprop.m: Overhaul function for performance and Matlab compatibility.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
138 %! hl2 = plot (1:10, "-*g"); |
e68788478aa1
linkprop.m: Overhaul function for performance and Matlab compatibility.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
139 %! hf3 = figure ("visible", "off"); |
e68788478aa1
linkprop.m: Overhaul function for performance and Matlab compatibility.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
140 %! hl3 = plot (1:10, "-xb"); |
e68788478aa1
linkprop.m: Overhaul function for performance and Matlab compatibility.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
141 %! unwind_protect |
e68788478aa1
linkprop.m: Overhaul function for performance and Matlab compatibility.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
142 %! hlink = linkprop ([hl1, hl2, hl3], {"color", "linestyle"}); |
e68788478aa1
linkprop.m: Overhaul function for performance and Matlab compatibility.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
143 %! ## Test initial values taken from first object in list |
e68788478aa1
linkprop.m: Overhaul function for performance and Matlab compatibility.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
144 %! assert (get (hl2, "color"), [1 0 0]); |
e68788478aa1
linkprop.m: Overhaul function for performance and Matlab compatibility.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
145 %! assert (get (hl3, "linestyle"), "none"); |
e68788478aa1
linkprop.m: Overhaul function for performance and Matlab compatibility.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
146 %! ## Test linking |
e68788478aa1
linkprop.m: Overhaul function for performance and Matlab compatibility.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
147 %! set (hl2, "color", "b"); |
e68788478aa1
linkprop.m: Overhaul function for performance and Matlab compatibility.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
148 %! assert (get (hl1, "color"), [0 0 1]); |
e68788478aa1
linkprop.m: Overhaul function for performance and Matlab compatibility.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
149 %! assert (get (hl3, "color"), [0 0 1]); |
e68788478aa1
linkprop.m: Overhaul function for performance and Matlab compatibility.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
150 %! set (hl3, "linestyle", "--"); |
e68788478aa1
linkprop.m: Overhaul function for performance and Matlab compatibility.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
151 %! assert (get (hl1, "linestyle"), "--"); |
e68788478aa1
linkprop.m: Overhaul function for performance and Matlab compatibility.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
152 %! assert (get (hl2, "linestyle"), "--"); |
e68788478aa1
linkprop.m: Overhaul function for performance and Matlab compatibility.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
153 %! ## Test linking of remaining objects after deletion of one object |
e68788478aa1
linkprop.m: Overhaul function for performance and Matlab compatibility.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
154 %! delete (hl2); |
e68788478aa1
linkprop.m: Overhaul function for performance and Matlab compatibility.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
155 %! set (hl1, "linestyle", ":"); |
e68788478aa1
linkprop.m: Overhaul function for performance and Matlab compatibility.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
156 %! assert (get (hl3, "linestyle"), ":"); |
e68788478aa1
linkprop.m: Overhaul function for performance and Matlab compatibility.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
157 %! ## Test deletion of link |
e68788478aa1
linkprop.m: Overhaul function for performance and Matlab compatibility.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
158 %! clear hlink; |
e68788478aa1
linkprop.m: Overhaul function for performance and Matlab compatibility.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
159 %! set (hl1, "color", "g"); |
e68788478aa1
linkprop.m: Overhaul function for performance and Matlab compatibility.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
160 %! assert (get (hl3, "color"), [0 0 1]); |
e68788478aa1
linkprop.m: Overhaul function for performance and Matlab compatibility.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
161 %! unwind_protect_cleanup |
e68788478aa1
linkprop.m: Overhaul function for performance and Matlab compatibility.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
162 %! close ([hf1 hf2 hf3]); |
e68788478aa1
linkprop.m: Overhaul function for performance and Matlab compatibility.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
163 %! end_unwind_protect |
e68788478aa1
linkprop.m: Overhaul function for performance and Matlab compatibility.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
164 |
e68788478aa1
linkprop.m: Overhaul function for performance and Matlab compatibility.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
165 %% Test input validation |
e68788478aa1
linkprop.m: Overhaul function for performance and Matlab compatibility.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
166 %!error linkprop () |
e68788478aa1
linkprop.m: Overhaul function for performance and Matlab compatibility.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
167 %!error linkprop (1) |
e68788478aa1
linkprop.m: Overhaul function for performance and Matlab compatibility.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
168 %!error linkprop (1,2,3) |
e68788478aa1
linkprop.m: Overhaul function for performance and Matlab compatibility.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
169 %!error <H must contain at least 2 handles> linkprop (1, "color") |
e68788478aa1
linkprop.m: Overhaul function for performance and Matlab compatibility.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
170 %!error <invalid graphic handle in input H> linkprop ([pi, e], "color") |
e68788478aa1
linkprop.m: Overhaul function for performance and Matlab compatibility.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
171 %!error <PROP must be a string or cell string array> linkprop ([0, 0], 1) |
e68788478aa1
linkprop.m: Overhaul function for performance and Matlab compatibility.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
172 |