comparison scripts/plot/ishold.m @ 13319:eb0ce6ffefb0

ishold: don't create axes if none exists * ishold.m: Don't create axes object if none exists.
author John W. Eaton <jwe@octave.org>
date Tue, 11 Oct 2011 16:15:35 -0400
parents be7bfd59300a
children 72c96de7a403
comparison
equal deleted inserted replaced
13318:f3b665972bb5 13319:eb0ce6ffefb0
28 ## @end deftypefn 28 ## @end deftypefn
29 29
30 function retval = ishold (h) 30 function retval = ishold (h)
31 31
32 if (nargin == 0) 32 if (nargin == 0)
33 ax = gca ();
34 fig = gcf (); 33 fig = gcf ();
34 ax = get (fig, "currentaxes");
35 elseif (nargin == 1) 35 elseif (nargin == 1)
36 if (ishandle (h)) 36 if (ishandle (h))
37 if (isfigure (h)) 37 if (isfigure (h))
38 ax = get (h, "currentaxes"); 38 ax = get (h, "currentaxes");
39 if (isempty (ax))
40 ax = __go_axes__ (h);
41 set (h, "currentaxes", ax);
42 endif
43 fig = h; 39 fig = h;
44 elseif (strcmpi (get (h, "type"), "axes")) 40 elseif (strcmpi (get (h, "type"), "axes"))
45 ax = h; 41 ax = h;
46 fig = get (h, "parent"); 42 fig = get (h, "parent");
47 else 43 else
53 else 49 else
54 print_usage (); 50 print_usage ();
55 endif 51 endif
56 52
57 retval = (strcmpi (get (fig, "nextplot"), "add") 53 retval = (strcmpi (get (fig, "nextplot"), "add")
58 && strcmpi (get (ax, "nextplot"), "add")); 54 && ! isempty (ax) && strcmpi (get (ax, "nextplot"), "add"));
59 55
60 endfunction 56 endfunction
61 57
62 %!test 58 %!test
63 %! hf = figure ("visible", "off"); 59 %! hf = figure ("visible", "off");
64 %! unwind_protect 60 %! unwind_protect
61 %! assert (!ishold);
62 %! assert (isempty (get (hf, "currentaxes")));
63 %! assert (get (hf, "NextPlot"), "add");
65 %! l = plot ([0 1]); 64 %! l = plot ([0 1]);
66 %! assert (!ishold); 65 %! assert (!ishold);
67 %! assert (!ishold (gca)); 66 %! assert (!ishold (gca));
68 %! assert (get (gca, "NextPlot"), "replace"); 67 %! assert (get (gca, "NextPlot"), "replace");
69 %! assert (get (hf, "NextPlot"), "add"); 68 %! assert (get (hf, "NextPlot"), "add");