Skip to content
Closed
Show file tree
Hide file tree
Changes from 16 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
4 changes: 3 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "Plots"
uuid = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
author = ["Tom Breloff (@tbreloff)"]
version = "1.36.4"
version = "1.36.5"

[deps]
Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"
Expand All @@ -21,6 +21,7 @@ NaNMath = "77ba4419-2d1f-58cd-9bb1-8ffee604a2e3"
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
PlotThemes = "ccf2f8ad-2431-5c83-bf29-c5338b663b6a"
PlotUtils = "995b91a9-d308-5afd-9ec6-746e21dbc043"
Preferences = "21216c6a-2e73-6563-6e65-726566657250"
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
REPL = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
Expand Down Expand Up @@ -62,6 +63,7 @@ PyCall = "1"
PyPlot = "2"
RecipesBase = "1.3.1"
RecipesPipeline = "0.6.10"
Preferences = "1"
Reexport = "0.2, 1"
RelocatableFolders = "0.3, 1"
Requires = "1"
Expand Down
7 changes: 5 additions & 2 deletions src/Plots.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ using Base.Meta
using Requires
using Reexport
using Unzip
@reexport using Preferences
@reexport using RecipesBase
@reexport using PlotThemes
@reexport using PlotUtils
Expand Down Expand Up @@ -204,9 +205,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
25 changes: 11 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,19 @@ CurrentBackend(sym::Symbol) = CurrentBackend(sym, _backend_instance(sym))

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

_fallback_default_backend() = backend(GRBackend())
_fallback_default_backend() = "gr"
function _default_backend()
Symbol(lowercase(@load_preference("default_backend", _fallback_default_backend())))
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 +286,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 @@ -1231,8 +1231,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
@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 @@ -30,6 +30,7 @@ hdf5()
gr()

for name in (
"init",
"quality",
"misc",
"utils",
Expand Down
23 changes: 23 additions & 0 deletions test/test_init.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using Plots, Test

const plots_path = escape_string(pkgdir(Plots))

@testset "Default Backend" begin
set_preferences!(Plots, "default_backend" => "plotly")
out = run(```
$(Base.julia_cmd()) -E """
using Pkg
Pkg.activate(; temp = true)
Pkg.develop(path = \"$(plots_path)\")
using Test
using Plots
@test backend() == Plots.PlotlyBackend()
"""
```)
@test out.exitcode == 0
set_preferences!(
Plots,
"default_backend" => Plots._fallback_default_backend(),
force = true,
)
end