UnicodePlots: rework png output (#4171)
This commit is contained in:
parent
e691a42b90
commit
02351a45b4
16
.github/workflows/docs.yml
vendored
16
.github/workflows/docs.yml
vendored
@ -9,7 +9,7 @@ on:
|
|||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
Build_docs:
|
Build_docs:
|
||||||
runs-on: ubuntu-18.04
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
with:
|
with:
|
||||||
@ -29,17 +29,14 @@ jobs:
|
|||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
run: |
|
run: |
|
||||||
sudo apt-get update -y
|
sudo apt-get update -y
|
||||||
sudo apt-get install -y qt5-default \
|
sudo apt-get install -y \
|
||||||
|
texlive-{latex-{base,extra},binaries,pictures,luatex} \
|
||||||
ttf-mscorefonts-installer \
|
ttf-mscorefonts-installer \
|
||||||
poppler-utils \
|
poppler-utils \
|
||||||
pdf2svg \
|
|
||||||
texlive-latex-base \
|
|
||||||
texlive-binaries \
|
|
||||||
texlive-pictures \
|
|
||||||
texlive-latex-extra \
|
|
||||||
texlive-luatex \
|
|
||||||
ghostscript-x \
|
ghostscript-x \
|
||||||
libgconf2-4 \
|
libgconf-2-4 \
|
||||||
|
qt5-default \
|
||||||
|
pdf2svg \
|
||||||
gnuplot
|
gnuplot
|
||||||
- name: Install fonts
|
- name: Install fonts
|
||||||
run: |
|
run: |
|
||||||
@ -49,7 +46,6 @@ jobs:
|
|||||||
url="$repo/releases/download/$ver/JuliaMono-ttf.tar.gz"
|
url="$repo/releases/download/$ver/JuliaMono-ttf.tar.gz"
|
||||||
echo "downloading & extract url=$url"
|
echo "downloading & extract url=$url"
|
||||||
wget -q "$url" -O - | tar -xz -C ~/.fonts
|
wget -q "$url" -O - | tar -xz -C ~/.fonts
|
||||||
ls ~/.fonts
|
|
||||||
sudo fc-cache -vr
|
sudo fc-cache -vr
|
||||||
fc-list | grep 'JuliaMono'
|
fc-list | grep 'JuliaMono'
|
||||||
- name: Build documentation
|
- name: Build documentation
|
||||||
|
|||||||
@ -244,10 +244,9 @@ function gaston_add_series(plt::Plot{GastonBackend}, series::Series)
|
|||||||
if (lx = length(x)) == 2 && lx != nc
|
if (lx = length(x)) == 2 && lx != nc
|
||||||
x = collect(range(x[1], x[2], length = nc))
|
x = collect(range(x[1], x[2], length = nc))
|
||||||
end
|
end
|
||||||
elseif st == :heatmap
|
|
||||||
length(x) == size(z, 2) + 1 && (x = @view x[1:(end - 1)])
|
|
||||||
length(y) == size(z, 1) + 1 && (y = @view y[1:(end - 1)])
|
|
||||||
end
|
end
|
||||||
|
length(x) == size(z, 2) + 1 && (x = (x[1:(end - 1)] + x[2:end]) / 2)
|
||||||
|
length(y) == size(z, 1) + 1 && (y = (y[1:(end - 1)] + y[2:end]) / 2)
|
||||||
end
|
end
|
||||||
if st == :mesh3d
|
if st == :mesh3d
|
||||||
x, y, z = mesh3d_triangles(x, y, z, series[:connections])
|
x, y, z = mesh3d_triangles(x, y, z, series[:connections])
|
||||||
|
|||||||
@ -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,10 @@ 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[]
|
|
||||||
|
|
||||||
|
function _before_layout_calcs(plt::Plot{UnicodePlotsBackend})
|
||||||
|
plt.o = UnicodePlots.Plot[]
|
||||||
up_width = UnicodePlots.DEFAULT_WIDTH[]
|
up_width = UnicodePlots.DEFAULT_WIDTH[]
|
||||||
up_height = UnicodePlots.DEFAULT_HEIGHT[]
|
up_height = UnicodePlots.DEFAULT_HEIGHT[]
|
||||||
|
|
||||||
@ -254,8 +250,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 +287,20 @@ 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)
|
function Base.show(io::IO, plt::Plot{UnicodePlotsBackend})
|
||||||
|
prepare_output(plt)
|
||||||
|
_show(io, MIME("text/plain"), plt)
|
||||||
|
end
|
||||||
|
|
||||||
# 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)
|
||||||
@ -367,4 +364,7 @@ function _show(io::IO, ::MIME"text/plain", plt::Plot{UnicodePlotsBackend})
|
|||||||
end
|
end
|
||||||
|
|
||||||
# we only support MIME"text/plain", hence display(...) falls back to plain-text on stdout
|
# we only support MIME"text/plain", hence display(...) falls back to plain-text on stdout
|
||||||
_display(plt::Plot{UnicodePlotsBackend}) = (show(stdout, plt); println(stdout))
|
function _display(plt::Plot{UnicodePlotsBackend})
|
||||||
|
show(stdout, plt)
|
||||||
|
println(stdout)
|
||||||
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user