diff scripts/image/hsv.m @ 24800:2dc04b6e1740

Don't create new figure when calling colormap functions (bug #53217). * autumn.m, bone.m, contrast.m, cool.m, copper.m, cubehelix.m, flag.m, gray.m, hot.m, hsv.m, jet.m, lines.m, ocean.m, pink.m, prism.m, rainbow.m, spring.m, summer.m, viridis.m, white.m, winter.m: Check root figure for a CurrentFigure and use the number of rows in its colormap if it is available. Otherwise, use default of 64.
author Rik <rik@octave.org>
date Tue, 27 Feb 2018 08:57:21 -0800
parents 194eb4bd202b
children 6652d3823428
line wrap: on
line diff
--- a/scripts/image/hsv.m	Mon Feb 26 17:35:21 2018 -0800
+++ b/scripts/image/hsv.m	Tue Feb 27 08:57:21 2018 -0800
@@ -33,14 +33,23 @@
 
 ## Author:  Kai Habel <kai.habel@gmx.de>
 
-function map = hsv (n = rows (colormap ()))
+function map = hsv (n)
 
   if (nargin > 1)
     print_usage ();
-  elseif (! isscalar (n))
-    error ("hsv: N must be a scalar");
+  elseif (nargin == 1)
+    if (! isscalar (n))
+      error ("hsv: N must be a scalar");
+    endif
+    n = double (n);
+  else
+    hf = get (0, "currentfigure");
+    if (! isempty (hf))
+      n = rows (get (hf, "colormap"));
+    else
+      n = 64;
+    endif
   endif
-  n = double (n);
 
   if (n == 1)
     map = [1, 0, 0];