changeset 24398:a7dfb685d261 stable

legend.m: Fix callback error when changing a legend string to "". * legend.m (updateline): Check whether hplots variable is empty before trying to index into it. Add FIXME notes to the code about why this is necessary, and why it is innefficient.
author Rik <rik@octave.org>
date Mon, 11 Dec 2017 14:46:43 -0800
parents 295664c0c922
children 4fda27e1c909 62add1b69100
files scripts/plot/appearance/legend.m
diffstat 1 files changed, 9 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/plot/appearance/legend.m	Thu Dec 07 21:47:14 2017 -0800
+++ b/scripts/plot/appearance/legend.m	Mon Dec 11 14:46:43 2017 -0800
@@ -412,6 +412,10 @@
         endwhile
         if (k > 0)
           if (have_labels)
+            ## FIXME: This is inefficient on an existing legend object because
+            ##        it triggers the updateline() callback which then calls
+            ##        legend() itself.  Possibly better to delete the callback
+            ##        on displayname and then re-attach it.  See bug #52641.
             set (kids(k), "displayname", arg);
           endif
           hplots(end+1) = kids(k);
@@ -1173,7 +1177,11 @@
   if (update_name)
     ## When string changes, have to rebuild legend completely
     [hplots, text_strings] = __getlegenddata__ (hlegend);
-    legend (get (hplots(1), "parent"), hplots, text_strings);
+    ## FIXME: See bug #52641.  Changing an existing legend string to a blank
+    ##        can trigger this.
+    if (! isempty (hplots))
+      legend (get (hplots(1), "parent"), hplots, text_strings);
+    endif
   else
     kids = get (hlegend, "children");
     ll = lm = [];