Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add fallback method for lplot! #4

Merged
merged 2 commits into from
Feb 20, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
25 changes: 25 additions & 0 deletions ext/recipes/lplot.jl
Original file line number Diff line number Diff line change
Expand Up @@ -205,5 +205,30 @@
Makie.lines!(ax, com_report.energy, com_report.values, linewidth = 4, color = :red, linestyle = :dash, label = LaTeXStrings.latexstring("\\fontfamily{Roboto}" * com_report.label_fit))
Makie.axislegend(ax, position = legend_position)

fig
end


function LegendMakie.lplot!(args...; watermark::Bool = false, kwargs...)

fig = Makie.current_figure()

#create plot
ax = if !isnothing(Makie.current_axis())
Makie.current_axis()
else
Makie.Axis(fig[1,1],

Check warning on line 220 in ext/recipes/lplot.jl

View check run for this annotation

Codecov / codecov/patch

ext/recipes/lplot.jl#L220

Added line #L220 was not covered by tests
titlesize = 18,
titlegap = 1,
titlealign = :right
)
end

# use built-in method as fallback if existent, tweak appearance
Makie.plot!(args...; kwargs...)

# add watermarks
watermark && LegendMakie.add_watermarks!(; kwargs...)

fig
end
1 change: 1 addition & 0 deletions test/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
LegendSpecFits = "18221496-77af-46cf-bab8-820da09f7f97"
Makie = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a"
RadiationDetectorSignals = "bf2c0563-65cf-5db2-a620-ceb7de82658c"
StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
Unitful = "1986cc42-f94f-5a68-af5c-568840ba703d"

Expand Down
3 changes: 2 additions & 1 deletion test/test_lplot.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ using Makie

import LegendSpecFits
import Distributions
import StatsBase
import Unitful: @u_str

using Test
Expand All @@ -16,7 +17,7 @@ using Test

# test default watermark
ax = Axis(fig[1,1])
hist!(ax, randn(10000))
@test_nowarn lplot!(StatsBase.fit(StatsBase.Histogram, randn(10000)))
@test_nowarn LegendMakie.add_watermarks!()

# test alternative watermark
Expand Down