Mercurial > hg > octave-nkf
diff 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 |
line wrap: on
line diff
--- a/scripts/plot/util/newplot.m +++ b/scripts/plot/util/newplot.m @@ -138,8 +138,10 @@ if (isempty (ca)) ca = gca (); + deleteall = true; else set (cf, "currentaxes", ca); + deleteall = false; endif ## FIXME: Is this necessary anymore? @@ -159,8 +161,19 @@ case "replacechildren" delete (get (ca, "children")); case "replace" - __go_axes_init__ (ca, "replace"); - __request_drawnow__ (); + if (! deleteall && ca != hsave) + ## preserve hsave and its parents, uncles, ... + kids = allchild (ca); + hkid = hsave; + while (! any (hkid == kids)) + hkid = get (hkid, "parent"); + endwhile + kids(kids == hkid) = []; + delete (kids); + else + __go_axes_init__ (ca, "replace"); + __request_drawnow__ (); + endif ## FIXME: The code above should perform the following: ########################### ## delete (allchild (ca)); @@ -192,3 +205,34 @@ %! close (hf); %! end_unwind_protect +%!test +%! hf = figure ("visible", "off"); +%! unwind_protect +%! hax = axes (); +%! hold on; +%! hg1 = hggroup (); +%! hg2 = hggroup ("parent", hg1); +%! li0 = line (1:10, 1:10); +%! li1 = line (1:10, -1:-1:-10, "parent", hg1); +%! li2 = line (1:10, sin (1:10), "parent", hg2); +%! hold off; +%! newplot (hg2); +%! assert (ishandle (li0), false); +%! assert (get (hax, "children"), hg1); +%! +%! ## kids are preserved for hggroups +%! kids = get (hg1, "children"); +%! newplot (hg1); +%! assert (get (hg1, "children"), kids)); +%! +%! ## preserve objects +%! newplot (li1); +%! assert (ishandle (li1)); +%! +%! ## kids are deleted for axes +%! newplot (hax); +%! assert (isempty (get (hax, "children"))); +%! unwind_protect_cleanup +%! close (hf); +%! end_unwind_protect +