Skip to content

Commit

Permalink
UnicodePlots: compat PR for png output (#4648)
Browse files Browse the repository at this point in the history
* adjust to UnicodePlots 3.4

* update tests

* only output to .txt

* restrict ver
  • Loading branch information
t-bltg authored Feb 8, 2023
1 parent a79a219 commit ef50445
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 4 deletions.
5 changes: 3 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ Showoff = "0.3.1, 1"
SnoopPrecompile = "1"
StatsBase = "0.33"
UnicodeFun = "0.4"
UnicodePlots = "2.10, 3"
UnicodePlots = "3.4"
Unzip = "0.1 - 0.2"
julia = "1.6"

Expand All @@ -84,6 +84,7 @@ Colors = "5ae59095-9a9b-59fe-a467-6f913c188581"
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
FileIO = "5789e2e9-d7fb-5bc7-8068-2c6fae9b9549"
FilePathsBase = "48062228-2e41-5def-b9a4-89aafe57970f"
FreeType = "b38be410-82b0-50bf-ab77-7b57e271db43"
Gaston = "4b11ee91-296f-5714-9832-002c20994614"
GeometryBasics = "5c1252a2-5f33-56bf-86c9-59e7332b4326"
Gtk = "4c0ca9eb-093a-5379-98c5-f87ac0bbbf44"
Expand Down Expand Up @@ -112,4 +113,4 @@ Unitful = "1986cc42-f94f-5a68-af5c-568840ba703d"
VisualRegressionTests = "34922c18-7c2a-561c-bac1-01e79b2c4c92"

[targets]
test = ["Aqua", "Colors", "Distributions", "FileIO", "FilePathsBase", "Gaston", "GeometryBasics", "Gtk", "ImageMagick", "Images", "InspectDR", "LibGit2", "OffsetArrays", "PGFPlotsX", "PlotlyJS", "PlotlyBase", "PyPlot", "PythonPlot", "PlotlyKaleido", "HDF5", "RDatasets", "SentinelArrays", "StableRNGs", "StaticArrays", "StatsPlots", "Test", "TestImages", "UnicodePlots", "Unitful", "VisualRegressionTests"]
test = ["Aqua", "Colors", "Distributions", "FileIO", "FilePathsBase", "FreeType", "Gaston", "GeometryBasics", "Gtk", "ImageMagick", "Images", "InspectDR", "LibGit2", "OffsetArrays", "PGFPlotsX", "PlotlyJS", "PlotlyBase", "PyPlot", "PythonPlot", "PlotlyKaleido", "HDF5", "RDatasets", "SentinelArrays", "StableRNGs", "StaticArrays", "StatsPlots", "Test", "TestImages", "UnicodePlots", "Unitful", "VisualRegressionTests"]
7 changes: 5 additions & 2 deletions src/backends/unicodeplots.jl
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,10 @@ end
# ------------------------------------------------------------------------------------------

function _show(io::IO, ::MIME"image/png", plt::Plot{UnicodePlotsBackend})
applicable(UnicodePlots.save_image, io) ||
"Plots(UnicodePlots): saving to `.png` requires `import FreeType, FileIO`" |>
ArgumentError |>
throw
prepare_output(plt)
nr, nc = size(plt.layout)
s1, s2 = map(_ -> zeros(Int, nr, nc), 1:2)
Expand Down Expand Up @@ -310,8 +314,7 @@ function _show(io::IO, ::MIME"image/png", plt::Plot{UnicodePlotsBackend})
end
n1 += m1[r]
end
stream = UnicodePlots.FileIO.Stream{UnicodePlots.FileIO.format"PNG"}(io)
UnicodePlots.FileIO.save(stream, img)
UnicodePlots.save_image(io, img)
end
nothing
end
Expand Down
4 changes: 4 additions & 0 deletions src/init.jl
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,10 @@ include(_path(backend_name()))
show(devnull, pl)
# FIXME: pgfplotsx requires bug
backend_name() === :pgfplotsx && return
if backend_name() === :unicodeplots
savefig(pl, "$fn.txt")
return
end
showable(MIME"image/png"(), pl) && savefig(pl, "$fn.png")
showable(MIME"application/pdf"(), pl) && savefig(pl, "$fn.pdf")
nothing
Expand Down
1 change: 1 addition & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import SentinelArrays: ChainedVector
import GeometryBasics
import OffsetArrays
import ImageMagick
import FreeType # for `unicodeplots`
import LibGit2
import Aqua
import JSON
Expand Down

0 comments on commit ef50445

Please sign in to comment.