changeset 24482:b4e371b5f6b5

Fix shrinking plots when colorbar or legend in "outside" location (bug #52732). * legend.m: Supply list of axes, ca, to cb_axes_deleted callback. * legend.m (cb_axes_deleted): Check whether axes are being deleted, or merely reset. If reset, don't disable legend deletefcn which calls cb_restore_axes. * colorbar.m: Supply axes, hax, to cb_axes_deleted callback. * legend.m (cb_axes_deleted): Check whether axes are being deleted, or merely reset. If reset, don't disable colorbar deletefcn which calls cb_restore_axes.
author Rik <rik@octave.org>
date Wed, 27 Dec 2017 22:04:38 -0800
parents 6b685bb172c6
children dac2ad033c43
files scripts/plot/appearance/legend.m scripts/plot/draw/colorbar.m
diffstat 2 files changed, 14 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/plot/appearance/legend.m	Wed Dec 27 17:13:10 2017 -0800
+++ b/scripts/plot/appearance/legend.m	Wed Dec 27 22:04:38 2017 -0800
@@ -991,7 +991,7 @@
         htdel = findall (ca(1), "tag", "deletelegend", "type", "text");
         if (isempty (htdel))
           htdel = text (0, 0, "", props{:});
-          set (htdel, "deletefcn", {@cb_axes_deleted, hlegend});
+          set (htdel, "deletefcn", {@cb_axes_deleted, ca, hlegend});
         endif
         if (isprop (hlegend, "unmodified_axes_position"))
           set (hlegend, "unmodified_axes_position",
@@ -1200,10 +1200,13 @@
   endif
 
 endfunction
-## Axes to which legend was attached has been deleted.  Delete legend.
-function cb_axes_deleted (~, ~, hlegend)
+## Axes to which legend was attached is being deleted/reset.  Delete legend.
+function cb_axes_deleted (~, ~, ca, hlegend)
   if (isaxes (hlegend))
-    set (hlegend, "deletefcn", []);
+    if (strcmp (get (ca(1), "beingdeleted"), "on"))
+      ## Axes are being deleted.  Disable call to cb_restore_axes.
+      set (hlegend, "deletefcn", []);
+    endif
     delete (hlegend);
   endif
 endfunction
--- a/scripts/plot/draw/colorbar.m	Wed Dec 27 17:13:10 2017 -0800
+++ b/scripts/plot/draw/colorbar.m	Wed Dec 27 22:04:38 2017 -0800
@@ -256,7 +256,7 @@
                   "visible", "off", "handlevisibility", "off",
                   "xliminclude", "off", "yliminclude", "off",
                   "zliminclude", "off",
-                  "deletefcn", {@cb_axes_deleted, hcb});
+                  "deletefcn", {@cb_axes_deleted, hax, hcb});
 
     set (hcb, "deletefcn", {@cb_restore_axes, hax, props});
 
@@ -283,10 +283,13 @@
 
 endfunction
 
-## Axes to which colorbar was attached has been deleted.  Delete colorbar.
-function cb_axes_deleted (~, ~, hcb, orig_props)
+## Axes to which colorbar was attached is being deleted/reset. Delete colorbar.
+function cb_axes_deleted (~, ~, hax, hcb)
   if (isaxes (hcb))
-    set (hcb, "deletefcn", []);
+    if (strcmp (get (hax, "beingdeleted"), "on"))
+      ## Axes are being deleted.  Disable call to cb_restore_axes.
+      set (hcb, "deletefcn", []);
+    endif
     delete (hcb);
   endif
 endfunction