Mercurial > jwe > octave
changeset 24426:a51497205f4c
Change uses of gcbf after Matlab compatibility change in bug #52621.
* legend.m (hideshowlegend): Test only hlegend object itself for "visible"
property to determine whether overall legend should be seen. Remove checks
on whether gcbf or axes are being deleted. The callback hideshowlegend is
never called in these cases.
* legend.m (deletelegend1): Remove checks on gcbf and axes to see if they are
being deleted. If the callback deletelegend1 has been called for any reason
the legend object should be deleted.
* legend.m (deletelegend2): Before restoring axes properties to original
values, check (use ancestor() rather than gcbf()) that figure or axes aren't
being deleted before proceeding. Use new isgraphics() function to simplify code.
* colorbar.m (deletecolorbar): Remove checks on whether gcbf or axes is being
deleted. Delete code to restore original axes properties; that functionality
is in resetaxis().
* colorbar.m (resetaxis): Check (using ancestor() rather than gcbf()) whether
figure is being destroyed and skip restoring axis.
* colorbar.m (update_colorbar_clim, update_colorbar_axis): Remove checks on
gcbf() and whether it is being deleted as they are unnecessary.
* plotyy.m (__plotyy__): Remove checks on whether gcbf or axes are being
deleted.
author | Rik <rik@octave.org> |
---|---|
date | Mon, 18 Dec 2017 11:03:07 -0800 |
parents | 3e88df7cd365 |
children | 51ead71394bc |
files | scripts/plot/appearance/legend.m scripts/plot/draw/colorbar.m scripts/plot/draw/plotyy.m |
diffstat | 3 files changed, 47 insertions(+), 59 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/plot/appearance/legend.m Mon Dec 18 09:16:05 2017 -0800 +++ b/scripts/plot/appearance/legend.m Mon Dec 18 11:03:07 2017 -0800 @@ -1115,18 +1115,12 @@ function hideshowlegend (h, ~, ca, pos1, pos2) - isvisible = strcmp (get (h, "visible"), "off"); - if (! isvisible) - kids = get (h, "children"); - if (any (! strcmp (get (kids, "visible"), "off"))) - isvisible = true; - endif - endif + isvisible = strcmp (get (h, "visible"), "on"); + ## FIXME: Can't use a single set() call because of linked axes and + ## listeners on plotyy graphs. for i = 1 : numel (ca) - if (isaxes (ca(i)) - && (isempty (gcbf ()) || strcmp (get (gcbf (), "beingdeleted"),"off")) - && strcmp (get (ca(i), "beingdeleted"), "off")) + if (isaxes (ca(i))) units = get (ca(i), "units"); unwind_protect set (ca(i), "units", "points"); @@ -1144,38 +1138,42 @@ endfunction function deletelegend1 (h, ~, hlegend) - if (isaxes (hlegend) - && (isempty (gcbf ()) || strcmp (get (gcbf (), "beingdeleted"), "off")) - && strcmp (get (hlegend, "beingdeleted"), "off")) + if (isaxes (hlegend)) delete (hlegend); endif endfunction function deletelegend2 (h, ~, ca, pos, outpos, t1, hplots) + hf = ancestor (ca(1), "figure"); + if (strcmp (get (hf, "beingdeleted"), "on") || + strcmp (get (ca(1), "beingdeleted"), "on")) + ## Skip restoring axes if entire figure or axes is being destroyed. + return; + endif + + ## Remove text object used to trigger legend delete when axes is deleted + if (ishghandle (t1)) + set (t1, "deletefcn", []); + delete (t1); + endif + + ## Restore original axes positions for i = 1 : numel (ca) - if (isaxes (ca(i)) - && (isempty (gcbf ()) || strcmp (get (gcbf (), "beingdeleted"), "off")) - && strcmp (get (ca(i), "beingdeleted"), "off")) - if (! isempty (pos) && ! isempty (outpos)) - units = get (ca(i), "units"); - unwind_protect - set (ca(i), "units", "points"); - set (ca(i), "position", pos, "deletefcn", ""); - unwind_protect_cleanup - set (ca(i), "units", units); - end_unwind_protect - endif + if (isaxes (ca(i))) + units = get (ca(i), "units"); + unwind_protect + set (ca(i), "units", "points"); + set (ca(i), "position", pos); + unwind_protect_cleanup + set (ca(i), "units", units); + end_unwind_protect endif endfor - if (ishghandle (t1)) - set (t1, "deletefcn", ""); - delete (t1); - endif - + ## Remove listeners from plot objects for i = 1 : numel (hplots) - if (ishghandle (hplots(i)) && strcmp (get (hplots(i), "type"), "line")) + if (isgraphics (hplots(i), "line")) dellistener (hplots(i), "color"); dellistener (hplots(i), "linestyle"); dellistener (hplots(i), "linewidth");
--- a/scripts/plot/draw/colorbar.m Mon Dec 18 09:16:05 2017 -0800 +++ b/scripts/plot/draw/colorbar.m Mon Dec 18 11:03:07 2017 -0800 @@ -256,23 +256,10 @@ endfunction function deletecolorbar (h, ~, hc, orig_props) - ## Don't delete the colorbar and reset the axis size - ## if the parent figure is being deleted. - if (isaxes (hc) - && (isempty (gcbf ()) || strcmp (get (gcbf (), "beingdeleted"), "off"))) - if (strcmp (get (hc, "beingdeleted"), "off")) - delete (hc); - endif - if (! isempty (ancestor (h, "axes")) - && strcmp (get (ancestor (h, "axes"), "beingdeleted"), "off")) - ax = ancestor (h, "axes"); - units = get (ax, "units"); - set (ax, "units", orig_props.units); - set (ancestor (h, "axes"), "position", orig_props.position, - "outerposition", orig_props.outerposition, - "activepositionproperty", orig_props.activepositionproperty); - set (ax, "units", units); - endif + + if (isaxes (hc)) + set (hc, "deletefcn", []); + delete (hc); endif endfunction @@ -286,9 +273,16 @@ function resetaxis (cax, ~, ax, orig_props) + hf = ancestor (ax, "figure"); + if (strcmp (get (hf, "beingdeleted"), "on")) + ## Skip restoring axes if entire figure is being destroyed. + return; + endif + if (isaxes (ax)) - ## FIXME: Probably don't want to delete everyone's listeners on colormap. - dellistener (ancestor (ax, "figure"), "colormap"); + ## FIXME: It is wrong to delete every listener for colormap on figure, + ## but we don't have a way of deleting just this instance. + dellistener (hf, "colormap"); dellistener (ax, "clim"); dellistener (ax, "dataaspectratio"); dellistener (ax, "dataaspectratiomode"); @@ -296,6 +290,7 @@ dellistener (ax, "plotboxaspectratiomode"); dellistener (ax, "position"); + ## Restore axes position units = get (ax, "units"); set (ax, "units", orig_props.units); set (ax, "position", orig_props.position, @@ -308,8 +303,7 @@ function update_colorbar_clim (hax, ~, hi, vert) - if (isaxes (hax) - && (isempty (gcbf ()) || strcmp (get (gcbf (), "beingdeleted"), "off"))) + if (isaxes (hax)) clen = rows (get (ancestor (hax, "figure"), "colormap")); cext = get (hax, "clim"); cdiff = (cext(2) - cext(1)) / clen / 2; @@ -331,8 +325,7 @@ function update_colorbar_cmap (hf, d, hi, vert, init_sz) persistent sz = init_sz; - if (ishghandle (hf) && strcmp (get (hf, "type"), "figure") - && (isempty (gcbf ()) || strcmp (get (gcbf (), "beingdeleted"), "off"))) + if (isfigure (hf)) clen = rows (get (hf, "colormap")); if (clen != sz) if (vert) @@ -350,8 +343,7 @@ function update_colorbar_axis (h, ~, cax, orig_props) - if (isaxes (cax) - && (isempty (gcbf ()) || strcmp (get (gcbf (), "beingdeleted"),"off"))) + if (isaxes (cax)) loc = get (cax, "location"); obj = get (h); obj.__cbar_hax__ = h;
--- a/scripts/plot/draw/plotyy.m Mon Dec 18 09:16:05 2017 -0800 +++ b/scripts/plot/draw/plotyy.m Mon Dec 18 11:03:07 2017 -0800 @@ -203,9 +203,7 @@ endfunction function deleteplotyy (h, ~, ax2, t2) - if (isaxes (ax2) - && (isempty (gcbf ()) || strcmp (get (gcbf (), "beingdeleted"), "off")) - && strcmp (get (ax2, "beingdeleted"), "off")) + if (isaxes (ax2)) set (t2, "deletefcn", []); delete (ax2); endif