From af7e915424bade23b8a2f738910568dbd5d3b4f0 Mon Sep 17 00:00:00 2001 From: t-bltg Date: Thu, 30 Dec 2021 18:56:39 +0100 Subject: [PATCH] Pluto compat --- src/backends.jl | 2 +- src/backends/unicodeplots.jl | 24 +++++++++++++----------- src/output.jl | 2 ++ 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/backends.jl b/src/backends.jl index 782d7149..87f0014b 100644 --- a/src/backends.jl +++ b/src/backends.jl @@ -972,8 +972,8 @@ const _unicodeplots_scale = [:identity, :ln, :log2, :log10] # Additional constants const _unicodeplots_canvas = Ref(:auto) const _unicodeplots_border = Ref(:auto) -const _unicodeplots_width = Ref(40) const _unicodeplots_height = Ref(15) +const _unicodeplots_width = Ref(40) # ------------------------------------------------------------------------------ # hdf5 diff --git a/src/backends/unicodeplots.jl b/src/backends/unicodeplots.jl index e8f0e121..eb75484b 100644 --- a/src/backends/unicodeplots.jl +++ b/src/backends/unicodeplots.jl @@ -1,17 +1,17 @@ # https://github.com/JuliaPlots/UnicodePlots.jl -# don't warn on unsupported... there's just too many warnings!! +# don't warn on unsupported... there's just too many warnings ! warn_on_unsupported_args(::UnicodePlotsBackend, plotattributes) = nothing # ------------------------------------------------------------------------------------------ const _canvas_map = ( - ascii = UnicodePlots.AsciiCanvas, - block = UnicodePlots.BlockCanvas, braille = UnicodePlots.BrailleCanvas, density = UnicodePlots.DensityCanvas, - dot = UnicodePlots.DotCanvas, heatmap = UnicodePlots.HeatmapCanvas, lookup = UnicodePlots.LookupCanvas, + ascii = UnicodePlots.AsciiCanvas, + block = UnicodePlots.BlockCanvas, + dot = UnicodePlots.DotCanvas, ) # do all the magic here... build it all at once, @@ -25,10 +25,10 @@ function unicodeplots_rebuild(plt::Plot{UnicodePlotsBackend}) xlim = collect(axis_limits(sp, :x)) ylim = collect(axis_limits(sp, :y)) - # we set x/y to have a single point, + # We set x/y to have a single point, # since we need to create the plot with some data. - # since this point is at the bottom left corner of the plot, - # it shouldn't actually be shown + # Since this point is at the bottom left corner of the plot, + # it should be hidden by consecutive plotting commands. x = Float64[xlim[1]] y = Float64[ylim[1]] @@ -51,8 +51,8 @@ function unicodeplots_rebuild(plt::Plot{UnicodePlotsBackend}) title = texmath2unicode(sp[:title]), xlabel = texmath2unicode(xaxis[:guide]), ylabel = texmath2unicode(yaxis[:guide]), - width = _unicodeplots_width[], height = _unicodeplots_height[], + width = _unicodeplots_width[], xscale = xaxis[:scale], yscale = yaxis[:scale], border = border, @@ -196,8 +196,10 @@ end # ------------------------------------------------------------------------------------------ Base.show(plt::Plot{UnicodePlotsBackend}) = show(stdout, plt) +Base.show(io::IO, plt::Plot{UnicodePlotsBackend}) = _show(io, MIME("text/plain"), plt) -function Base.show(io::IO, plt::Plot{UnicodePlotsBackend}) +# NOTE: _show(..) must be kept for Base.showable (src/output.jl) +function _show(io::IO, ::MIME"text/plain", plt::Plot{UnicodePlotsBackend}) unicodeplots_rebuild(plt) nr, nc = size(plt.layout) if nr == 1 && nc == 1 # fast path @@ -207,13 +209,13 @@ function Base.show(io::IO, plt::Plot{UnicodePlotsBackend}) i < n && println(io) end else + re_col = r"\e\[[0-9;]*m" # m: color, [a-zA-Z]: all escape sequences have_color = Base.get_have_color() + buf = IOContext(PipeBuffer(), :color => have_color) lines_colored = Array{Union{Nothing,Vector{String}}}(undef, nr, nc) lines_uncolored = have_color ? similar(lines_colored) : lines_colored l_max = zeros(Int, nr) w_max = zeros(Int, nc) - buf = IOContext(PipeBuffer(), :color => have_color) - re_col = r"\e\[[0-9;]*[a-zA-Z]" sps = 0 for r in 1:nr lmax = 0 diff --git a/src/output.jl b/src/output.jl index dd028837..89cc29ae 100644 --- a/src/output.jl +++ b/src/output.jl @@ -217,6 +217,8 @@ for mime in ( end end +Base.showable(::MIME"text/html", plt::Plot{UnicodePlotsBackend}) = false # Pluto + Base.show(io::IO, m::MIME"application/prs.juno.plotpane+html", plt::Plot) = showjuno(io, MIME("text/html"), plt)