# HG changeset patch # User costerwisch@costerwisch-lt1 # Date 1372186113 14400 # Node ID 78a2f43bbc69c3b6e54688c96171fe83851c8c21 # Parent e6ddaa65a77713029bdf87128f5697dd6e11a372 Implemented line color and style rotation across multiple axes (bug #39344). diff -r e6ddaa65a777 -r 78a2f43bbc69 scripts/plot/private/__next_line_color__.m --- a/scripts/plot/private/__next_line_color__.m Tue Jul 09 17:37:26 2013 -0700 +++ b/scripts/plot/private/__next_line_color__.m Tue Jun 25 14:48:33 2013 -0400 @@ -23,32 +23,31 @@ ## Return the next line color in the rotation. -## Author: jwe +## Author: Carl Osterwisch function rgb = __next_line_color__ (reset) - persistent color_rotation; - persistent num_colors; - persistent color_index; + persistent reset_colors = true; if (nargin < 2) if (nargin == 1) - if (reset || isempty (color_rotation)) - color_rotation = get (gca (), "colororder"); - num_colors = rows (color_rotation); + % 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 - elseif (! isempty (color_rotation)) - rgb = color_rotation(color_index,:); - if (++color_index > num_colors) - color_index = 1; - __next_line_style__ ("incr"); - endif - else - error ("__next_line_color__: color_rotation not initialized"); + rgb = colorOrder(color_index,:); endif else print_usage (); endif - endfunction diff -r e6ddaa65a777 -r 78a2f43bbc69 scripts/plot/private/__next_line_style__.m --- a/scripts/plot/private/__next_line_style__.m Tue Jul 09 17:37:26 2013 -0700 +++ b/scripts/plot/private/__next_line_style__.m Tue Jun 25 14:48:33 2013 -0400 @@ -26,36 +26,34 @@ function [linestyle, marker] = __next_line_style__ (reset) - persistent style_rotation; - persistent num_styles; - persistent style_index; + persistent reset_style = true; if (nargin < 2) if (nargin == 1) - if (ischar (reset) && strncmp (reset, "incr", 4)) - if (isempty (style_rotation)) - error ("__next_line_style__: style_rotation not initialized"); - elseif (++style_index > num_styles) - style_index = 1; - endif - elseif (reset || isempty (style_rotation)) - style_rotation = get (gca (), "linestyleorder"); - if (ischar (style_rotation)) - style_rotation = ostrsplit (style_rotation, "|"); - endif - num_styles = length (style_rotation); + % 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 - elseif (! isempty (style_rotation)) options = __pltopt__ ("__next_line_style__", style_rotation (style_index)); linestyle = options.linestyle; marker = options.marker; - else - error ("__next_line_style__: style_rotation not initialized"); endif else print_usage (); endif - endfunction