diff --git a/src/args.jl b/src/args.jl index c869bc5c..f721e754 100644 --- a/src/args.jl +++ b/src/args.jl @@ -1510,19 +1510,19 @@ function has_black_border_for_default(st::Symbol) like_histogram(st) || st in (:hexbin, :bar, :shape) end - -# converts a symbol or string into a colorant (Colors.RGB), and assigns a color automatically -function getSeriesRGBColor(c, sp::Subplot, n::Int) +# converts a symbol or string into a Colorant or ColorGradient +# and assigns a color automatically +function get_series_color(c, sp::Subplot, n::Int, seriestype) if c == :auto - c = autopick(sp[:color_palette], n) + c = like_surface(seriestype) ? cgrad() : autopick(sp[:color_palette], n) elseif isa(c, Int) c = autopick(sp[:color_palette], c) end plot_color(c) end -function getSeriesRGBColor(c::AbstractArray, sp::Subplot, n::Int) - map(x->getSeriesRGBColor(x, sp, n), c) +function get_series_color(c::AbstractArray, sp::Subplot, n::Int, seriestype) + map(x->get_series_color(x, sp, n), c, seriestype) end function ensure_gradient!(plotattributes::KW, csym::Symbol, asym::Symbol) @@ -1567,21 +1567,23 @@ function _update_series_attributes!(plotattributes::KW, plt::Plot, sp::Subplot) end # update series color - plotattributes[:seriescolor] = getSeriesRGBColor(plotattributes[:seriescolor], sp, plotIndex) + scolor = plotattributes[:seriescolor] + stype = plotattributes[:seriestype] + plotattributes[:seriescolor] = scolor = get_series_color(scolor, sp, plotIndex, stype) # update other colors for s in (:line, :marker, :fill) csym, asym = Symbol(s,:color), Symbol(s,:alpha) plotattributes[csym] = if plotattributes[csym] == :auto - plot_color(if has_black_border_for_default(plotattributes[:seriestype]) && s == :line + plot_color(if has_black_border_for_default(stype) && s == :line sp[:foreground_color_subplot] else - plotattributes[:seriescolor] + scolor end) elseif plotattributes[csym] == :match - plot_color(plotattributes[:seriescolor]) + plot_color(scolor) else - getSeriesRGBColor(plotattributes[csym], sp, plotIndex) + get_series_color(plotattributes[csym], sp, plotIndex, stype) end end @@ -1589,9 +1591,9 @@ function _update_series_attributes!(plotattributes::KW, plt::Plot, sp::Subplot) plotattributes[:markerstrokecolor] = if plotattributes[:markerstrokecolor] == :match plot_color(sp[:foreground_color_subplot]) elseif plotattributes[:markerstrokecolor] == :auto - getSeriesRGBColor(plotattributes[:markercolor], sp, plotIndex) + get_series_color(plotattributes[:markercolor], sp, plotIndex, stype) else - getSeriesRGBColor(plotattributes[:markerstrokecolor], sp, plotIndex) + get_series_color(plotattributes[:markerstrokecolor], sp, plotIndex, stype) end # if marker_z, fill_z or line_z are set, ensure we have a gradient diff --git a/src/backends/gr.jl b/src/backends/gr.jl index 3831ffda..b7111562 100644 --- a/src/backends/gr.jl +++ b/src/backends/gr.jl @@ -548,7 +548,7 @@ end const _gr_gradient_alpha = ones(256) function gr_set_gradient(c) - grad = c isa ColorGradient ? c : cgrad() + grad = _as_gradient(c) for (i,z) in enumerate(range(0, stop=1, length=256)) c = grad[z] GR.setcolorrep(999+i, red(c), green(c), blue(c)) diff --git a/src/backends/plotly.jl b/src/backends/plotly.jl index 3fd226de..dc06ed45 100644 --- a/src/backends/plotly.jl +++ b/src/backends/plotly.jl @@ -354,7 +354,7 @@ end function plotly_colorscale(grad::ColorGradient, α) [[grad.values[i], rgba_string(plot_color(grad.colors[i], α))] for i in 1:length(grad.colors)] end -plotly_colorscale(c, α) = plotly_colorscale(cgrad(alpha=α), α) +plotly_colorscale(c::Colorant,α) = plotly_colorscale(_as_gradient(c),α) function plotly_colorscale(c::AbstractVector{<:RGBA}, α) if length(c) == 1 return [[0.0, rgba_string(plot_color(c[1], α))], [1.0, rgba_string(plot_color(c[1], α))]] diff --git a/src/backends/pyplot.jl b/src/backends/pyplot.jl index 1e3ca98d..8697c07f 100644 --- a/src/backends/pyplot.jl +++ b/src/backends/pyplot.jl @@ -73,7 +73,7 @@ function py_colormap(grad::ColorGradient) cm."set_bad"(color=(0,0,0,0.0), alpha=0.0) cm end -py_colormap(c) = py_colormap(cgrad()) +py_colormap(c::Colorant) = py_colormap(_as_gradient(c)) function py_shading(c, z) diff --git a/src/utils.jl b/src/utils.jl index 472f67c4..4b9c7ceb 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -273,6 +273,9 @@ _cycle(v, indices::AVec{Int}) = fill(v, length(indices)) _cycle(grad::ColorGradient, idx::Int) = _cycle(grad.colors, idx) _cycle(grad::ColorGradient, indices::AVec{Int}) = _cycle(grad.colors, indices) +_as_gradient(grad::ColorGradient) = grad +_as_gradient(c::Colorant) = ColorGradient([c,c]) + makevec(v::AVec) = v makevec(v::T) where {T} = T[v]