Skip to content
Closed
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/Plots.jl
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,11 @@ include("init.jl")

include("backends/plotly.jl")
include("backends/web.jl")
include("backends/gr.jl")

include("shorthands.jl")
include("precompile.jl")
@static if backend(_pick_default_backend()) == GRBackend()
include("backends/gr.jl")
include("precompile.jl")
end

end
30 changes: 16 additions & 14 deletions src/backends.jl
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ macro init_backend(s)
end |> esc
end

# include("backends/web.jl")

# ---------------------------------------------------------

# don't do anything as a default
Expand Down Expand Up @@ -131,20 +129,24 @@ CurrentBackend(sym::Symbol) = CurrentBackend(sym, _backend_instance(sym))

# ---------------------------------------------------------

_fallback_default_backend() = backend(GRBackend())
_fallback_default_backend() = :gr
function _default_backend()
env_default = get(ENV, "PLOTS_DEFAULT_BACKEND", "")
if env_default != ""
Symbol(lowercase(env_default))
else
_fallback_default_backend()
end
end

function _pick_default_backend()
if (env_default = get(ENV, "PLOTS_DEFAULT_BACKEND", "")) != ""
if (sym = Symbol(lowercase(env_default))) in _backends
backend(sym)
else
@warn """You have set PLOTS_DEFAULT_BACKEND=$env_default, but it is not a valid backend package.
Choose from: \n\t$(join(sort(_backends), "\n\t"))
"""
_fallback_default_backend()
end
if (sym = _default_backend()) in _backends
backend(sym)
else
_fallback_default_backend()
@warn """You have set $sym as the default backend, but it is not a valid backend package.
Choose from: \n\t$(join(sort(_backends), "\n\t"))
"""
backend(_fallback_default_backend())
end
end

Expand Down Expand Up @@ -289,7 +291,7 @@ end
# ------------------------------------------------------------------------------
# gr

_initialize_backend(pkg::GRBackend) = nothing # COV_EXCL_LINE
_initialize_backend(pkg::GRBackend) = @eval Plots import GR # COV_EXCL_LINE

const _gr_attr = merge_with_base_supported([
:annotations,
Expand Down
4 changes: 2 additions & 2 deletions src/backends/gr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1204,8 +1204,8 @@ function gr_get_legend_geometry(vp, sp)
span_hspace = span + pad # part of the horizontal increment
dx = (textw + (vertical ? 0 : span_hspace)) * get(ekw, :legend_wfactor, 1)

# This is to prevent that linestyle is obscured by large markers.
# We are trying to get markers to not be larger than half the line length.
# This is to prevent that linestyle is obscured by large markers.
# We are trying to get markers to not be larger than half the line length.
# 1 / leg.dy translates base_factor to line length units (important in the context of size kwarg)
# gr_legend_marker_to_line_factor is an empirical constant to translate between line length unit and marker size unit
base_markersize = gr_legend_marker_to_line_factor[] * span / dy # NOTE: arbitrarily based on horizontal measures !
Expand Down
6 changes: 6 additions & 0 deletions src/init.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ using Scratch
using REPL

const plotly_local_file_path = Ref{Union{Nothing,String}}(nothing)
const BACKEND_PATH_GR = @path joinpath(@__DIR__, "backends", "gr.jl")
const BACKEND_PATH_GASTON = @path joinpath(@__DIR__, "backends", "gaston.jl")
const BACKEND_PATH_HDF5 = @path joinpath(@__DIR__, "backends", "hdf5.jl")
const BACKEND_PATH_INSPECTDR = @path joinpath(@__DIR__, "backends", "inspectdr.jl")
Expand Down Expand Up @@ -63,6 +64,11 @@ function __init__()
)
end,
)
if _default_backend() === :gr
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That wasn't a typo since, we need the requires only if GR is not the default backend

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you try if the test passes locally for you? I had this weird situation where it worked locally, but not on CI ...

Copy link
Member

@t-bltg t-bltg Nov 26, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I got no notifications, because the PR was is on draft. Sorry for interfering with this PR then, wanted to see if CI passed.

@require GR = "28b8d3ca-fb5f-59d9-8090-bfdbd6d07a71" begin
include(BACKEND_PATH_GR)
end
end

@require HDF5 = "f67ccb44-e63f-5c2f-98bd-6dc0ccc4ba2f" begin
include(BACKEND_PATH_HDF5)
Expand Down
1 change: 1 addition & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ for name in (
"animations",
"output",
"backends",
"init",
)
@testset "$name" begin
if get(ENV, "VISUAL_REGRESSION_TESTS_AUTO", "false") == "true" && name != "backends"
Expand Down
19 changes: 19 additions & 0 deletions test/test_init.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using Plots, Test

const plots_path = escape_string(pkgdir(Plots))

@testset "Default Backend" begin
out = withenv("PLOTS_DEFAULT_BACKEND" => "Plotly") do
run(```
$(Base.julia_cmd()) -E """
using Pkg
Pkg.activate(; temp = true)
Pkg.develop(path = \"$(plots_path)\")
using Test
using Plots
@test backend() == Plots.PlotlyBackend()
"""
```)
end
@test out.exitcode == 0
end