# HG changeset patch # User Pantxo Diribarne # Date 1424514750 -3600 # Node ID 4569903d6c5a4ed99938d80a32b4c94efa1b1945 # Parent 6e94fcc1a8a624cdbab927d71fed0074e520adbf axes.m: reworks axes restacking for ML compatibility (bug #43282) * axes.m (restack_axes): New subfunction. * axes.m ("axes (prp/val)" form): restack annotation axes, only if it was already on top * axes.m ("axes (HAX)" form): let axes with "handlevisibility" == "off" be restacked also * annotation.m: ensure annotation axes is on top when drawing a new annotation. diff -r 6e94fcc1a8a6 -r 4569903d6c5a scripts/plot/appearance/annotation.m --- a/scripts/plot/appearance/annotation.m Sun Feb 22 10:53:11 2015 +0100 +++ b/scripts/plot/appearance/annotation.m Sat Feb 21 11:32:30 2015 +0100 @@ -240,6 +240,9 @@ hax = findall (hf, "-depth", 1, "tag", "scribeoverlay"); if (isempty (hax)) hax = buildoverlay (hf); + else + ## Make sure the annotations are on top of other axes + axes (hax); endif ## Build annotation diff -r 6e94fcc1a8a6 -r 4569903d6c5a scripts/plot/util/axes.m --- a/scripts/plot/util/axes.m Sun Feb 22 10:53:11 2015 +0100 +++ b/scripts/plot/util/axes.m Sat Feb 21 11:32:30 2015 +0100 @@ -42,7 +42,7 @@ function h = axes (varargin) if (nargin == 0 || nargin > 1) - ## Create an axes object. + ## Parent figure idx = find (strcmpi (varargin(1:2:end), "parent"), 1, "first"); if (! isempty (idx) && length (varargin) >= 2*idx) cf = varargin{2*idx}; @@ -50,49 +50,44 @@ else cf = gcf (); endif + + ## If there is an annotation axes currently on top of the figure + ## children stack, we will put it back on top + do_restack = false; + ch = allchild (cf); + hax = ch(isaxes (ch)); + idx = find (strcmp (get (hax, "tag"), "scribeoverlay")); + if (idx == 1) + hover = hax(idx); + do_restack = true; + endif + + ## Create an axes object. htmp = __go_axes__ (cf, varargin{:}); if (__is_handle_visible__ (htmp)) set (ancestor (cf, "figure"), "currentaxes", htmp); endif + + ## Restack if necessary + if (do_restack) + restack_axes (hover, cf); + endif else ## ARG is axes handle. htmp = varargin{1}; if (isscalar (htmp) && isaxes (htmp)) + cf = ancestor (htmp, "figure"); if (__is_handle_visible__ (htmp)) - cf = ancestor (htmp, "figure"); set (0, "currentfigure", cf); set (cf, "currentaxes", htmp); + endif - ## restack - ch = get (cf, "children")(:); - idx = (ch == htmp); - ch = [ch(idx); ch(!idx)]; - set (cf, "children", ch); - endif + ## restack + restack_axes (htmp, cf); else error ("axes: H must be a scalar axes handle"); endif endif - - ## FIXME: In order to have the overlay axes on top of all other axes - ## we restack the figure children. Does Matlab use a similar - ## hack? - show = get (0, "showhiddenhandles"); - set (0, "showhiddenhandles", "on"); - unwind_protect - ch = get (cf, "children"); - idx = strcmp (get (ch, "tag"), "scribeoverlay"); - hover = ch(idx); - if (! isempty (hover)) - hax = ch(isaxes (ch)); - if (numel (hax) > 1) - ch(isaxes (ch)) = [hover; hax(hax != hover)]; - set (cf, "children", ch); - endif - endif - unwind_protect_cleanup - set (0, "showhiddenhandles", show); - end_unwind_protect if (nargout > 0) h = htmp; @@ -100,3 +95,15 @@ endfunction +function restack_axes (h, cf) + show = get (0, "showhiddenhandles"); + set (0, "showhiddenhandles", "on"); + unwind_protect + ch = get (cf, "children"); + hax = ch(isaxes (ch)); + ch(isaxes (ch)) = [h; hax(hax != h)]; + set (cf, "children", ch); + unwind_protect_cleanup + set (0, "showhiddenhandles", show); + end_unwind_protect +endfunction