Skip to content

Commit

Permalink
format
Browse files Browse the repository at this point in the history
  • Loading branch information
t-bltg committed Apr 1, 2024
1 parent 6411638 commit a78d7db
Show file tree
Hide file tree
Showing 24 changed files with 256 additions and 155 deletions.
9 changes: 5 additions & 4 deletions PlotsBase/ext/GRExt.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
module GRExt


import PlotsBase: PlotsBase, _cycle
import RecipesPipeline
import NaNMath
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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.
Expand Down
8 changes: 4 additions & 4 deletions PlotsBase/ext/HDF5Ext.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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}()
Expand Down Expand Up @@ -620,5 +621,4 @@ end

hdf5plot_write(path::AbstractString) = hdf5plot_write(current(), path)


end # module
18 changes: 14 additions & 4 deletions PlotsBase/ext/PGFPlotsXExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down Expand Up @@ -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,
Expand Down
11 changes: 6 additions & 5 deletions PlotsBase/ext/PlotlyJSExt.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
module PlotlyJSExt


import PlotsBase: PlotsBase, Plot, isijulia
using PlotsBase.PlotsPlots
using PlotsBase.Commons
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down
27 changes: 21 additions & 6 deletions PlotsBase/ext/PythonPlotExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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()
Expand All @@ -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,
Expand Down
15 changes: 12 additions & 3 deletions PlotsBase/ext/UnicodePlotsExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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 |>
Expand Down Expand Up @@ -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
Expand Down
15 changes: 14 additions & 1 deletion PlotsBase/ext/UnitfulExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion PlotsBase/src/Commons/Commons.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion PlotsBase/src/PlotsBase.jl
Original file line number Diff line number Diff line change
Expand Up @@ -201,4 +201,4 @@ using .Plotly
include("init.jl")
include("users.jl")

end
end
3 changes: 2 additions & 1 deletion PlotsBase/src/Series.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
6 changes: 4 additions & 2 deletions PlotsBase/src/backends/plotly.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)

Expand Down
14 changes: 10 additions & 4 deletions PlotsBase/src/examples.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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)),
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion PlotsBase/src/utils.jl
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
12 changes: 11 additions & 1 deletion PlotsBase/test/runtests.jl
Original file line number Diff line number Diff line change
@@ -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
Expand Down
3 changes: 2 additions & 1 deletion PlotsBase/test/test_axes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
7 changes: 5 additions & 2 deletions PlotsBase/test/test_backends.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion PlotsBase/test/test_hdf5plots.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit a78d7db

Please sign in to comment.