Mercurial > hg > octave-lyh
changeset 14578:f579a94aacaa
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.
author | Carnë Draug <carandraug+dev@gmail.com> |
---|---|
date | Tue, 24 Apr 2012 20:08:35 -0400 |
parents | 447038c2dde8 |
children | 4dc85c4f151b |
files | scripts/plot/legend.m |
diffstat | 1 files changed, 11 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/plot/legend.m +++ b/scripts/plot/legend.m @@ -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;