diff --git a/PlotsBase/ext/GRExt.jl b/PlotsBase/ext/GRExt.jl index f180c6fcf..5bc1e7f67 100644 --- a/PlotsBase/ext/GRExt.jl +++ b/PlotsBase/ext/GRExt.jl @@ -1,6 +1,5 @@ module GRExt - import PlotsBase: PlotsBase, _cycle import RecipesPipeline import NaNMath @@ -221,7 +220,6 @@ end PlotsBase.is_marker_supported(::GRBackend, shape::Shape) = true - # https://github.com/jheinen/GR.jl - significant contributions by @jheinen const gr_projections = (auto = 1, ortho = 1, orthographic = 1, persp = 2, perspective = 2) @@ -1984,7 +1982,8 @@ function gr_add_series(sp, series) GR.gr3.clear() elseif st === :heatmap # `z` is already transposed, so we need to reverse before passing its size. - x, y = PlotsBase.heatmap_edges(x, xscale, y, yscale, reverse(size(z)), ispolar(series)) + x, y = + PlotsBase.heatmap_edges(x, xscale, y, yscale, reverse(size(z)), ispolar(series)) gr_draw_heatmap(series, x, y, z, clims) elseif st === :image gr_draw_image(series, x, y, z, clims) @@ -2214,7 +2213,9 @@ function gr_draw_heatmap(series, x, y, z, clims) GR.setspace(clims..., 0, 90) w, h = length(x) - 1, length(y) - 1 sp = series[:subplot] - if !ispolar(series) && PlotsBase.is_uniformly_spaced(x) && PlotsBase.is_uniformly_spaced(y) + if !ispolar(series) && + PlotsBase.is_uniformly_spaced(x) && + PlotsBase.is_uniformly_spaced(y) # For uniformly spaced data use GR.drawimage, which can be # much faster than GR.nonuniformcellarray, especially for # pdf output, and also supports alpha values. diff --git a/PlotsBase/ext/HDF5Ext.jl b/PlotsBase/ext/HDF5Ext.jl index 90904e6f4..1aeaf7783 100644 --- a/PlotsBase/ext/HDF5Ext.jl +++ b/PlotsBase/ext/HDF5Ext.jl @@ -8,8 +8,10 @@ import PlotUtils.Colors: Colorant import RecipesPipeline import RecipesPipeline.datetimeformatter -import PlotUtils.ColorPalette, PlotUtils.CategoricalColorGradient, PlotUtils.ContinuousColorGradient -import PlotsBase: PlotsBase, Surface, Arrow, GridLayout, RootLayout, Font, PlotText, SeriesAnnotations +import PlotUtils.ColorPalette, + PlotUtils.CategoricalColorGradient, PlotUtils.ContinuousColorGradient +import PlotsBase: + PlotsBase, Surface, Arrow, GridLayout, RootLayout, Font, PlotText, SeriesAnnotations import PlotsBase: BoundingBox, Length, Plot, DefaultsDict, plot, plot! using PlotsBase.PlotsSeries @@ -149,7 +151,6 @@ end # PlotsBase.supported_scales(::HDF5Backend) -> ::Vector{Symbol} # ----------------------------------------------------------------------------- - # Additional constants # Dict has problems using "Types" as keys. Initialize in "_initialize_backend": const HDF5PLOT_MAP_STR2TELEM = Dict{String,Type}() @@ -620,5 +621,4 @@ end hdf5plot_write(path::AbstractString) = hdf5plot_write(current(), path) - end # module diff --git a/PlotsBase/ext/PGFPlotsXExt.jl b/PlotsBase/ext/PGFPlotsXExt.jl index 8e95bac90..e72abe26f 100644 --- a/PlotsBase/ext/PGFPlotsXExt.jl +++ b/PlotsBase/ext/PGFPlotsXExt.jl @@ -321,7 +321,8 @@ curly(obj) = "{$(string(obj))}" latex_formatter(formatter::Symbol) = formatter in (:plain, :latex) ? formatter : :latex latex_formatter(formatter::Function) = formatter -PlotsBase.labelfunc(scale::Symbol, backend::PGFPlotsXBackend) = PlotsBase.labelfunc_tex(scale) +PlotsBase.labelfunc(scale::Symbol, backend::PGFPlotsXBackend) = + PlotsBase.labelfunc_tex(scale) pgfx_halign(k) = (left = "left", hcenter = "center", center = "center", right = "right")[k] @@ -1601,18 +1602,27 @@ end PlotsBase._create_backend_figure(plt::Plot{PGFPlotsXBackend}) = plt.o = PGFPlotsXPlot() -PlotsBase._series_added(plt::Plot{PGFPlotsXBackend}, series::Series) = plt.o.is_created = false +PlotsBase._series_added(plt::Plot{PGFPlotsXBackend}, series::Series) = + plt.o.is_created = false PlotsBase._update_plot_object(plt::Plot{PGFPlotsXBackend}) = plt.o(plt) for mime in ("application/pdf", "image/svg+xml", "image/png") - @eval function PlotsBase._show(io::IO, mime::MIME{Symbol($mime)}, plt::Plot{PGFPlotsXBackend}) + @eval function PlotsBase._show( + io::IO, + mime::MIME{Symbol($mime)}, + plt::Plot{PGFPlotsXBackend}, + ) plt.o.was_shown = true show(io, mime, plt.o.the_plot) end end -function PlotsBase._show(io::IO, mime::MIME{Symbol("application/x-tex")}, plt::Plot{PGFPlotsXBackend}) +function PlotsBase._show( + io::IO, + mime::MIME{Symbol("application/x-tex")}, + plt::Plot{PGFPlotsXBackend}, +) plt.o.was_shown = true PGFPlotsX.print_tex( io, diff --git a/PlotsBase/ext/PlotlyJSExt.jl b/PlotsBase/ext/PlotlyJSExt.jl index e4050a697..27f06a4c1 100644 --- a/PlotsBase/ext/PlotlyJSExt.jl +++ b/PlotsBase/ext/PlotlyJSExt.jl @@ -1,6 +1,5 @@ module PlotlyJSExt - import PlotsBase: PlotsBase, Plot, isijulia using PlotsBase.PlotsPlots using PlotsBase.Commons @@ -90,8 +89,11 @@ for (mime, fmt) in ( end # Use the Plotly implementation for json and html: -PlotsBase._show(io::IO, mime::MIME"application/vnd.plotly.v1+json", plt::Plot{PlotlyJSBackend}) = - plotly_show_js(io, plt) +PlotsBase._show( + io::IO, + mime::MIME"application/vnd.plotly.v1+json", + plt::Plot{PlotlyJSBackend}, +) = plotly_show_js(io, plt) PlotsBase.html_head(plt::Plot{PlotlyJSBackend}) = PlotsBase.Plotly.plotly_html_head(plt) PlotsBase.html_body(plt::Plot{PlotlyJSBackend}) = PlotsBase.Plotly.plotly_html_body(plt) @@ -101,8 +103,7 @@ PlotsBase._show(io::IO, ::MIME"text/html", plt::Plot{PlotlyJSBackend}) = PlotsBase._display(plt::Plot{PlotlyJSBackend}) = display(plotlyjs_syncplot(plt)) -WebIO.render(plt::Plot{PlotlyJSBackend}) = - WebIO.render(plotlyjs_syncplot(plt)) +WebIO.render(plt::Plot{PlotlyJSBackend}) = WebIO.render(plotlyjs_syncplot(plt)) PlotsBase.closeall(::PlotlyJSBackend) = if !PlotsBase.isplotnull() && isa(PlotsBase.current().o, PlotlyJS.SyncPlot) diff --git a/PlotsBase/ext/PythonPlotExt.jl b/PlotsBase/ext/PythonPlotExt.jl index 34073353d..5b37e0bd6 100644 --- a/PlotsBase/ext/PythonPlotExt.jl +++ b/PlotsBase/ext/PythonPlotExt.jl @@ -1002,7 +1002,8 @@ function _py_compute_axis_minval(sp::Subplot, axis::Axis) end function _py_set_scale(ax, sp::Subplot, scale::Symbol, letter::Symbol) - scale ∈ PlotsBase.supported_scales() || return @warn "Unhandled scale value in PythonPlot: $scale" + scale ∈ PlotsBase.supported_scales() || + return @warn "Unhandled scale value in PythonPlot: $scale" scl, kw = if scale === :identity "linear", KW() else @@ -1451,7 +1452,8 @@ function PlotsBase._before_layout_calcs(plt::Plot{PythonPlotBackend}) end expand_padding!(padding, bb, plotbb) = - if PlotsBase.ispositive(PlotsBase.width(bb)) && PlotsBase.ispositive(PlotsBase.height(bb)) + if PlotsBase.ispositive(PlotsBase.width(bb)) && + PlotsBase.ispositive(PlotsBase.height(bb)) padding[1] = max(padding[1], PlotsBase.left(plotbb) - PlotsBase.left(bb)) padding[2] = max(padding[2], PlotsBase.top(plotbb) - PlotsBase.top(bb)) padding[3] = max(padding[3], PlotsBase.right(bb) - PlotsBase.right(plotbb)) @@ -1541,7 +1543,13 @@ function _py_legend_pos(pos::Tuple{<:Real,Symbol}) s, c = sincosd(pos[1]) .* (pos[2] === :outer ? -1 : 1) yanchors = "lower", "center", "upper" xanchors = "left", "center", "right" - join([yanchors[PlotsBase.legend_anchor_index(s)], xanchors[PlotsBase.legend_anchor_index(c)]], ' ') + join( + [ + yanchors[PlotsBase.legend_anchor_index(s)], + xanchors[PlotsBase.legend_anchor_index(c)], + ], + ' ', + ) end # legend_pos_from_angle(theta, xmin, xcenter, xmax, ymin, ycenter, ymax) @@ -1706,8 +1714,11 @@ function PlotsBase._update_plot_object(plt::Plot{PythonPlotBackend}) PlotsBase.width(bb), # width PlotsBase.height(sp.bbox) - 2pad, # height ) - get(sp[:extra_kwargs], "3d_colorbar_axis", PlotsBase.bbox_to_pcts(cb_bbox, figw, figh)) |> - sp.attr[:cbar_ax].set_position + get( + sp[:extra_kwargs], + "3d_colorbar_axis", + PlotsBase.bbox_to_pcts(cb_bbox, figw, figh), + ) |> sp.attr[:cbar_ax].set_position end end PythonPlot.draw() @@ -1727,7 +1738,11 @@ for (mime, fmt) in ( "image/svg+xml" => "svg", "application/x-tex" => "pgf", ) - @eval function PlotsBase._show(io::IO, ::MIME{Symbol($mime)}, plt::Plot{PythonPlotBackend}) + @eval function PlotsBase._show( + io::IO, + ::MIME{Symbol($mime)}, + plt::Plot{PythonPlotBackend}, + ) fig = plt.o fig.canvas.print_figure( io, diff --git a/PlotsBase/ext/UnicodePlotsExt.jl b/PlotsBase/ext/UnicodePlotsExt.jl index 0070f3ab4..b517e2176 100644 --- a/PlotsBase/ext/UnicodePlotsExt.jl +++ b/PlotsBase/ext/UnicodePlotsExt.jl @@ -412,7 +412,11 @@ end # ------------------------------------------------------------------------------------------ -function PlotsBase._show(io::IO, ::MIME"image/png", plt::PlotsBase.Plot{UnicodePlotsBackend}) +function PlotsBase._show( + io::IO, + ::MIME"image/png", + plt::PlotsBase.Plot{UnicodePlotsBackend}, +) applicable(UnicodePlots.save_image, io) || "PlotsBase(UnicodePlots): saving to `.png` requires `import FreeType, FileIO`" |> ArgumentError |> @@ -458,10 +462,15 @@ function PlotsBase._show(io::IO, ::MIME"image/png", plt::PlotsBase.Plot{UnicodeP end Base.show(plt::PlotsBase.Plot{UnicodePlotsBackend}) = show(stdout, plt) -Base.show(io::IO, plt::PlotsBase.Plot{UnicodePlotsBackend}) = PlotsBase._show(io, MIME("text/plain"), plt) +Base.show(io::IO, plt::PlotsBase.Plot{UnicodePlotsBackend}) = + PlotsBase._show(io, MIME("text/plain"), plt) # NOTE: _show(...) must be kept for Base.showable (src/output.jl) -function PlotsBase._show(io::IO, ::MIME"text/plain", plt::PlotsBase.Plot{UnicodePlotsBackend}) +function PlotsBase._show( + io::IO, + ::MIME"text/plain", + plt::PlotsBase.Plot{UnicodePlotsBackend}, +) PlotsBase.prepare_output(plt) nr, nc = size(plt.layout) if nr == 1 && nc == 1 # fast path diff --git a/PlotsBase/ext/UnitfulExt.jl b/PlotsBase/ext/UnitfulExt.jl index 059a1d53a..ede2e5713 100644 --- a/PlotsBase/ext/UnitfulExt.jl +++ b/PlotsBase/ext/UnitfulExt.jl @@ -3,7 +3,20 @@ module UnitfulExt -import Unitful: Unitful, Quantity, unit, ustrip, dimension, Units, NoUnits, LogScaled, logunit, MixedUnits, Level, Gain, uconvert +import Unitful: + Unitful, + Quantity, + unit, + ustrip, + dimension, + Units, + NoUnits, + LogScaled, + logunit, + MixedUnits, + Level, + Gain, + uconvert import PlotsBase: PlotsBase, @recipe, PlotText, Subplot, AVec, AMat, Axis import RecipesBase import LaTeXStrings: LaTeXString diff --git a/PlotsBase/src/Commons/Commons.jl b/PlotsBase/src/Commons/Commons.jl index 83858ce55..5d995153d 100644 --- a/PlotsBase/src/Commons/Commons.jl +++ b/PlotsBase/src/Commons/Commons.jl @@ -111,7 +111,8 @@ all_styles(arg) = true_or_all_true(a -> get(Commons._styleAliases, a, a) in Commons._all_styles, arg) all_shapes(arg) = (true_or_all_true( a -> - get(Commons._marker_aliases, a, a) in Commons._all_markers || a isa PlotsBase.Shape, + get(Commons._marker_aliases, a, a) in Commons._all_markers || + a isa PlotsBase.Shape, arg, )) all_alphas(arg) = true_or_all_true( diff --git a/PlotsBase/src/PlotsBase.jl b/PlotsBase/src/PlotsBase.jl index fcba5a9e8..c78fef6f6 100644 --- a/PlotsBase/src/PlotsBase.jl +++ b/PlotsBase/src/PlotsBase.jl @@ -201,4 +201,4 @@ using .Plotly include("init.jl") include("users.jl") -end \ No newline at end of file +end diff --git a/PlotsBase/src/Series.jl b/PlotsBase/src/Series.jl index 251b5ff1b..411e82549 100644 --- a/PlotsBase/src/Series.jl +++ b/PlotsBase/src/Series.jl @@ -225,7 +225,8 @@ struct NaNSegmentsIterator end function Base.iterate(itr::NaNSegmentsIterator, nextidx::Int = itr.n1) - (i = findfirst(!PlotsBase.Commons.anynan(itr.args), nextidx:(itr.n2))) === nothing && return + (i = findfirst(!PlotsBase.Commons.anynan(itr.args), nextidx:(itr.n2))) === nothing && + return nextval = nextidx + i - 1 j = findfirst(PlotsBase.Commons.anynan(itr.args), nextval:(itr.n2)) diff --git a/PlotsBase/src/backends/plotly.jl b/PlotsBase/src/backends/plotly.jl index ce3ee8096..9a97182cf 100644 --- a/PlotsBase/src/backends/plotly.jl +++ b/PlotsBase/src/backends/plotly.jl @@ -519,7 +519,8 @@ function plotly_layout(plt::Plot) plotattributes_out[:hovermode] = "none" end - plotattributes_out = PlotsBase.recursive_merge(plotattributes_out, plt.attr[:extra_plot_kwargs]) + plotattributes_out = + PlotsBase.recursive_merge(plotattributes_out, plt.attr[:extra_plot_kwargs]) end function plotly_add_legend!(plotattributes_out::KW, sp::Subplot) @@ -1317,7 +1318,8 @@ Base.showable(::MIME"application/prs.juno.plotpane+html", plt::Plot{PlotlyBacken PlotsBase._show(io::IO, ::MIME"application/vnd.plotly.v1+json", plot::Plot{PlotlyBackend}) = plotly_show_js(io, plot) -PlotsBase._show(io::IO, ::MIME"text/html", plt::Plot{PlotlyBackend}) = write(io, PlotsBase.embeddable_html(plt)) +PlotsBase._show(io::IO, ::MIME"text/html", plt::Plot{PlotlyBackend}) = + write(io, PlotsBase.embeddable_html(plt)) PlotsBase._display(plt::Plot{PlotlyBackend}) = standalone_html_window(plt) diff --git a/PlotsBase/src/examples.jl b/PlotsBase/src/examples.jl index 77201932f..96c40facc 100644 --- a/PlotsBase/src/examples.jl +++ b/PlotsBase/src/examples.jl @@ -179,8 +179,10 @@ const _examples = PlotExample[ PlotExample( # 13 "Marker types", quote - markers = - filter(m -> m in PlotsBase.supported_markers(), PlotsBase.Commons._shape_keys) + markers = filter( + m -> m in PlotsBase.supported_markers(), + PlotsBase.Commons._shape_keys, + ) markers = permutedims(markers) n = length(markers) x = range(0, stop = 10, length = n + 2)[2:(end - 1)] @@ -295,7 +297,11 @@ const _examples = PlotExample[ """, quote y = rand(10) - plot(y, annotations = (3, y[3], PlotsBase.text("this is #3", :left)), leg = false) + plot( + y, + annotations = (3, y[3], PlotsBase.text("this is #3", :left)), + leg = false, + ) # single vector of annotation tuples annotate!([ (5, y[5], ("this is #5", 16, :red, :center)), @@ -1328,7 +1334,7 @@ replace_module(ex) = ex function replace_module(ex::Expr) if Meta.isexpr(ex, :import) || Meta.isexpr(ex, :using) expr = Expr(ex.head) - for arg ∈ ex.args + for arg in ex.args mod = last(arg.args) new_arg = if Meta.isexpr(arg, :.) mod ≡ :PlotsBase ? arg : Expr(:., :PlotsBase, mod) diff --git a/PlotsBase/src/utils.jl b/PlotsBase/src/utils.jl index f4e7fe725..ef38e1baa 100644 --- a/PlotsBase/src/utils.jl +++ b/PlotsBase/src/utils.jl @@ -1,6 +1,6 @@ # --------------------------------------------------------------- -bool_env(x, default::String="0")::Bool = tryparse(Bool, get(ENV, x, default)) +bool_env(x, default::String = "0")::Bool = tryparse(Bool, get(ENV, x, default)) treats_y_as_x(seriestype) = seriestype in (:vline, :vspan, :histogram, :barhist, :stephist, :scatterhist) diff --git a/PlotsBase/test/runtests.jl b/PlotsBase/test/runtests.jl index 08ecdce51..2d8048ad1 100644 --- a/PlotsBase/test/runtests.jl +++ b/PlotsBase/test/runtests.jl @@ -1,4 +1,14 @@ -const TEST_PACKAGES = strip.(split(get(ENV, "PLOTSBASE_TEST_PACKAGES", "GR,UnicodePlots,PythonPlot,PGFPlotsX,PlotlyJS,Gaston"), ",")) +const TEST_PACKAGES = + strip.( + split( + get( + ENV, + "PLOTSBASE_TEST_PACKAGES", + "GR,UnicodePlots,PythonPlot,PGFPlotsX,PlotlyJS,Gaston", + ), + ",", + ) + ) const TEST_BACKENDS = Symbol.(lowercase.(TEST_PACKAGES)) using PlotsBase diff --git a/PlotsBase/test/test_axes.jl b/PlotsBase/test/test_axes.jl index f22f187f1..abda149df 100644 --- a/PlotsBase/test/test_axes.jl +++ b/PlotsBase/test/test_axes.jl @@ -36,7 +36,8 @@ @test PlotsBase.get_labels(:auto, 1:3, :ln) == ["e^{1}", "e^{2}", "e^{3}"] @test PlotsBase.get_labels(:latex, 1:3, :log10) == ["\$10^{1}\$", "\$10^{2}\$", "\$10^{3}\$"] - @test PlotsBase.get_labels(:latex, 1:3, :log2) == ["\$2^{1}\$", "\$2^{2}\$", "\$2^{3}\$"] + @test PlotsBase.get_labels(:latex, 1:3, :log2) == + ["\$2^{1}\$", "\$2^{2}\$", "\$2^{3}\$"] @test PlotsBase.get_labels(:latex, 1:3, :ln) == ["\$e^{1}\$", "\$e^{2}\$", "\$e^{3}\$"] @test PlotsBase.get_labels(x -> 1e3x, 1:3, :identity) == ["1000", "2000", "3000"] diff --git a/PlotsBase/test/test_backends.jl b/PlotsBase/test/test_backends.jl index 9cc6453f9..b30111944 100644 --- a/PlotsBase/test/test_backends.jl +++ b/PlotsBase/test/test_backends.jl @@ -155,7 +155,10 @@ end pl = plot([Dates.Date(2019, 1, 1), Dates.Date(2019, 2, 1)], [3, 4]) hline!(pl, [3.1]) - annotate!(pl, [(Dates.Date(2019, 1, 15), 3.2, PlotsBase.text("Test", :red, :center))]) + annotate!( + pl, + [(Dates.Date(2019, 1, 15), 3.2, PlotsBase.text("Test", :red, :center))], + ) @test show(io, pl) isa Nothing pl = plot([Dates.Date(2019, 1, 1), Dates.Date(2019, 2, 1)], [3, 4]) @@ -222,7 +225,7 @@ is_pkgeval() || @testset "Examples" begin ) @test filesize(fn) > 1_000 end - Sys.islinux() && for be ∈ TEST_BACKENDS + Sys.islinux() && for be in TEST_BACKENDS skip = vcat(PlotsBase._backend_skips[be], blacklist) PlotsBase.test_examples(be; skip, callback, disp = is_ci(), strict = true) # `ci` display for coverage closeall() diff --git a/PlotsBase/test/test_hdf5plots.jl b/PlotsBase/test/test_hdf5plots.jl index 01a16acac..c9bf158d0 100644 --- a/PlotsBase/test/test_hdf5plots.jl +++ b/PlotsBase/test/test_hdf5plots.jl @@ -5,7 +5,7 @@ using HDF5 hdf5() x = 1:10 - pl = plot(x, x.^2) # create some plot + pl = plot(x, x .^ 2) # create some plot PlotsBase.hdf5plot_write(pl, fname) # read back file diff --git a/PlotsBase/test/test_misc.jl b/PlotsBase/test/test_misc.jl index 859698dd9..6a53aad68 100644 --- a/PlotsBase/test/test_misc.jl +++ b/PlotsBase/test/test_misc.jl @@ -110,7 +110,9 @@ end @test PlotsBase.legend_anchor_index(+1) == 3 @test PlotsBase.legend_angle(:foo_bar) == (45, :inner) - @test PlotsBase.legend_angle(20.0) == PlotsBase.legend_angle((20.0, :inner)) == (20.0, :inner) + @test PlotsBase.legend_angle(20.0) == + PlotsBase.legend_angle((20.0, :inner)) == + (20.0, :inner) @test PlotsBase.legend_angle((20.0, 10.0)) == (20.0, 10.0) end @@ -211,7 +213,10 @@ end end @testset "docstring" begin - @test occursin("label", PlotsBase._generate_doclist(PlotsBase.Commons._all_series_attrs)) + @test occursin( + "label", + PlotsBase._generate_doclist(PlotsBase.Commons._all_series_attrs), + ) end @testset "protect" begin @@ -324,7 +329,8 @@ with(:gr) do end @testset "legends" begin - @test plot([0:1 reverse(0:1)]; labels = ["a" "b"], leg = (0.5, 0.5)) isa PlotsBase.Plot + @test plot([0:1 reverse(0:1)]; labels = ["a" "b"], leg = (0.5, 0.5)) isa + PlotsBase.Plot @test plot([0:1 reverse(0:1)]; labels = ["a" "b"], leg = (0.5, :outer)) isa PlotsBase.Plot @test plot([0:1 reverse(0:1)]; labels = ["a" "b"], leg = (0.5, :inner)) isa diff --git a/PlotsBase/test/test_pgfplotsx.jl b/PlotsBase/test/test_pgfplotsx.jl index 2a9079779..81dde6ea1 100644 --- a/PlotsBase/test/test_pgfplotsx.jl +++ b/PlotsBase/test/test_pgfplotsx.jl @@ -107,9 +107,12 @@ with(:pgfplotsx) do end @testset "Marker types" begin - markers = filter((m -> begin - m in PlotsBase.supported_markers() - end), PlotsBase.Commons._shape_keys) + markers = filter( + (m -> begin + m in PlotsBase.supported_markers() + end), + PlotsBase.Commons._shape_keys, + ) markers = reshape(markers, 1, length(markers)) n = length(markers) x = (range(0, stop = 10, length = n + 2))[2:(end - 1)] diff --git a/PlotsBase/test/test_unitful.jl b/PlotsBase/test/test_unitful.jl index bb005917b..69f3a2d40 100644 --- a/PlotsBase/test/test_unitful.jl +++ b/PlotsBase/test/test_unitful.jl @@ -227,7 +227,8 @@ end @test plot(x * m, y * s, z * (m / s), yunit = u"ks") isa PlotsBase.Plot @test plot(x * m, y * s, z * (m / s), zlabel = "z") isa PlotsBase.Plot @test plot(x * m, y * s, z * (m / s), zlims = (-1, 1)) isa PlotsBase.Plot - @test plot(x * m, y * s, z * (m / s), zlims = (-1, 1) .* (m / s)) isa PlotsBase.Plot + @test plot(x * m, y * s, z * (m / s), zlims = (-1, 1) .* (m / s)) isa + PlotsBase.Plot @test plot(x * m, y * s, z * (m / s), zunit = u"km/hr") isa PlotsBase.Plot @test plot(x * m, y * s, z * (m / s), zticks = (1:2) * m / s) isa PlotsBase.Plot @test scatter(x * m, y * s, z * (m / s)) isa PlotsBase.Plot diff --git a/Project.toml b/Project.toml index c848b10c6..430295e24 100644 --- a/Project.toml +++ b/Project.toml @@ -21,8 +21,9 @@ Reexport = "0.2, 1" julia = "1.6" [extras] +PythonPlot = "274fc56d-3b97-40fa-a1cd-1b4a50311bf9" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" UnicodePlots = "b8865327-cd53-5732-bb35-84acbb429228" [targets] -test = ["Test", "UnicodePlots"] +test = ["PythonPlot", "Test", "UnicodePlots"] diff --git a/src/Plots.jl b/src/Plots.jl index 6ff382e73..3d9c6e9f6 100644 --- a/src/Plots.jl +++ b/src/Plots.jl @@ -1,116 +1,121 @@ module Plots - using PrecompileTools - using Preferences - using Reexport - using Pkg - @reexport using PlotsBase +using PrecompileTools +using Preferences +using Reexport +using Pkg +@reexport using PlotsBase - function __init__() - ccall(:jl_generating_output, Cint, ()) == 1 && return - load_default_backend() - end +function __init__() + ccall(:jl_generating_output, Cint, ()) == 1 && return + load_default_backend() +end - # from github.com/JuliaPackaging/Preferences.jl/blob/master/README.md: - # "Preferences that are accessed during compilation are automatically marked as compile-time preferences" - # ==> this must always be done during precompilation, otherwise - # the cache will not invalidate when preferences change - const PLOTS_DEFAULT_BACKEND = lowercase(load_preference(Plots, "default_backend", "gr")) +# from github.com/JuliaPackaging/Preferences.jl/blob/master/README.md: +# "Preferences that are accessed during compilation are automatically marked as compile-time preferences" +# ==> this must always be done during precompilation, otherwise +# the cache will not invalidate when preferences change +const PLOTS_DEFAULT_BACKEND = lowercase(load_preference(Plots, "default_backend", "gr")) - function load_default_backend() - # environment variable preempts the `Preferences` based mechanism - PlotsBase.CURRENT_BACKEND.sym = - get(ENV, "PLOTS_DEFAULT_BACKEND", PLOTS_DEFAULT_BACKEND) |> lowercase |> Symbol - if (pkg_name = PlotsBase.backend_package_name()) ≡ :GR - @eval import GR - end - Base.invokelatest(PlotsBase.backend, PlotsBase.CURRENT_BACKEND.sym) +function load_default_backend() + # environment variable preempts the `Preferences` based mechanism + PlotsBase.CURRENT_BACKEND.sym = + get(ENV, "PLOTS_DEFAULT_BACKEND", PLOTS_DEFAULT_BACKEND) |> lowercase |> Symbol + if (pkg_name = PlotsBase.backend_package_name()) ≡ :GR + @eval import GR end + Base.invokelatest(PlotsBase.backend, PlotsBase.CURRENT_BACKEND.sym) +end - function set_default_backend!( - backend::Union{Nothing,AbstractString,Symbol} = nothing; - force = true, - kw..., - ) - if backend ≡ nothing - delete_preferences!(Plots, "default_backend"; force, kw...) - else - # NOTE: `_check_installed` already throws a warning - if (value = lowercase(string(backend))) |> PlotsBase._check_installed ≢ nothing - set_preferences!(Plots, "default_backend" => value; force, kw...) - end +function set_default_backend!( + backend::Union{Nothing,AbstractString,Symbol} = nothing; + force = true, + kw..., +) + if backend ≡ nothing + delete_preferences!(Plots, "default_backend"; force, kw...) + else + # NOTE: `_check_installed` already throws a warning + if (value = lowercase(string(backend))) |> PlotsBase._check_installed ≢ nothing + set_preferences!(Plots, "default_backend" => value; force, kw...) end - nothing end + nothing +end - function diagnostics(io::IO = stdout) - origin = if has_preference(Plots, "default_backend") - "`Preferences`" - elseif haskey(ENV, "PLOTS_DEFAULT_BACKEND") - "environment variable" - else - "fallback" - end - if (be = backend_name()) ≡ :none - @info "no `Plots` backends currently initialized" - else - be_name = string(PlotsBase.backend_package_name(be)) - @info "selected `Plots` backend: $be_name, from $origin" - Pkg.status( - ["Plots", "PlotsBase", "RecipesBase", "RecipesPipeline", be_name]; - mode = Pkg.PKGMODE_MANIFEST, - io, - ) - end - nothing +function diagnostics(io::IO = stdout) + origin = if has_preference(Plots, "default_backend") + "`Preferences`" + elseif haskey(ENV, "PLOTS_DEFAULT_BACKEND") + "environment variable" + else + "fallback" + end + if (be = backend_name()) ≡ :none + @info "no `Plots` backends currently initialized" + else + be_name = string(PlotsBase.backend_package_name(be)) + @info "selected `Plots` backend: $be_name, from $origin" + Pkg.status( + ["Plots", "PlotsBase", "RecipesBase", "RecipesPipeline", be_name]; + mode = Pkg.PKGMODE_MANIFEST, + io, + ) end + nothing +end - # COV_EXCL_START - @setup_workload begin - load_default_backend() - @debug PlotsBase.backend_package_name() - n = length(PlotsBase._examples) - imports = sizehint!(Expr[], n) - examples = sizehint!(Expr[], 10n) - scratch_dir = mktempdir() - for i in setdiff(1:n, PlotsBase._backend_skips[backend_name()], PlotsBase._animation_examples) - PlotsBase._examples[i].external && continue - (imp = PlotsBase._examples[i].imports) ≡ nothing || push!(imports, PlotsBase.replace_module(imp)) - func = gensym(string(i)) - push!( - examples, - quote - $func() = begin # evaluate each example in a local scope - $(PlotsBase._examples[i].exprs) - $i == 1 || return # only for one example - fn = joinpath(scratch_dir, tempname()) - pl = current() - 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") - if showable(MIME"image/svg+xml"(), pl) - show(IOBuffer(), MIME"image/svg+xml"(), pl) - end - nothing - end - $func() - end, - ) - end - withenv("GKSwstype" => "nul") do - @compile_workload begin - load_default_backend() - eval.(imports) - eval.(examples) - end +# COV_EXCL_START +@setup_workload begin + load_default_backend() + @debug PlotsBase.backend_package_name() + n = length(PlotsBase._examples) + imports = sizehint!(Expr[], n) + examples = sizehint!(Expr[], 10n) + scratch_dir = mktempdir() + for i in setdiff( + 1:n, + PlotsBase._backend_skips[backend_name()], + PlotsBase._animation_examples, + ) + PlotsBase._examples[i].external && continue + (imp = PlotsBase._examples[i].imports) ≡ nothing || + push!(imports, PlotsBase.replace_module(imp)) + func = gensym(string(i)) + push!( + examples, + quote + $func() = begin # evaluate each example in a local scope + $(PlotsBase._examples[i].exprs) + $i == 1 || return # only for one example + fn = joinpath(scratch_dir, tempname()) + pl = current() + 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") + if showable(MIME"image/svg+xml"(), pl) + show(IOBuffer(), MIME"image/svg+xml"(), pl) + end + nothing + end + $func() + end, + ) + end + withenv("GKSwstype" => "nul") do + @compile_workload begin + load_default_backend() + eval.(imports) + eval.(examples) end - PlotsBase.CURRENT_PLOT.nullableplot = nothing end - # COV_EXCL_STOP + PlotsBase.CURRENT_PLOT.nullableplot = nothing +end +# COV_EXCL_STOP end diff --git a/test/preferences.jl b/test/preferences.jl index 691666189..8178cd85b 100644 --- a/test/preferences.jl +++ b/test/preferences.jl @@ -11,7 +11,8 @@ withenv("PLOTS_DEFAULT_BACKEND" => "unicodeplots") do @test_logs (:info, r".*environment variable") Plots.diagnostics(devnull) - @test Plots.load_default_backend() == Base.get_extension(PlotsBase, :UnicodePlotsExt).UnicodePlotsBackend() + @test Plots.load_default_backend() == + Base.get_extension(PlotsBase, :UnicodePlotsExt).UnicodePlotsBackend() end @test Plots.load_default_backend() == Base.get_extension(PlotsBase, :GRExt).GRBackend() @@ -42,7 +43,7 @@ @test_logs (:info, r".*Preferences") Plots.diagnostics(io) @test backend() == Base.get_extension(PlotsBase, :UnicodePlotsExt).UnicodePlotsBackend() end - exit(res.n_passed == 2 ? 0 : 1) + exit(res.n_passed == 2 ? 0 : 123) """, ) @test success(run(```$(Base.julia_cmd()) $script```)) @@ -55,7 +56,17 @@ @test_logs Plots.set_default_backend!(be) # test the absence of warnings rm.(Base.find_all_in_cache_path(Base.module_keys[Plots])) # make sure the compiled cache is removed script = tempname() - write(script, "import :$pkg; using Test, Plots; @test Plots.backend_name() ≡ :$be") + write( + script, + """ + import $pkg + using Test, Plots + res = @testset "Backends" begin + @test Plots.backend_name() ≡ :$be + end + exit(res.n_passed == 1 ? 0 : 123) + """, + ) @test success(run(```$(Base.julia_cmd()) $script```)) # test default precompilation end diff --git a/test/runtests.jl b/test/runtests.jl index 746b56f41..054a40117 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,4 +1,5 @@ -const TEST_PACKAGES = strip.(split(get(ENV, "PLOTS_TEST_PACKAGES", "GR,UnicodePlots"), ",")) +const TEST_PACKAGES = + strip.(split(get(ENV, "PLOTS_TEST_PACKAGES", "GR,UnicodePlots,PythonPlot"), ",")) using PlotsBase # initialize all backends