Mercurial > hg > octave-nkf
comparison scripts/plot/findobj.m @ 17238:3fd617363762
findobj.m: Return handles in hierarchy order rather than sorted order (bug #39767).
* scripts/plot/findobj.m: Use concatenation rather than union to join lists of
handles together. Update %!tests to reflect new ordering.
* scripts/plot/findall.m: Update %!tests to reflect new ordering.
author | Rik <rik@octave.org> |
---|---|
date | Tue, 13 Aug 2013 16:38:25 -0700 |
parents | eaab03308c0b |
children | bc924baa2c4e |
comparison
equal
deleted
inserted
replaced
17237:5f14fc8feba3 | 17238:3fd617363762 |
---|---|
196 idepth = 0; | 196 idepth = 0; |
197 h = handles; | 197 h = handles; |
198 while (numel (handles) && ! (idepth >= depth)) | 198 while (numel (handles) && ! (idepth >= depth)) |
199 children = []; | 199 children = []; |
200 for n = 1 : numel (handles) | 200 for n = 1 : numel (handles) |
201 children = union (children, get (handles(n), "children")); | 201 children = [children; get(handles(n), "children")]; |
202 endfor | 202 endfor |
203 handles = children; | 203 handles = children; |
204 h = union (h, children); | 204 h = [h; children]; |
205 idepth = idepth + 1; | 205 idepth = idepth + 1; |
206 endwhile | 206 endwhile |
207 | 207 |
208 if (numpairs > 0) | 208 if (numpairs > 0) |
209 match = true (numel (h), numpairs); | 209 match = true (numel (h), numpairs); |
272 | 272 |
273 h = h(match); | 273 h = h(match); |
274 h = h(:); | 274 h = h(:); |
275 endfunction | 275 endfunction |
276 | 276 |
277 %!test | 277 |
278 %! hf = figure ("visible", "off"); | 278 %!test |
279 %! clf (hf); | 279 %! hf = figure ("visible", "off"); |
280 %! unwind_protect | 280 %! unwind_protect |
281 %! h = findobj (gca (), "-property", "foo"); | 281 %! h = findobj (gca (), "-property", "foo"); |
282 %! assert (h, zeros (0, 1)) | 282 %! assert (isempty (h)); |
283 %! unwind_protect_cleanup | 283 %! unwind_protect_cleanup |
284 %! close (hf); | 284 %! close (hf); |
285 %! end_unwind_protect | 285 %! end_unwind_protect |
286 | 286 |
287 %!test | 287 %!test |
288 %! hf = figure ("visible", "off"); | 288 %! hf = figure ("visible", "off"); |
289 %! unwind_protect | 289 %! unwind_protect |
290 %! h = plot (1:10); | 290 %! h = plot (1:10); |
291 %! set (h, "tag", "foobar") | 291 %! set (h, "tag", "foobar"); |
292 %! g = findobj (gcf (), "tag", "foobar", "type", "line", "color", [0 0 1]); | 292 %! g = findobj (gcf (), "tag", "foobar", "type", "line", "color", [0 0 1]); |
293 %! assert (g, h) | 293 %! assert (g, h); |
294 %! unwind_protect_cleanup | 294 %! unwind_protect_cleanup |
295 %! close (hf); | 295 %! close (hf); |
296 %! end_unwind_protect | 296 %! end_unwind_protect |
297 | 297 |
298 %!test | 298 %!test |
309 %! end_unwind_protect | 309 %! end_unwind_protect |
310 | 310 |
311 %!test | 311 %!test |
312 %! hf = figure ("visible", "off"); | 312 %! hf = figure ("visible", "off"); |
313 %! unwind_protect | 313 %! unwind_protect |
314 %! subplot (2, 2, 1) | 314 %! subplot (2,2,1); |
315 %! imagesc (rand (10)) | 315 %! imagesc (rand (10)); |
316 %! subplot (2, 2, 2) | 316 %! subplot (2,2,2); |
317 %! surf (peaks) | 317 %! surf (peaks); |
318 %! subplot (2, 2, 3) | 318 %! subplot (2,2,3); |
319 %! contour (peaks) | 319 %! contour (peaks); |
320 %! subplot (2, 2, 4) | 320 %! subplot (2,2,4); |
321 %! plot (peaks) | 321 %! plot (peaks); |
322 %! h1 = findobj (gcf (), "-regexp", "Type", "image|surface|hggroup"); | 322 %! h1 = findobj (gcf (), "-regexp", "Type", "image|surface|hggroup"); |
323 %! h2 = findobj (gcf (), "Type", "image", "-or", "Type", "surface", "-or", "Type", "hggroup"); | 323 %! h2 = findobj (gcf (), "Type", "image", |
324 %! unwind_protect_cleanup | 324 %! "-or", "Type", "surface", |
325 %! close (hf); | 325 %! "-or", "Type", "hggroup"); |
326 %! end_unwind_protect | 326 %! assert (h2, h1); |
327 %! assert (h2, h1) | 327 %! unwind_protect_cleanup |
328 %! close (hf); | |
329 %! end_unwind_protect | |
328 | 330 |
329 %!test | 331 %!test |
330 %! toolkit = graphics_toolkit ("gnuplot"); | 332 %! toolkit = graphics_toolkit ("gnuplot"); |
331 %! hf = figure ("visible", "off"); | 333 %! hf = figure ("visible", "off"); |
332 %! unwind_protect | 334 %! unwind_protect |
335 %! h1 = subplot (2,2,1); | |
336 %! h2 = subplot (2,2,2); | |
337 %! h3 = subplot (2,2,3, "userdata", struct ("foo", "bar")); | |
338 %! h4 = subplot (2,2,4); | |
339 %! h = findobj (hf, "userdata", struct ("foo", "bar")); | |
340 %! assert (h, h3); | |
341 %! unwind_protect_cleanup | |
342 %! close (hf); | |
343 %! graphics_toolkit (toolkit); | |
344 %! end_unwind_protect | |
345 | |
346 %!test | |
347 %! toolkit = graphics_toolkit ("gnuplot"); | |
348 %! hf = figure ("visible", "off"); | |
349 %! unwind_protect | |
350 %! h1 = subplot (2,2,1, "tag", "1"); | |
351 %! h2 = subplot (2,2,2, "tag", "2"); | |
352 %! h3 = subplot (2,2,3, "tag", "3"); | |
353 %! h4 = subplot (2,2,4, "tag", "4"); | |
354 %! h = findobj (hf, "type", "axes", "-not", "tag", "1"); | |
355 %! assert (h, [h4; h3; h2]) | |
356 %! unwind_protect_cleanup | |
357 %! close (hf); | |
358 %! graphics_toolkit (toolkit); | |
359 %! end_unwind_protect | |
360 | |
361 %!test | |
362 %! hf = figure ("visible", "off"); | |
363 %! unwind_protect | |
333 %! h1 = subplot (2, 2, 1); | 364 %! h1 = subplot (2, 2, 1); |
365 %! set (h1, "userdata", struct ("column", 1, "row", 1)); | |
334 %! h2 = subplot (2, 2, 2); | 366 %! h2 = subplot (2, 2, 2); |
367 %! set (h2, "userdata", struct ("column", 2, "row", 1)); | |
335 %! h3 = subplot (2, 2, 3); | 368 %! h3 = subplot (2, 2, 3); |
369 %! set (h3, "userdata", struct ("column", 1, "row", 2)); | |
336 %! h4 = subplot (2, 2, 4); | 370 %! h4 = subplot (2, 2, 4); |
337 %! userdata = struct ("foo", "bar"); | 371 %! set (h4, "userdata", struct ("column", 2, "row", 2)); |
338 %! set (h3, "userdata", userdata); | 372 %! h = findobj (hf, "type", "axes", |
339 %! h = findobj (hf, "userdata", userdata); | 373 %! "-not", "userdata", struct ("column", 1, "row", 1)); |
340 %! unwind_protect_cleanup | 374 %! unwind_protect_cleanup |
341 %! close (hf); | 375 %! close (hf); |
342 %! graphics_toolkit (toolkit); | 376 %! end_unwind_protect |
343 %! end_unwind_protect | 377 %! assert (h, [h4; h3; h2]) |
344 %! assert (h, h3) | |
345 | |
346 %!test | |
347 %! toolkit = graphics_toolkit ("gnuplot"); | |
348 %! hf = figure ("visible", "off"); | |
349 %! unwind_protect | |
350 %! h1 = subplot (2, 2, 1); | |
351 %! set (h1, 'tag', '1') | |
352 %! h2 = subplot (2, 2, 2); | |
353 %! set (h2, 'tag', '2') | |
354 %! h3 = subplot (2, 2, 3); | |
355 %! set (h3, 'tag', '3') | |
356 %! h4 = subplot (2, 2, 4); | |
357 %! set (h4, 'tag', '4') | |
358 %! h = findobj (hf, 'type', 'axes', '-not', 'tag', '1'); | |
359 %! unwind_protect_cleanup | |
360 %! close (hf); | |
361 %! graphics_toolkit (toolkit); | |
362 %! end_unwind_protect | |
363 %! assert (h, [h2; h3; h4]) | |
364 | |
365 %!test | |
366 %! hf = figure ("visible", "off"); | |
367 %! unwind_protect | |
368 %! h1 = subplot (2, 2, 1); | |
369 %! set (h1, 'userdata', struct ('column', 1, 'row', 1)); | |
370 %! h2 = subplot (2, 2, 2); | |
371 %! set (h2, 'userdata', struct ('column', 2, 'row', 1)); | |
372 %! h3 = subplot (2, 2, 3); | |
373 %! set (h3, 'userdata', struct ('column', 1, 'row', 2)); | |
374 %! h4 = subplot (2, 2, 4); | |
375 %! set (h4, 'userdata', struct ('column', 2, 'row', 2)); | |
376 %! h = findobj (hf, 'type', 'axes', '-not', 'userdata', ... | |
377 %! struct ('column', 1, 'row', 1)); | |
378 %! unwind_protect_cleanup | |
379 %! close (hf); | |
380 %! end_unwind_protect | |
381 %! assert (h, [h2; h3; h4]) | |
382 | 378 |
383 %!test | 379 %!test |
384 %! hf = figure ("visible", "off"); | 380 %! hf = figure ("visible", "off"); |
385 %! unwind_protect | 381 %! unwind_protect |
386 %! ha = axes (); | 382 %! ha = axes (); |
387 %! plot (1:10); | 383 %! plot (1:10); |
388 %! h = findobj (hf, 'type', 'figure', ... | 384 %! h = findobj (hf, "type", "figure", |
389 %! '-or', 'parent', hf, ... | 385 %! "-or", "parent", hf, |
390 %! '-and', 'type', 'axes'); | 386 %! "-and", "type", "axes"); |
391 %! unwind_protect_cleanup | 387 %! unwind_protect_cleanup |
392 %! close (hf) | 388 %! close (hf) |
393 %! end_unwind_protect | 389 %! end_unwind_protect |
394 %! assert (h, [ha; hf]) | 390 %! assert (h, [hf; ha]) |
395 | 391 |
396 %!test | 392 %!test |
397 %! hf = figure ("visible", "off"); | 393 %! hf = figure ("visible", "off"); |
398 %! set (hf, 'tag', 'foo'); | 394 %! unwind_protect |
399 %! unwind_protect | 395 %! set (hf, "tag", "foo"); |
400 %! h1 = subplot (2, 2, 1); | 396 %! h1 = subplot (2,2,1, "tag", "foo"); |
401 %! set (h1, 'tag', 'foo'); | 397 %! h2 = subplot (2,2,2, "tag", "bar"); |
402 %! h2 = subplot (2, 2, 2); | 398 %! h3 = subplot (2,2,3, "tag", "foo"); |
403 %! set (h2, 'tag', 'bar'); | 399 %! h4 = subplot (2,2,4, "tag", "bar"); |
404 %! h3 = subplot (2, 2, 3); | 400 %! h = findobj (hf, "type", "axes", "-xor", "tag", "foo"); |
405 %! set (h3, 'tag', 'foo'); | 401 %! assert (h, [hf; h4; h2]); |
406 %! h4 = subplot (2, 2, 4); | 402 %! unwind_protect_cleanup |
407 %! set (h4, 'tag', 'bar') | 403 %! close (hf); |
408 %! h = findobj (hf, 'type', 'axes', '-xor', ... | 404 %! end_unwind_protect |
409 %! 'tag', 'foo'); | 405 |
410 %! unwind_protect_cleanup | 406 %!test |
411 %! close (hf); | 407 %! hf = figure ("visible", "off"); |
412 %! end_unwind_protect | 408 %! unwind_protect |
413 %! assert (h, [h2; h4; hf]) | 409 %! hax1 = subplot (2,1,1); |
410 %! hl1 = plot (rand (10,1)); | |
411 %! hax2 = subplot (2,1,2); | |
412 %! hl2 = plot (rand (10,1)); | |
413 %! hobj = findobj (hf); | |
414 %! assert (hobj, [hf; hax2; hax1; hl2; hl1]); | |
415 %! unwind_protect_cleanup | |
416 %! close (hf); | |
417 %! end_unwind_protect | |
418 |