Skip to content
This repository was archived by the owner on Jul 13, 2021. It is now read-only.

Commit f7d593f

Browse files
committed
fix to_colormap
1 parent ed06de8 commit f7d593f

File tree

2 files changed

+15
-13
lines changed

2 files changed

+15
-13
lines changed

src/conversions.jl

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -667,27 +667,31 @@ struct Reverse{T}
667667
data::T
668668
end
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))
672672
end
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)
676676
end
677677

678-
679678
"""
680679
to_colormap(b, x)
681680
682681
An `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
"""
687691
Tuple(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)
691695
end
692696

693697
to_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)
696700
A Symbol/String naming the gradient. For more on what names are available please see: `available_gradients()`.
697701
For 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
711714
end
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
717720
end
718721

src/layouting/boundingbox.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@ function boundingbox(x::Text, text::String)
9393
FRect3D(minimum(bb) .- aoffset, whp)
9494
end
9595

96-
9796
boundingbox(x::Text) = boundingbox(x, to_value(x[1]))
9897

9998
function boundingbox(

0 commit comments

Comments
 (0)