diff scripts/plot/legend.m @ 12390:7428d177f00a release-3-4-x

Fix for inline legends (#32022, #32343)
author David Bateman <dbateman@free.fr>
date Sat, 05 Feb 2011 10:19:13 -0500
parents c792872f8942
children d63007ac067a
line wrap: on
line diff
--- a/scripts/plot/legend.m	Sun Feb 06 07:30:27 2011 -0500
+++ b/scripts/plot/legend.m	Sat Feb 05 10:19:13 2011 -0500
@@ -775,10 +775,13 @@
   persistent recursive = false;
   if (! recursive)
     recursive = true;
-    hax = getfield (get (h, "userdata"), "handle");
-    [hplots, text_strings] = getlegenddata (h);
-    h = legend (hax, flipud (hplots), get (h, "string"));
-    recursive = false;
+    unwind_protect
+      hax = getfield (get (h, "userdata"), "handle");
+      [hplots, text_strings] = __getlegenddata__ (h);
+      h = legend (hax, hplots, get (h, "string"));
+    unwind_protect_cleanup
+      recursive = false;
+    end_unwind_protect
   endif
 endfunction
 
@@ -895,7 +898,7 @@
        && (! isempty (lm) || isempty (ll)))
     ## An element was removed from the legend. Need to recall the
     ## legend function to recreate a new legend
-    [hplots, text_strings] = getlegenddata (hlegend);
+    [hplots, text_strings] = __getlegenddata__ (hlegend);
     for i = 1 : numel (hplots)
       if (hplots (i) == h)
         hplots(i) = [];
@@ -909,7 +912,7 @@
           && isempty (lm) && isempty (ll))
     ## An element was added to the legend. Need to recall the
     ## legend function to recreate a new legend
-    [hplots, text_strings] = getlegenddata (hlegend);
+    [hplots, text_strings] = __getlegenddata__ (hlegend);
     hplots = [hplots, h];
     text_strings = {text_strings{:}, displayname};
     legend (hplots, text_strings);
@@ -945,47 +948,6 @@
   endif
 endfunction
 
-function [hplots, text_strings] = getlegenddata (hlegend)
-  hplots = [];
-  text_strings = {};
-  ca = getfield (get (hlegend, "userdata"), "handle");
-  kids = [];
-  for i = 1  : numel (ca)
-    kids = [kids; get(ca (i), "children")];
-  endfor
-  k = numel (kids);
-  while (k > 0)
-    typ = get (kids(k), "type");
-    while (k > 0
-           && ! (strcmp (typ, "line") || strcmp (typ, "surface")
-                 || strcmp (typ, "patch") || strcmp (typ, "hggroup")))
-      typ = get (kids(--k), "type");
-    endwhile
-    if (k > 0)
-      if (strcmp (get (kids(k), "type"), "hggroup"))
-        hgkids = get (kids(k), "children");
-        for j = 1 : length (hgkids)
-          hgobj = get (hgkids (j));
-          if (isfield (hgobj, "displayname")
-              && ! isempty (hgobj.displayname))
-            hplots = [hplots, hgkids(j)];
-            text_strings = {text_strings{:}, hbobj.displayname};
-            break;
-          endif
-        endfor
-      else
-        if (! isempty (get (kids (k), "displayname")))
-          hplots = [hplots, kids(k)];
-          text_strings = {text_strings{:}, get(kids (k), "displayname")};
-        endif
-      endif
-      if (--k == 0)
-        break;
-      endif
-    endif
-  endwhile
-endfunction
-
 %!demo
 %! clf
 %! x = 0:1;