Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 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
7 changes: 5 additions & 2 deletions src/Plots.jl
Original file line number Diff line number Diff line change
Expand Up @@ -194,14 +194,17 @@ include("fileio.jl")
const _plotly_min_js_filename = "plotly-2.6.3.min.js"
const CURRENT_BACKEND = CurrentBackend(:none)
const PLOTS_SEED = 1234
backend(_pick_default_backend())

include("init.jl")

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

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

end
24 changes: 13 additions & 11 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,21 +129,25 @@ 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
if (sym = _default_backend()) in _backends
backend(sym)
else
@warn """You have set PLOTS_DEFAULT_BACKEND=$env_default, but it is not a valid backend package.
@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"))
"""
_fallback_default_backend()
backend(_fallback_default_backend())
end
else
_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
@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