Skip to content

Commit

Permalink
Singleargustrip (JuliaPlots#4752)
Browse files Browse the repository at this point in the history
* Test

* Remove single arg _ustrips from annotate

* Formatting
  • Loading branch information
gustaphe authored May 26, 2023
1 parent 0b3015d commit 289e373
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
27 changes: 21 additions & 6 deletions ext/UnitfulExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -287,21 +287,36 @@ getaxisunit(a::Axis) = getaxisunit(a[:guide])
#==============
Fix annotations
===============#
Plots.locate_annotation(
function Plots.locate_annotation(
sp::Subplot,
x::MissingOrQuantity,
y::MissingOrQuantity,
label::PlotText,
) = (_ustrip(x), _ustrip(y), label)
Plots.locate_annotation(
)
xunit = getaxisunit(sp.attr[:xaxis])
yunit = getaxisunit(sp.attr[:yaxis])
(_ustrip(xunit, x), _ustrip(yunit, y), label)
end
function Plots.locate_annotation(
sp::Subplot,
x::MissingOrQuantity,
y::MissingOrQuantity,
z::MissingOrQuantity,
label::PlotText,
) = (_ustrip(x), _ustrip(y), _ustrip(z), label)
Plots.locate_annotation(sp::Subplot, rel::NTuple{N,<:MissingOrQuantity}, label) where {N} =
Plots.locate_annotation(sp, _ustrip.(rel), label)
)
xunit = getaxisunit(sp.attr[:xaxis])
yunit = getaxisunit(sp.attr[:yaxis])
zunit = getaxisunit(sp.attr[:zaxis])
(_ustrip(xunit, x), _ustrip(yunit, y), _ustrip(zunit, z), label)
end
function Plots.locate_annotation(
sp::Subplot,
rel::NTuple{N,<:MissingOrQuantity},
label,
) where {N}
units = getaxisunit(sp.attr[:xaxis], sp.attr[:yaxis], sp.attr[:zaxis])
Plots.locate_annotation(sp, _ustrip.(zip(units, rel)), label)
end

#==================#
# ticks and limits #
Expand Down
3 changes: 2 additions & 1 deletion test/test_unitful.jl
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,8 @@ end
@testset "Annotate" begin
pl = plot([0, 1]u"s", [0, 1]u"m")
annotate!(pl, [0.25]u"s", [0.5]u"m", text("annotation"))
@test show(devnull, pl) isa Nothing
savefig(pl, testfile)
@test length(pl.subplots[1].attr[:annotations]) == 1
end

@testset "AbstractProtectedString" begin
Expand Down

0 comments on commit 289e373

Please sign in to comment.