UnicodePlots: allow passing arbitrary colors (RGBA, symbols, integers, ...) (#3758)
This commit is contained in:
parent
f85f668f18
commit
c67da7d7b8
@ -51,6 +51,7 @@ Requires = "1"
|
|||||||
Scratch = "1"
|
Scratch = "1"
|
||||||
Showoff = "0.3.1, 1.0"
|
Showoff = "0.3.1, 1.0"
|
||||||
StatsBase = "0.32, 0.33"
|
StatsBase = "0.32, 0.33"
|
||||||
|
UnicodePlots = "2"
|
||||||
julia = "1.5"
|
julia = "1.5"
|
||||||
|
|
||||||
[extras]
|
[extras]
|
||||||
|
|||||||
@ -6,15 +6,13 @@ warn_on_unsupported_args(::UnicodePlotsBackend, plotattributes::KW) = nothing
|
|||||||
|
|
||||||
# --------------------------------------------------------------------------------------
|
# --------------------------------------------------------------------------------------
|
||||||
|
|
||||||
function _canvas_map()
|
_canvas_map() = (
|
||||||
(
|
braille = UnicodePlots.BrailleCanvas,
|
||||||
braille = UnicodePlots.BrailleCanvas,
|
ascii = UnicodePlots.AsciiCanvas,
|
||||||
ascii = UnicodePlots.AsciiCanvas,
|
block = UnicodePlots.BlockCanvas,
|
||||||
block = UnicodePlots.BlockCanvas,
|
dot = UnicodePlots.DotCanvas,
|
||||||
dot = UnicodePlots.DotCanvas,
|
density = UnicodePlots.DensityCanvas,
|
||||||
density = UnicodePlots.DensityCanvas,
|
)
|
||||||
)
|
|
||||||
end
|
|
||||||
|
|
||||||
# do all the magic here... build it all at once, since we need to know about all the series at the very beginning
|
# do all the magic here... build it all at once, since we need to know about all the series at the very beginning
|
||||||
function rebuildUnicodePlot!(plt::Plot, width, height)
|
function rebuildUnicodePlot!(plt::Plot, width, height)
|
||||||
@ -93,14 +91,7 @@ function rebuildUnicodePlot!(plt::Plot, width, height)
|
|||||||
end
|
end
|
||||||
|
|
||||||
# add a single series
|
# add a single series
|
||||||
function addUnicodeSeries!(
|
function addUnicodeSeries!(o, plotattributes, addlegend::Bool, xlim, ylim)
|
||||||
o,
|
|
||||||
plotattributes,
|
|
||||||
addlegend::Bool,
|
|
||||||
xlim,
|
|
||||||
ylim;
|
|
||||||
rev_color_names = Dict(v => k for (k, v) in Colors.color_names),
|
|
||||||
)
|
|
||||||
# get the function, or special handling for step/bar/hist
|
# get the function, or special handling for step/bar/hist
|
||||||
st = plotattributes[:seriestype]
|
st = plotattributes[:seriestype]
|
||||||
if st == :histogram2d
|
if st == :histogram2d
|
||||||
@ -130,12 +121,15 @@ function addUnicodeSeries!(
|
|||||||
end
|
end
|
||||||
label = addlegend ? plotattributes[:label] : ""
|
label = addlegend ? plotattributes[:label] : ""
|
||||||
|
|
||||||
# if we happen to pass in allowed color symbols, great... otherwise let UnicodePlots decide
|
lc = plotattributes[:linecolor]
|
||||||
lc = convert(ARGB32, plotattributes[:linecolor])
|
if typeof(lc) <: UnicodePlots.UserColorType
|
||||||
sym = Symbol(
|
color = lc
|
||||||
get(rev_color_names, map(Int, (red(lc).i, green(lc).i, blue(lc).i)), nothing),
|
elseif lc isa RGBA{Float64}
|
||||||
)
|
lc = convert(ARGB32, lc)
|
||||||
color = sym in UnicodePlots.color_cycle ? sym : :auto
|
color = map(Int, (red(lc).i, green(lc).i, blue(lc).i))
|
||||||
|
else
|
||||||
|
color = :auto
|
||||||
|
end
|
||||||
|
|
||||||
# add the series
|
# add the series
|
||||||
x, y = RecipesPipeline.unzip(
|
x, y = RecipesPipeline.unzip(
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user