Mercurial > hg > octave-nkf
comparison scripts/plot/util/newplot.m @ 17719:ed9a21a90221
Fix incorrect parenting of axes and hggroups (bug #39813)
Modify newplot to accept any type of graphics handle so that it can be
preserved. Modify __plt_get_axis_arg__ to return "parent" handle instead of
axis handle.
* newplot.m: Make the function preserve the hsave handle. Add Matlab compatible tests
*__plt_get_axis_arg__: Return "parent" argument in case one is specified instead of axis.
author | Pantxo Diribarne <pantxo.diribarne@gmail.com> |
---|---|
date | Mon, 23 Sep 2013 19:44:57 +0200 |
parents | 7bb76a22cde1 |
children | 1ab8e21d9cfc |
comparison
equal
deleted
inserted
replaced
17718:6ed0a8532bcf | 17719:ed9a21a90221 |
---|---|
136 endswitch | 136 endswitch |
137 set (cf, "nextplot", "add"); # Matlab compatibility | 137 set (cf, "nextplot", "add"); # Matlab compatibility |
138 | 138 |
139 if (isempty (ca)) | 139 if (isempty (ca)) |
140 ca = gca (); | 140 ca = gca (); |
141 deleteall = true; | |
141 else | 142 else |
142 set (cf, "currentaxes", ca); | 143 set (cf, "currentaxes", ca); |
144 deleteall = false; | |
143 endif | 145 endif |
144 | 146 |
145 ## FIXME: Is this necessary anymore? | 147 ## FIXME: Is this necessary anymore? |
146 ## It seems like a kluge that belongs somewhere else. | 148 ## It seems like a kluge that belongs somewhere else. |
147 if (strcmp (get (ca, "__hold_all__"), "off")) | 149 if (strcmp (get (ca, "__hold_all__"), "off")) |
157 case "add" | 159 case "add" |
158 ## Default case. Doesn't require action. | 160 ## Default case. Doesn't require action. |
159 case "replacechildren" | 161 case "replacechildren" |
160 delete (get (ca, "children")); | 162 delete (get (ca, "children")); |
161 case "replace" | 163 case "replace" |
162 __go_axes_init__ (ca, "replace"); | 164 if (! deleteall && ca != hsave) |
163 __request_drawnow__ (); | 165 ## preserve hsave and its parents, uncles, ... |
166 kids = allchild (ca); | |
167 hkid = hsave; | |
168 while (! any (hkid == kids)) | |
169 hkid = get (hkid, "parent"); | |
170 endwhile | |
171 kids(kids == hkid) = []; | |
172 delete (kids); | |
173 else | |
174 __go_axes_init__ (ca, "replace"); | |
175 __request_drawnow__ (); | |
176 endif | |
164 ## FIXME: The code above should perform the following: | 177 ## FIXME: The code above should perform the following: |
165 ########################### | 178 ########################### |
166 ## delete (allchild (ca)); | 179 ## delete (allchild (ca)); |
167 ## reset (ca); | 180 ## reset (ca); |
168 ########################### | 181 ########################### |
190 %! assert (isempty (get (gca, "children"))); | 203 %! assert (isempty (get (gca, "children"))); |
191 %! unwind_protect_cleanup | 204 %! unwind_protect_cleanup |
192 %! close (hf); | 205 %! close (hf); |
193 %! end_unwind_protect | 206 %! end_unwind_protect |
194 | 207 |
208 %!test | |
209 %! hf = figure ("visible", "off"); | |
210 %! unwind_protect | |
211 %! hax = axes (); | |
212 %! hold on; | |
213 %! hg1 = hggroup (); | |
214 %! hg2 = hggroup ("parent", hg1); | |
215 %! li0 = line (1:10, 1:10); | |
216 %! li1 = line (1:10, -1:-1:-10, "parent", hg1); | |
217 %! li2 = line (1:10, sin (1:10), "parent", hg2); | |
218 %! hold off; | |
219 %! newplot (hg2); | |
220 %! assert (ishandle (li0), false); | |
221 %! assert (get (hax, "children"), hg1); | |
222 %! | |
223 %! ## kids are preserved for hggroups | |
224 %! kids = get (hg1, "children"); | |
225 %! newplot (hg1); | |
226 %! assert (get (hg1, "children"), kids)); | |
227 %! | |
228 %! ## preserve objects | |
229 %! newplot (li1); | |
230 %! assert (ishandle (li1)); | |
231 %! | |
232 %! ## kids are deleted for axes | |
233 %! newplot (hax); | |
234 %! assert (isempty (get (hax, "children"))); | |
235 %! unwind_protect_cleanup | |
236 %! close (hf); | |
237 %! end_unwind_protect | |
238 |