1######################################################################## 2## 3## Copyright (C) 2005-2021 The Octave Project Developers 4## 5## See the file COPYRIGHT.md in the top-level directory of this 6## distribution or <https://octave.org/copyright/>. 7## 8## This file is part of Octave. 9## 10## Octave is free software: you can redistribute it and/or modify it 11## under the terms of the GNU General Public License as published by 12## the Free Software Foundation, either version 3 of the License, or 13## (at your option) any later version. 14## 15## Octave is distributed in the hope that it will be useful, but 16## WITHOUT ANY WARRANTY; without even the implied warranty of 17## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18## GNU General Public License for more details. 19## 20## You should have received a copy of the GNU General Public License 21## along with Octave; see the file COPYING. If not, see 22## <https://www.gnu.org/licenses/>. 23## 24######################################################################## 25 26## -*- texinfo -*- 27## @deftypefn {} {} ishold 28## @deftypefnx {} {} ishold (@var{hax}) 29## @deftypefnx {} {} ishold (@var{hfig}) 30## Return true if the next plot will be added to the current plot, or 31## false if the plot device will be cleared before drawing the next plot. 32## 33## If the first argument is an axes handle @var{hax} or figure handle 34## @var{hfig} then operate on this plot rather than the current one. 35## @seealso{hold, newplot} 36## @end deftypefn 37 38function retval = ishold (h) 39 40 if (nargin > 1) 41 print_usage (); 42 endif 43 44 if (nargin == 0) 45 fig = gcf (); 46 ax = get (fig, "currentaxes"); 47 else 48 if (! ishghandle (h)) 49 error ("ishold: H must be an axes or figure graphics handle"); 50 endif 51 52 switch (get (h, "type")) 53 case "figure" 54 fig = h; 55 ax = get (fig, "currentaxes"); 56 57 case "axes" 58 ax = h; 59 fig = ancestor (ax, "figure"); 60 61 otherwise 62 error ("ishold: H must be an axes or figure graphics handle"); 63 64 endswitch 65 endif 66 67 retval = (strcmp (get (fig, "nextplot"), "add") 68 && ! isempty (ax) && strcmp (get (ax, "nextplot"), "add")); 69 70endfunction 71 72 73%!test 74%! hf = figure ("visible", "off"); 75%! unwind_protect 76%! assert (! ishold); 77%! assert (isempty (get (hf, "currentaxes"))); 78%! assert (get (hf, "NextPlot"), "add"); 79%! l = plot ([0 1]); 80%! assert (! ishold); 81%! assert (! ishold (gca)); 82%! assert (get (gca, "NextPlot"), "replace"); 83%! assert (get (hf, "NextPlot"), "add"); 84%! hold; 85%! assert (ishold); 86%! assert (ishold (gca)); 87%! assert (get (gca, "NextPlot"), "add"); 88%! assert (get (hf, "NextPlot"), "add"); 89%! p = fill ([0 1 1], [0 0 1],"black"); 90%! assert (length (get (hf, "children")), 1); 91%! assert (length (get (gca, "children")), 2); 92%! unwind_protect_cleanup 93%! close (hf); 94%! end_unwind_protect 95