Mercurial > hg > octave-lyh
changeset 16942:78a2f43bbc69
Implemented line color and style rotation across multiple axes (bug #39344).
author | costerwisch@costerwisch-lt1 |
---|---|
date | Tue, 25 Jun 2013 14:48:33 -0400 |
parents | e6ddaa65a777 |
children | 0dab17e69a55 |
files | scripts/plot/private/__next_line_color__.m scripts/plot/private/__next_line_style__.m |
diffstat | 2 files changed, 32 insertions(+), 35 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/plot/private/__next_line_color__.m +++ b/scripts/plot/private/__next_line_color__.m @@ -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
--- a/scripts/plot/private/__next_line_style__.m +++ b/scripts/plot/private/__next_line_style__.m @@ -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