# HG changeset patch # User John W. Eaton # Date 1252303301 -7200 # Node ID c5ab026894eff3ca7bfc9ab3851345e9ee39a5c3 # Parent bd994ce2015862fc1857af5c6ab2a67a9d8d88bb correctly toggle hold state diff -r bd994ce20158 -r c5ab026894ef scripts/ChangeLog --- a/scripts/ChangeLog Fri Sep 04 06:59:44 2009 +0200 +++ b/scripts/ChangeLog Mon Sep 07 08:01:41 2009 +0200 @@ -1,3 +1,10 @@ +2009-09-05 John W. Eaton + + * 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 * general/int2str.m: Convert to double before calling log10. diff -r bd994ce20158 -r c5ab026894ef scripts/plot/hold.m --- a/scripts/plot/hold.m Fri Sep 04 06:59:44 2009 +0200 +++ b/scripts/plot/hold.m Mon Sep 07 08:01:41 2009 +0200 @@ -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 diff -r bd994ce20158 -r c5ab026894ef scripts/plot/ishold.m --- a/scripts/plot/ishold.m Fri Sep 04 06:59:44 2009 +0200 +++ b/scripts/plot/ishold.m Mon Sep 07 08:01:41 2009 +0200 @@ -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