@@ -667,27 +667,31 @@ struct Reverse{T}
667667 data:: T
668668end
669669
670- function convert_attribute (r:: Reverse , :: key"colormap" , n:: Integer = 20 )
670+ function convert_attribute (r:: Reverse , :: key"colormap" , n:: Integer = 20 )
671671 reverse (to_colormap (r. data, n))
672672end
673673
674- function convert_attribute (cs:: ColorScheme , :: key"colormap" , n:: Integer = 20 )
674+ function convert_attribute (cs:: ColorScheme , :: key"colormap" , n:: Integer = 20 )
675675 return to_colormap (cs. colors, n)
676676end
677677
678-
679678"""
680679 to_colormap(b, x)
681680
682681An `AbstractVector{T}` with any object that [`to_color`](@ref) accepts.
683682"""
684- convert_attribute (cm:: AbstractVector , :: key"colormap" ) = to_color .(cm)
683+ convert_attribute (cm:: AbstractVector , :: key"colormap" , n:: Int = length (cm)) = to_colormap (to_color .(cm), n)
684+
685+ function convert_attribute (cm:: AbstractVector{<: Colorant} , :: key"colormap" , n:: Int = length (cm))
686+ colormap = length (cm) == n ? cm : resample (cm, n)
687+ return el32convert (colormap)
688+ end
685689
686690"""
687691Tuple(A, B) or Pair{A, B} with any object that [`to_color`](@ref) accepts
688692"""
689- function convert_attribute (cs:: Union{Tuple, Pair} , :: key"colormap" )
690- [to_color .(cs)... ]
693+ function convert_attribute (cs:: Union{Tuple, Pair} , :: key"colormap" , n :: Int = 2 )
694+ return to_colormap ( [to_color .(cs)... ], n)
691695end
692696
693697to_colormap (x, n:: Integer ) = convert_attribute (x, key " colormap" (), n)
@@ -696,23 +700,22 @@ to_colormap(x, n::Integer) = convert_attribute(x, key"colormap"(), n)
696700A Symbol/String naming the gradient. For more on what names are available please see: `available_gradients()`.
697701For now, we support gradients from `PlotUtils` natively.
698702"""
699- function convert_attribute (cs:: Union{String, Symbol} , :: key"colormap" , n:: Integer = 20 )
703+ function convert_attribute (cs:: Union{String, Symbol} , :: key"colormap" , n:: Integer = 20 )
700704 cs_string = string (cs)
701-
702705 if cs_string in all_gradient_names
703706 if cs_string in colorbrewer_8color_names # special handling for 8 color only
704- return resample (ColorBrewer. palette (cs_string, 8 ), n)
707+ return to_colormap (ColorBrewer. palette (cs_string, 8 ), n)
705708 else # cs_string must be in plotutils_names
706- return PlotUtils. cvec (Symbol (cs), n) .| > color .| > x -> convert (RGB{FixedPointNumbers . Normed{UInt8, 8 }}, x )
709+ return RGBf0 .( PlotUtils. cvec (Symbol (cs), n))
707710 end
708711 else
709712 error (" There is no color gradient named: $cs " )
710713 end
711714end
712715
713- function AbstractPlotting. convert_attribute (cg:: PlotUtils.ColorGradient , :: key"colormap" , n:: Integer = 30 )
716+ function AbstractPlotting. convert_attribute (cg:: PlotUtils.ColorGradient , :: key"colormap" , n:: Integer = length (cg . values) )
714717 # PlotUtils does not always give [0, 1] range, so we adapt to what it has
715- return getindex .(Ref (cg), LinRange (first (c . values), last (c . values), n)) # workaround until PlotUtils tags a release
718+ return getindex .(Ref (cg), LinRange (first (cg . values), last (cg . values), n)) # workaround until PlotUtils tags a release
716719 # TODO change this once PlotUtils supports collections of indices
717720end
718721
0 commit comments