Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
t-bltg committed Nov 13, 2024
1 parent 0de8c73 commit 731eadb
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 54 deletions.
1 change: 1 addition & 0 deletions PlotsBase/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ Base64 = "1"
Colors = "0.12 - 0.13"
Contour = "0.6"
Dates = "1"
Downloads = "1"
FFMPEG = "0.4"
FixedPointNumbers = "0.8"
GR = "0.73"
Expand Down
20 changes: 0 additions & 20 deletions PlotsBase/ext/PGFPlotsXExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,26 +26,6 @@ using PlotsBase.Axes
struct PGFPlotsXBackend <: PlotsBase.AbstractBackend end
PlotsBase.@extension_static PGFPlotsXBackend pgfplotsx

######################################################
# FIXME: extension issue, from PGFPlotsX
function _rgb_for_printing(c::Colors.Colorant)
rgb = convert(Colors.RGB{Float64}, c)
# round colors since pgfplots cannot parse scientific notation, eg 1e-10
round.((Colors.red(rgb), Colors.green(rgb), Colors.blue(rgb)); digits = 4)
end
function PGFPlotsX.print_opt(io::IO, c::Colors.Colorant)
rgb_64 = _rgb_for_printing(c)
print(io, "rgb,1:",
"red," , rgb_64[1], ";",
"green,", rgb_64[2], ";",
"blue," , rgb_64[3])
end
function PGFPlotsX.print_tex(io::IO, c::Colors.Colorant)
rgb_64 = _rgb_for_printing(c)
print(io, "rgb=", rgb_64[1], ",", rgb_64[2], ",", rgb_64[3])
end
######################################################

const _pgfplotsx_attrs = PlotsBase.merge_with_base_supported([
:annotations,
:annotationrotation,
Expand Down
42 changes: 14 additions & 28 deletions PlotsBase/ext/PythonPlotExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,20 @@ function PlotsBase.extension_init(::PythonPlotBackend)
PythonCall.pyimport("mpl_toolkits.axes_grid1")
numpy.seterr(invalid = "ignore")

# FIXME: __init__ is bypassed in PythonPlot see PythonPlot.jl/src/init.jl
# we duplicate the code of PythonPlot here
PythonPlot.version = PythonPlot.vparse(PythonCall.pyconvert(String, mpl.__version__))
backend_gui = PythonPlot.find_backend(mpl)
PythonPlot.backend = backend_gui[1]
PythonPlot.gui = backend_gui[2]
PythonCall.pycopy!(PythonPlot.pyplot, PythonCall.pyimport("matplotlib.pyplot")) # raw Python module
PythonCall.pycopy!(PythonPlot.Gcf, PythonCall.pyimport("matplotlib._pylab_helpers").Gcf)
PythonCall.pycopy!(PythonPlot.orig_gcf, PythonPlot.pyplot.gcf)
PythonCall.pycopy!(PythonPlot.orig_figure, PythonPlot.pyplot.figure)
PythonPlot.pyplot.gcf = PythonPlot.gcf
PythonPlot.pyplot.figure = PythonPlot.figure
##################################################################
@static if false
# FIXME: __init__ is bypassed in PythonPlot see PythonPlot.jl/src/init.jl
# we duplicate the code of PythonPlot here
PythonPlot.version = PythonPlot.vparse(PythonCall.pyconvert(String, mpl.__version__))
backend_gui = PythonPlot.find_backend(mpl)
PythonPlot.backend = backend_gui[1]
PythonPlot.gui = backend_gui[2]
PythonCall.pycopy!(PythonPlot.pyplot, PythonCall.pyimport("matplotlib.pyplot")) # raw Python module
PythonCall.pycopy!(PythonPlot.Gcf, PythonCall.pyimport("matplotlib._pylab_helpers").Gcf)
PythonCall.pycopy!(PythonPlot.orig_gcf, PythonPlot.pyplot.gcf)
PythonCall.pycopy!(PythonPlot.orig_figure, PythonPlot.pyplot.figure)
PythonPlot.pyplot.gcf = PythonPlot.gcf
PythonPlot.pyplot.figure = PythonPlot.figure
end

PythonPlot.ioff() # we don't want every command to update the figure

Expand All @@ -76,21 +77,6 @@ function PlotsBase.extension_init(::PythonPlotBackend)
end
end

function PlotsBase.extension_cleanup(::PythonPlotBackend)
mpl_toolkits = PythonCall.pynew()
numpy = PythonCall.pynew()
mpl = PythonCall.pynew()
PythonPlot.pyplot.gcf = PythonCall.pynew()
PythonPlot.pyplot.figure = PythonCall.pynew()
PythonPlot.pyplot = PythonCall.pynew()
PythonPlot.Gcf = PythonCall.pynew()
PythonPlot.orig_gcf = PythonCall.pynew()
PythonPlot.orig_figure = PythonCall.pynew()
PythonPlot.backend = PythonCall.pynew()
PythonPlot.gui = PythonCall.pynew()
nothing
end

PlotsBase.@extension_static PythonPlotBackend pythonplot

const _pythonplot_attrs = PlotsBase.merge_with_base_supported([
Expand Down
5 changes: 2 additions & 3 deletions PlotsBase/src/backends.jl
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,6 @@ end
"extra init step for an extension"
extension_init(::AbstractBackend) = nothing

extension_cleanup(::AbstractBackend) = nothing

"generate extension `__init__` function, and common defines"
macro extension_static(be_type, be)
be_sym = QuoteNode(be)
Expand All @@ -194,7 +192,8 @@ macro extension_static(be_type, be)
PlotsBase._backendType[$be_sym] = $be_type
PlotsBase._backendSymbol[$be_type] = $be_sym
push!(PlotsBase._initialized_backends, $be_sym)
PlotsBase.extension_init($be_type())
ccall(:jl_generating_output, Cint, ()) == 1 && return
PlotsBase.extension_init($be_type()) # runtime init, incompatible with precompilation
@debug $("Initialized $be_type backend in PlotsBase; run `$be()` to activate it.")
end
end |> esc
Expand Down
7 changes: 6 additions & 1 deletion PlotsBase/src/init.jl
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,18 @@ macro precompile_backend(backend_package)
examples,
quote
$func() = begin # evaluate each example in a local scope
if backend_name() :pythonplot
return # FIXME: __init__ failure with PythonPlot
end
$(PlotsBase._examples[i].exprs)
@debug $i
$i == 1 || return # trigger display only for one example
fn = tempname(scratch_dir)
pl = current()
show(devnull, pl)
if backend_name() :pgfplotsx
return # FIXME: `Colors` extension issue for PFPlotsX
end
if backend_name() :unicodeplots
savefig(pl, "$fn.txt")
return
Expand All @@ -165,7 +171,6 @@ macro precompile_backend(backend_package)
eval.(imports)
eval.(examples)
PlotsBase.CURRENT_PLOT.nullableplot = nothing
PlotsBase.extension_cleanup($abstract_backend())
end
end
end
Expand Down
5 changes: 3 additions & 2 deletions PlotsBase/test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import PlotsBase: PLOTS_SEED, Plot, with
import SentinelArrays: ChainedVector
import GeometryBasics
import OffsetArrays
import Downloads
import FreeType # for `unicodeplots`
import LibGit2
import Aqua
Expand Down Expand Up @@ -55,11 +56,11 @@ function available_channels()
juliaup = "https://julialang-s3.julialang.org/juliaup"
for i 1:6
buf = PipeBuffer()
pipeline(`curl -s $juliaup/DBVERSION` |> ignorestatus, stdout=buf) |> run
Downloads.download("$juliaup/DBVERSION", buf)
dbversion = VersionNumber(readline(buf))
dbversion.major == 1 || continue
buf = PipeBuffer()
pipeline(`curl -s $juliaup/versiondb/versiondb-$dbversion-x86_64-unknown-linux-gnu.json` |> ignorestatus, stdout=buf) |> run
Downloads.download("$juliaup/versiondb/versiondb-$dbversion-x86_64-unknown-linux-gnu.json", buf)
json = JSON.parse(buf)
haskey(json, "AvailableChannels") || continue
return json["AvailableChannels"]
Expand Down
2 changes: 2 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ author = ["Tom Breloff (@tbreloff)"]
version = "2.0.0"

[deps]
Contour = "d38c429a-6771-53c6-b99e-75d170b6e991"
GR = "28b8d3ca-fb5f-59d9-8090-bfdbd6d07a71"
PlotsBase = "c52230a3-c5da-43a3-9e85-260fcdfdc737"
PrecompileTools = "aea7be01-6a6a-4083-8856-8a6e6704d82a"
Reexport = "189a3867-3050-52da-a836-e630ba90ab69"

[compat]
Contour = "0.6.3"
GR = "0.73"
PlotsBase = "0.1"
PrecompileTools = "1"
Expand Down

0 comments on commit 731eadb

Please sign in to comment.