UnicodePlots: support layout (#3787)
This commit is contained in:
parent
bdbe300412
commit
2dc812aa15
@ -166,13 +166,55 @@ function png(plt::Plot{UnicodePlotsBackend}, fn::AbstractString)
|
|||||||
end
|
end
|
||||||
|
|
||||||
# -------------------------------
|
# -------------------------------
|
||||||
|
Base.show(plt::Plot{UnicodePlotsBackend}) = _show(stdout, MIME("text/plain"), plt)
|
||||||
|
|
||||||
function _show(io::IO, ::MIME"text/plain", plt::Plot{UnicodePlotsBackend})
|
function _show(io::IO, ::MIME"text/plain", plt::Plot{UnicodePlotsBackend})
|
||||||
unicodeplots_rebuild(plt)
|
unicodeplots_rebuild(plt)
|
||||||
n = length(plt.o)
|
nr, nc = size(plt.layout)
|
||||||
for (i, p) in enumerate(plt.o)
|
lines_colored = Array{Union{Nothing,Vector{String}}}(undef, nr, nc)
|
||||||
show(io, p)
|
lines_uncolored = copy(lines_colored)
|
||||||
i < n && println(io)
|
buf = IOBuffer()
|
||||||
|
cbuf = IOContext(buf, :color => true)
|
||||||
|
sps = wmax = 0
|
||||||
|
l_max = zeros(Int, nr)
|
||||||
|
for r in 1:nr
|
||||||
|
lmax = 0
|
||||||
|
for c in 1:nc
|
||||||
|
l = plt.layout[r, c]
|
||||||
|
if l isa GridLayout
|
||||||
|
@error "UnicodePlots: nested layout is currently unsupported !"
|
||||||
|
else
|
||||||
|
if get(l.attr, :blank, false)
|
||||||
|
lines_colored[r, c] = lines_uncolored[r, c] = nothing
|
||||||
|
else
|
||||||
|
sp = plt.o[sps += 1]
|
||||||
|
show(cbuf, sp)
|
||||||
|
colored = String(take!(buf))
|
||||||
|
uncolored = replace(colored, r"\x1B\[[0-9;]*[a-zA-Z]" => "")
|
||||||
|
lines_colored[r, c] = lc = split(colored, "\n")
|
||||||
|
lines_uncolored[r, c] = lu = split(uncolored, "\n")
|
||||||
|
lmax = max(length(lc), lmax)
|
||||||
|
wmax = max(maximum(length.(lu)), wmax)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
l_max[r] = lmax
|
||||||
|
end
|
||||||
|
for r in 1:nr
|
||||||
|
for n in 1:l_max[r]
|
||||||
|
for c in 1:nc
|
||||||
|
pre = c == 1 ? '' : ' '
|
||||||
|
if (lc = lines_colored[r, c]) !== nothing
|
||||||
|
length(lc) < n && continue
|
||||||
|
lu = lines_uncolored[r, c]
|
||||||
|
print(io, pre, lc[n], ' '^(wmax - length(lu[n])))
|
||||||
|
else
|
||||||
|
print(io, pre, ' '^wmax)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
println(io)
|
||||||
|
end
|
||||||
|
r < nr && println(io)
|
||||||
end
|
end
|
||||||
nothing
|
nothing
|
||||||
end
|
end
|
||||||
|
|||||||
@ -1253,16 +1253,15 @@ _backend_skips = Dict(
|
|||||||
6, # embedded images unsupported
|
6, # embedded images unsupported
|
||||||
10, # histogram2d
|
10, # histogram2d
|
||||||
13, # markers unsupported
|
13, # markers unsupported
|
||||||
16, # subplots unsupported
|
16, # nested layout unsupported
|
||||||
17, # grid layout unsupported
|
|
||||||
20, # annotations unsupported
|
20, # annotations unsupported
|
||||||
21, # custom markers unsupported
|
21, # custom markers unsupported
|
||||||
22, # contours unsupported
|
22, # contours unsupported
|
||||||
24, # 3D unsupported
|
24, # 3D unsupported
|
||||||
26, # subplots unsupported
|
26, # nested layout unsupported
|
||||||
29, # layout unsupported
|
29, # nested layout unsupported
|
||||||
33, # grid lines unsupported
|
33, # grid lines unsupported
|
||||||
34, # framestyles unsupported
|
34, # framestyle unsupported
|
||||||
37, # ribbons / filled unsupported
|
37, # ribbons / filled unsupported
|
||||||
38, # histogram2D
|
38, # histogram2D
|
||||||
43, # heatmap with DateTime
|
43, # heatmap with DateTime
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user