Mercurial > hg > octave-terminal
changeset 12085:c5ab026894ef release-3-2-x
correctly toggle hold state
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Mon, 07 Sep 2009 08:01:41 +0200 |
parents | bd994ce20158 |
children | 330cf1e13fb6 |
files | scripts/ChangeLog scripts/plot/hold.m scripts/plot/ishold.m |
diffstat | 3 files changed, 46 insertions(+), 25 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/ChangeLog +++ b/scripts/ChangeLog @@ -1,3 +1,10 @@ +2009-09-05 John W. Eaton <jwe@octave.org> + + * plot/hold.m: Correctly toggle hold state. Set both figure and + axes "nextplot" property when turning hold state on. + * plot/ishold.m: Check figure and axes nextplot properties. + Accept axes or figure handle argument. + 2009-08-17 Jaroslav Hajek <highegg@gmail.com> * general/int2str.m: Convert to double before calling log10.
--- a/scripts/plot/hold.m +++ b/scripts/plot/hold.m @@ -46,49 +46,41 @@ function hold (varargin) - if (nargin > 0 && numel (varargin{1}) == 1 && ishandle (varargin{1}(1)) + if (nargin > 0 && numel (varargin{1}) == 1 && ishandle (varargin{1}) && strcmp (get (varargin{1}, "type"), "axes")) - [h, varargin, nargs] = __plt_get_axis_arg__ ("hold", varargin{:}); - elseif (nargin > 0 && numel (varargin{1}) > 1 && ishandle (varargin{1}(1))) + [ax, varargin, nargs] = __plt_get_axis_arg__ ("hold", varargin{:}); + elseif (nargin > 0 && numel (varargin{1}) > 1 && ishandle (varargin{1})) print_usage (); else - h = gcf (); + ax = gca (); + fig = gcf (); nargs = numel (varargin); endif - hold_state = get (h, "nextplot"); - if (nargs == 0) - if (strcmpi (hold_state, "add")) - hold_state = "replace"; - else - hold_state = "add"; - endif + turn_hold_off = ishold (ax); elseif (nargs == 1) state = varargin{1}; if (ischar (state)) if (strcmpi (state, "off")) - hold_state = "replace"; + turn_hold_off = true; elseif (strcmpi (state, "on")) - hold_state = "add"; + turn_hold_off = false; else - print_usage (); + error ("hold: invalid hold state"); endif endif else print_usage (); endif - if (isfigure (h)) - if (isempty (get (h, "currentaxes"))) - set (h, "currentaxes", __go_axes__ (h)) - endif - axes_objs = findobj (h, "type", "axes"); - h = [h; axes_objs]; + if (turn_hold_off) + set (ax, "nextplot", "replace"); + else + set (ax, "nextplot", "add"); + set (fig, "nextplot", "add"); endif - set (h, "nextplot", hold_state); - endfunction %!demo
--- a/scripts/plot/ishold.m +++ b/scripts/plot/ishold.m @@ -1,4 +1,4 @@ -## Copyright (C) 2005, 2006, 2007, 2008 John W. Eaton +## Copyright (C) 2005, 2006, 2007, 2008 2009 John W. Eaton ## ## This file is part of Octave. ## @@ -22,12 +22,34 @@ ## false if the plot device will be cleared before drawing the next line. ## @end deftypefn -function retval = ishold () +function retval = ishold (h) if (nargin == 0) - retval = strcmpi (get (gca (), "nextplot"), "add"); + ax = gca (); + fig = gcf (); + elseif (nargin == 1) + if (ishandle (h)) + if (isfigure (h)) + ax = get (h, "currentaxes"); + if (isempty (ax)) + ax = __go_axes__ (h); + set (h, "currentaxes", ax); + endif + fig = h; + elseif (strcmpi (get (h, "type"), "axes")) + ax = h; + fig = get (h, "parent"); + else + error ("hold: expecting argument to be axes or figure graphics handle"); + endif + else + error ("hold: expecting argument to be axes or figure graphics handle"); + endif else print_usage (); endif + retval = (strcmpi (get (fig, "nextplot"), "add") + && strcmpi (get (ax, "nextplot"), "add")); + endfunction