diff --git a/Project.toml b/Project.toml index f405c9e9..a5d70c8f 100644 --- a/Project.toml +++ b/Project.toml @@ -51,6 +51,7 @@ Requires = "1" Scratch = "1" Showoff = "0.3.1, 1.0" StatsBase = "0.32, 0.33" +UnicodePlots = "2" julia = "1.5" [extras] diff --git a/src/backends/unicodeplots.jl b/src/backends/unicodeplots.jl index b1f766ec..0812542f 100644 --- a/src/backends/unicodeplots.jl +++ b/src/backends/unicodeplots.jl @@ -6,15 +6,13 @@ warn_on_unsupported_args(::UnicodePlotsBackend, plotattributes::KW) = nothing # -------------------------------------------------------------------------------------- -function _canvas_map() - ( - braille = UnicodePlots.BrailleCanvas, - ascii = UnicodePlots.AsciiCanvas, - block = UnicodePlots.BlockCanvas, - dot = UnicodePlots.DotCanvas, - density = UnicodePlots.DensityCanvas, - ) -end +_canvas_map() = ( + braille = UnicodePlots.BrailleCanvas, + ascii = UnicodePlots.AsciiCanvas, + block = UnicodePlots.BlockCanvas, + dot = UnicodePlots.DotCanvas, + density = UnicodePlots.DensityCanvas, +) # 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) @@ -93,14 +91,7 @@ function rebuildUnicodePlot!(plt::Plot, width, height) end # add a single series -function addUnicodeSeries!( - o, - plotattributes, - addlegend::Bool, - xlim, - ylim; - rev_color_names = Dict(v => k for (k, v) in Colors.color_names), -) +function addUnicodeSeries!(o, plotattributes, addlegend::Bool, xlim, ylim) # get the function, or special handling for step/bar/hist st = plotattributes[:seriestype] if st == :histogram2d @@ -130,12 +121,15 @@ function addUnicodeSeries!( end label = addlegend ? plotattributes[:label] : "" - # if we happen to pass in allowed color symbols, great... otherwise let UnicodePlots decide - lc = convert(ARGB32, plotattributes[:linecolor]) - sym = Symbol( - get(rev_color_names, map(Int, (red(lc).i, green(lc).i, blue(lc).i)), nothing), - ) - color = sym in UnicodePlots.color_cycle ? sym : :auto + lc = plotattributes[:linecolor] + if typeof(lc) <: UnicodePlots.UserColorType + color = lc + elseif lc isa RGBA{Float64} + lc = convert(ARGB32, lc) + color = map(Int, (red(lc).i, green(lc).i, blue(lc).i)) + else + color = :auto + end # add the series x, y = RecipesPipeline.unzip(