rework png output
This commit is contained in:
parent
cc1bd28ccd
commit
096726bcb6
@ -1,8 +1,5 @@
|
|||||||
# https://github.com/JuliaPlots/UnicodePlots.jl
|
# https://github.com/JuliaPlots/UnicodePlots.jl
|
||||||
|
|
||||||
should_warn_on_unsupported(::UnicodePlotsBackend) = false
|
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------------------
|
|
||||||
const _canvas_map = (
|
const _canvas_map = (
|
||||||
braille = UnicodePlots.BrailleCanvas,
|
braille = UnicodePlots.BrailleCanvas,
|
||||||
density = UnicodePlots.DensityCanvas,
|
density = UnicodePlots.DensityCanvas,
|
||||||
@ -13,11 +10,11 @@ const _canvas_map = (
|
|||||||
dot = UnicodePlots.DotCanvas,
|
dot = UnicodePlots.DotCanvas,
|
||||||
)
|
)
|
||||||
|
|
||||||
# do all the magic here... build it all at once,
|
should_warn_on_unsupported(::UnicodePlotsBackend) = false
|
||||||
# since we need to know about all the series at the very beginning
|
|
||||||
function unicodeplots_rebuild(plt::Plot{UnicodePlotsBackend})
|
|
||||||
plt.o = UnicodePlots.Plot[]
|
|
||||||
|
|
||||||
|
_create_backend_figure(plt::Plot{UnicodePlotsBackend}) = plt.o = UnicodePlots.Plot[]
|
||||||
|
|
||||||
|
function _before_layout_calcs(plt::Plot{UnicodePlotsBackend})
|
||||||
up_width = UnicodePlots.DEFAULT_WIDTH[]
|
up_width = UnicodePlots.DEFAULT_WIDTH[]
|
||||||
up_height = UnicodePlots.DEFAULT_HEIGHT[]
|
up_height = UnicodePlots.DEFAULT_HEIGHT[]
|
||||||
|
|
||||||
@ -254,8 +251,7 @@ end
|
|||||||
|
|
||||||
# ------------------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
function png(plt::Plot{UnicodePlotsBackend}, fn::AbstractString)
|
function _show(io::IO, ::MIME"image/png", plt::Plot{UnicodePlotsBackend})
|
||||||
unicodeplots_rebuild(plt)
|
|
||||||
nr, nc = size(plt.layout)
|
nr, nc = size(plt.layout)
|
||||||
s1 = zeros(Int, nr, nc)
|
s1 = zeros(Int, nr, nc)
|
||||||
s2 = zeros(Int, nr, nc)
|
s2 = zeros(Int, nr, nc)
|
||||||
@ -292,18 +288,17 @@ function png(plt::Plot{UnicodePlotsBackend}, fn::AbstractString)
|
|||||||
end
|
end
|
||||||
n1 += m1[r]
|
n1 += m1[r]
|
||||||
end
|
end
|
||||||
UnicodePlots.FileIO.save(fn, img)
|
stream = UnicodePlots.FileIO.Stream{UnicodePlots.FileIO.format"PNG"}(io)
|
||||||
|
UnicodePlots.FileIO.save(stream, img)
|
||||||
end
|
end
|
||||||
nothing
|
nothing
|
||||||
end
|
end
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------------------
|
|
||||||
Base.show(plt::Plot{UnicodePlotsBackend}) = show(stdout, plt)
|
Base.show(plt::Plot{UnicodePlotsBackend}) = show(stdout, plt)
|
||||||
Base.show(io::IO, plt::Plot{UnicodePlotsBackend}) = _show(io, MIME("text/plain"), plt)
|
Base.show(io::IO, plt::Plot{UnicodePlotsBackend}) = _show(io, MIME("text/plain"), plt)
|
||||||
|
|
||||||
# NOTE: _show(...) must be kept for Base.showable (src/output.jl)
|
# NOTE: _show(...) must be kept for Base.showable (src/output.jl)
|
||||||
function _show(io::IO, ::MIME"text/plain", plt::Plot{UnicodePlotsBackend})
|
function _show(io::IO, ::MIME"text/plain", plt::Plot{UnicodePlotsBackend})
|
||||||
unicodeplots_rebuild(plt)
|
|
||||||
nr, nc = size(plt.layout)
|
nr, nc = size(plt.layout)
|
||||||
if nr == 1 && nc == 1 # fast path
|
if nr == 1 && nc == 1 # fast path
|
||||||
n = length(plt.o)
|
n = length(plt.o)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user