changeset 16943:0dab17e69a55

Implement line color and style rotation across multiple axes (bug #39344). * scripts/plot/private/__next_line_color__.m: Get ColorOrder from gca rather than using persistent variable. * scripts/plot/private/__next_line_style__.m: Get LineStyleOrder from gca rather than using persistent variable.
author Carl Osterwisch <costerwisch@costerwisch-lt1>
date Tue, 09 Jul 2013 18:53:06 -0700
parents 78a2f43bbc69
children 1b3b3ee88284
files scripts/plot/private/__next_line_color__.m scripts/plot/private/__next_line_style__.m
diffstat 2 files changed, 50 insertions(+), 45 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/plot/private/__next_line_color__.m	Tue Jun 25 14:48:33 2013 -0400
+++ b/scripts/plot/private/__next_line_color__.m	Tue Jul 09 18:53:06 2013 -0700
@@ -1,3 +1,4 @@
+## Copyright (C) 2013 Carl Osterwisch
 ## Copyright (C) 2007-2012 John W. Eaton
 ##
 ## This file is part of Octave.
@@ -24,30 +25,33 @@
 ## Return the next line color in the rotation.
 
 ## Author: Carl Osterwisch
+## Author: jwe
 
 function rgb = __next_line_color__ (reset)
 
   persistent reset_colors = true;
 
-  if (nargin < 2)
-    if (nargin == 1)
-      % Indicates whether the next call will increment or not
-      reset_colors = reset;
-    else
-      % Find and return the next line color
-      ca = gca();
-      colorOrder = get(ca, "ColorOrder");
-      if reset_colors
-        color_index = 1;
-      else
-        % Executed when "hold all" is active
-        nChildren = length(get(ca, "Children"));
-        nColors = rows(colorOrder);
-        color_index = mod(nChildren, nColors) + 1;
-      endif
-      rgb = colorOrder(color_index,:);
-    endif
-  else
+  if (nargin > 1)
     print_usage ();
   endif
+
+  if (nargin == 1)
+    ## Indicates whether the next call will increment or not
+    reset_colors = reset;
+  else
+    ## Find and return the next line color
+    ca = gca ();
+    colorOrder = get (ca, "ColorOrder");
+    if (reset_colors)
+      color_index = 1;
+    else
+      ## Executed when "hold all" is active
+      nChildren = length (get (ca, "Children"));
+      nColors = rows (colorOrder);
+      color_index = mod (nChildren, nColors) + 1;
+    endif
+    rgb = colorOrder(color_index,:);
+  endif
+
 endfunction
+
--- a/scripts/plot/private/__next_line_style__.m	Tue Jun 25 14:48:33 2013 -0400
+++ b/scripts/plot/private/__next_line_style__.m	Tue Jul 09 18:53:06 2013 -0700
@@ -28,32 +28,33 @@
 
   persistent reset_style = true;
 
-  if (nargin < 2)
-    if (nargin == 1)
-      % Indicates whether the next call will increment or not
-      reset_style = reset;
-    else
-      % Find and return the next line style
-      ca = gca();
-      style_rotation = get (ca, "linestyleorder");
-      if (ischar (style_rotation))
-        style_rotation = strsplit (style_rotation, "|");
-      endif
-      nStyles = length (style_rotation);
-      if reset_style || (nStyles < 2)
-        style_index = 1;
-      else
-        % Executed when "hold all" is active
-        nChildren = length(get(ca, "Children"));
-        nColors = length(get(ca, "ColorOrder"));
-        style_index = mod(floor(nChildren/nColors), nStyles) + 1;
-      endif
-      options = __pltopt__ ("__next_line_style__",
-                            style_rotation (style_index));
-      linestyle = options.linestyle;
-      marker = options.marker;
-    endif
-  else
+  if (nargin > 1)
     print_usage ();
   endif
+
+  if (nargin == 1)
+    ## Indicates whether the next call will increment or not
+    reset_style = reset;
+  else
+    ## Find and return the next line style
+    ca = gca ();
+    style_rotation = get (ca, "linestyleorder");
+    if (ischar (style_rotation))
+      style_rotation = strsplit (style_rotation, "|");
+    endif
+    nStyles = length (style_rotation);
+    if (reset_style || (nStyles < 2))
+      style_index = 1;
+    else
+      ## Executed when "hold all" is active
+      nChildren = length (get (ca, "Children"));
+      nColors = length (get (ca, "ColorOrder"));
+      style_index = mod (floor (nChildren/nColors), nStyles) + 1;
+    endif
+    options = __pltopt__ ("__next_line_style__",
+                          style_rotation(style_index));
+    linestyle = options.linestyle;
+    marker = options.marker;
+  endif
+
 endfunction