# HG changeset patch # User Carnë Draug # Date 1335312515 14400 # Node ID f579a94aacaa2e5e59b3b661ea8c7df3e243d7dd # Parent 447038c2dde8236489a50bbc283045fac8efd4a4 Preserve legend handle when changing properties (Bug # 36259). * legend.m: Preserve legend handle with changing properites. Set "visible" property of the legend axes and its children to "off" when legend is hidden. Modify a demo to test preserving the legend's handle. diff -r 447038c2dde8 -r f579a94aacaa scripts/plot/legend.m --- a/scripts/plot/legend.m Sat Apr 21 18:46:04 2012 -0400 +++ b/scripts/plot/legend.m Tue Apr 24 20:08:35 2012 -0400 @@ -276,7 +276,7 @@ if (strcmp (show, "off")) if (! isempty (hlegend)) - set (get (hlegend, "children"), "visible", "off"); + set (findobj (hlegend), "visible", "off"); hlegend = []; endif hobjects = []; @@ -284,7 +284,7 @@ text_strings = {}; elseif (strcmp (show, "on")) if (! isempty (hlegend)) - set (get (hlegend, "children"), "visible", "on"); + set (findobj (hlegend), "visible", "on"); else hobjects = []; hplots = []; @@ -435,7 +435,7 @@ text_strings = {}; endif else - ## Delete the old legend if it exists + ## Preserve the old legend if it exists if (! isempty (hlegend)) if (strcmp (textpos, "default")) textpos = get (hlegend, "textposition"); @@ -454,10 +454,6 @@ orientation = get (hlegend, "orientation"); endif box = get (hlegend, "box"); - fkids = get (fig, "children"); - - delete (hlegend); - hlegend = []; else if (strcmp (textpos, "default")) textpos = "left"; @@ -507,15 +503,14 @@ "box", box, "xtick", [], "ytick", [], "xticklabel", "", "yticklabel", "", "zticklabel", "", - "xlim", [0, 1], "ylim", [0, 1], - "visible", ifelse (strcmp (box, "on"), "on", "off"), + "xlim", [0, 1], "ylim", [0, 1], + "visible", ifelse (strcmp (box, "on"), "on", "off"), "activepositionproperty", "position"); else addprops = false; axes (hlegend); delete (get (hlegend, "children")); endif - ## Add text label to the axis first, checking their extents nentries = numel (hplots); texthandle = []; @@ -973,6 +968,12 @@ endif endfunction +%!demo +%! plot (rand (2,2)) ; +%! h = legend ('a', 'b') ; +%! legend ('right') ; +%! set (h, 'textposition', 'left') +%! set (h, 'textposition', 'right') %!demo %! clf;