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

fix pkg extension #90

Merged
merged 8 commits into from
Nov 24, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ Makie = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a"
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"

[extensions]
PlottingCairoMakieExt = "CairoMakie"
PlottingMakieExt = "Makie"
PlottingPlotsExt = "Plots"
FHistCairoMakieExt = "CairoMakie"
FHistMakieExt = "Makie"
FHistPlotsExt = "Plots"

[compat]
BayesHistogram = "1.0.7"
Expand Down
1 change: 1 addition & 0 deletions docs/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
CairoMakie = "13f3f980-e62b-5c42-98c6-ff1f3baf88f0"
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
FHist = "68837c9b-b678-4cd5-9925-8a54edc8f695"
Makie = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a"
Pluto = "c3e4b0f8-55cb-11ea-2926-15256bba5781"
PlutoStaticHTML = "359b1769-a58e-495b-9770-312e911026ad"
3 changes: 2 additions & 1 deletion docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ makedocs(;
modules=[FHist],
format = Documenter.HTML(
prettyurls = get(ENV, "CI", nothing) == "true",
size_threshold = 5*10^6
# assets = ["assets/logo.ico"],
),
pages=[
Expand All @@ -26,7 +27,7 @@ makedocs(;
],
repo="https://github.com/Moelf/FHist.jl/blob/{commit}{path}#L{line}",
sitename="FHist.jl",
authors="Jerry Ling",
authors="Jerry Ling"
)

deploydocs(;
Expand Down
19 changes: 13 additions & 6 deletions docs/src/notebooks/makie_plotting.jl
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ begin
p1, ax1= plot(fig[1, 1],h1; label = "plot(h1)")
p2, ax2 = stairs(fig[1, 2], h1, label = "stairs(h1)")
p3, ax3 = hist(fig[2, 1], h1, label = "hist(h1)")
p4, ax4 = errorbars(fig[2, 2], h1, whiskerwidth=6, label = "errorbars(h1)")
p4, ax4 = errorbars(fig[2, 2], h1, color=:black, whiskerwidth=6, label = "errorbars(h1)")
axislegend.([p1, p2, p3, p4])
fig
end
Expand Down Expand Up @@ -110,7 +110,7 @@ We also have a recipe for that:

# ╔═╡ 70a5ba34-53c5-4e12-93b9-49eace436524
with_theme(ATLASTHEME) do
f, a, p = stackedhist([h2, h2, h1 ]; errors=true) #errors defaults to `true`
f, a, p = stackedhist([h2, h2, h1 ])
labels = ["proc1", "blah", "third one"]
elements = [PolyElement(polycolor = p.attributes.color[][i]) for i in 1:length(labels)]
title = "Legend title"
Expand All @@ -136,10 +136,10 @@ with_theme(ATLASTHEME) do
errorbars!(a, h3)

axislegend()
ratioax = Axis(f_ratio[2, 1], aspect = 5.5, xlabel = "my x-axis", ylabel="h11/ h3")
ratioax = Axis(f_ratio[2, 1], aspect = 5.5, xlabel = "my x-axis", ylabel="h1 / h3")
linkxaxes!(ratioax, a)
hidexdecorations!(a)
ratiohist!(ratioax, h1/h3; errors=true)
ratiohist!(ratioax, h1/h3; color=:black, errors=true)
rowsize!(f_ratio.layout, 1, Aspect(1, 0.5))
f_ratio
end
Expand All @@ -165,15 +165,21 @@ begin
end

# ╔═╡ b114c8a7-5f01-44fe-9660-b5021d359399
with_theme(ATLASTHEME) do
f, a, p = stackedhist([h1, h1 ]; error_color=Pattern('/'))
let
f, a, p = stackedhist([h1, h1 ]; error_color=(:black, 0.5))
labels = ["proc1", "blah"]
elements = [PolyElement(polycolor = p.attributes.color[][i]) for i in 1:length(labels)]
title = "Legend title"
Legend(f[1,2], elements, labels, title)
f
end

# ╔═╡ fae56f0f-bac4-4dea-b33c-d45e6f3b51fc
let
f, a, p = stackedhist([h1, h1 ]; error_color=Pattern('/'))
f
end

# ╔═╡ Cell order:
# ╠═4cf8f502-eba2-11ec-275f-3f1858e4c2e6
# ╠═82a6fb18-e9c9-450d-9c93-e05bd6cf5859
Expand All @@ -195,3 +201,4 @@ end
# ╟─2f97d05b-9103-451e-8fce-bb7458acf2ba
# ╠═f120fa84-6d27-4561-a8d0-fb619c94c490
# ╠═b114c8a7-5f01-44fe-9660-b5021d359399
# ╠═fae56f0f-bac4-4dea-b33c-d45e6f3b51fc
16 changes: 16 additions & 0 deletions ext/FHistCairoMakieExt.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module FHistCairoMakieExt
#using .CairoMakie

# isdefined(Base, :get_extension) ? (using CairoMakie) : (using ..CairoMakie)

#FIXME remove piracy
# function CairoMakie.Cairo.CairoPattern(color::Makie.AbstractPattern)
# # the Cairo y-coordinate are fliped
# color_matrix = replace!(Makie.to_image(color), Makie.RGBA{Float32}(1.0f0,1.0f0,1.0f0,0.0f0) => Makie.RGBA{Float32}(0.0f0,0.0f0,0.0f0,0.0f0))
# bitmappattern = reverse!(Makie.ARGB32.(color_matrix); dims=2)
# cairoimage = CairoMakie.Cairo.CairoImageSurface(bitmappattern)
# cairopattern = CairoMakie.Cairo.CairoPattern(cairoimage)
# return cairopattern
# end
end

57 changes: 20 additions & 37 deletions src/makie.jl → ext/FHistMakieExt.jl
Original file line number Diff line number Diff line change
@@ -1,36 +1,10 @@
module PlottingMakieExt
module FHistMakieExt
using FHist, FHist.Measurements
#using .Makie
using RecipesBase, Statistics
using MakieCore, Statistics
isdefined(Base, :get_extension) ? (using Makie) : (using ..Makie)

"""

## Example
```
with_theme(ATLASTHEME) do
h1 = Hist1D(randn(10^4))
hist(h1; label="atlas style histogram")
end
```
"""
const ATLASTHEME =
Theme(
Axis = (
xtickalign=1, ytickalign=1,
xticksmirrored=1, yticksmirrored=1,
xminortickalign=1, yminortickalign=1,
xticksize=10, yticksize=10,
xminorticksize=6, yminorticksize=6,
xgridvisible = false, ygridvisible = false,
xminorticksvisible = true, yminorticksvisible = true,
limits = (nothing, nothing, 0, nothing),
),
Colorbar = (
colormap = :haline,
highclip = :red,
lowclip = :black
)
)
import FHist: stackedhist, stackedhist!

"""
stackedhist(hs:AbstractVector{<:Hist1D}; errors=true|:bar|:shade, color=Makie.wong_colors())
Expand Down Expand Up @@ -100,6 +74,13 @@
input
end

import FHist: ratiohist, ratiohist!

"""
ratiohist(h::Hist1D; color=:black, errors=true)

Plot a histogram that represents a ratio (i.e. `h = h1/h3`), you can pass `color` to fix the error bar colors, and use `error` to turn on or off the error bars in the ratio plot.
"""
@recipe(RatioHist) do scene
Attributes(
errors = true,
Expand All @@ -112,9 +93,11 @@
xs = bincenters(hratio)
ys = bincounts(hratio)

scatter!(input, xs, ys)
color = input[:color][]

Check warning on line 96 in ext/FHistMakieExt.jl

View check run for this annotation

Codecov / codecov/patch

ext/FHistMakieExt.jl#L96

Added line #L96 was not covered by tests

scatter!(input, xs, ys; color=color)

Check warning on line 98 in ext/FHistMakieExt.jl

View check run for this annotation

Codecov / codecov/patch

ext/FHistMakieExt.jl#L98

Added line #L98 was not covered by tests
if input[:errors][]
errorbars!(input, xs, ys, binerrors(hratio); whiskerwidth=input[:whiskerwidth][])
errorbars!(input, xs, ys, binerrors(hratio); color=color, whiskerwidth=input[:whiskerwidth][])

Check warning on line 100 in ext/FHistMakieExt.jl

View check run for this annotation

Codecov / codecov/patch

ext/FHistMakieExt.jl#L100

Added line #L100 was not covered by tests
end
hlines!(input, 1; color=RGBf(0.2,0.2,0.2), linestyle=:dashdot)
input
Expand Down Expand Up @@ -160,12 +143,12 @@
statbox!(afp, h1)
```
"""
function statbox!(fig::Makie.FigureAxisPlot, h; position = (1,2))
function FHist.statbox!(fig::Makie.FigureAxisPlot, h; position = (1,2))

Check warning on line 146 in ext/FHistMakieExt.jl

View check run for this annotation

Codecov / codecov/patch

ext/FHistMakieExt.jl#L146

Added line #L146 was not covered by tests
f, _, _ = fig
statbox!(f, h; position)
fig
end
function statbox!(fig::Makie.Figure, h::Hist1D; position = (1,2))
function FHist.statbox!(fig::Makie.Figure, h::Hist1D; position = (1,2))

Check warning on line 151 in ext/FHistMakieExt.jl

View check run for this annotation

Codecov / codecov/patch

ext/FHistMakieExt.jl#L151

Added line #L151 was not covered by tests
N = nentries(h)
M = round(mean(h); sigdigits= 2)
S = round(std(h); sigdigits= 2)
Expand All @@ -174,7 +157,7 @@
Legend(getindex(fig, position...), elements, labels)
fig
end
function statbox!(fig::Makie.Figure, h::Hist2D; position = (1,2))
function FHist.statbox!(fig::Makie.Figure, h::Hist2D; position = (1,2))

Check warning on line 160 in ext/FHistMakieExt.jl

View check run for this annotation

Codecov / codecov/patch

ext/FHistMakieExt.jl#L160

Added line #L160 was not covered by tests
N = nentries(h)
xM, yM = round.(mean(h); sigdigits= 2)
xS, yS = round.(std(h); sigdigits= 2)
Expand Down Expand Up @@ -206,7 +189,7 @@
fig
end
"""
function collabtext!(axis, colabname = "ATLAS", stage = "Preliminary"; position=:lt)
function FHist.collabtext!(axis, colabname = "ATLAS", stage = "Preliminary"; position=:lt)

Check warning on line 192 in ext/FHistMakieExt.jl

View check run for this annotation

Codecov / codecov/patch

ext/FHistMakieExt.jl#L192

Added line #L192 was not covered by tests
relative_projection = Makie.camrelative(axis.scene);
pos = if position isa Symbol
length(String(position)) != 2 && throw("`position` must be length == 2, support `lt` or `rt`")
Expand All @@ -218,4 +201,4 @@
font=[fill("TeX Gyre Heros Bold Italic Makie", length(colabname)); fill("TeX Gyre Heros Makie", length(stage)+1)]
)
end
end
end
2 changes: 1 addition & 1 deletion src/plots.jl → ext/FHistPlotsExt.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module PlottingPlotsExt
module FHistPlotsExt
using RecipesBase, Statistics

isdefined(Base, :get_extension) ? (using Plots) : (using ..Plots)
Expand Down
21 changes: 17 additions & 4 deletions src/FHist.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export atomic_push!

export Hist2D, project, profile, transpose

export Hist3D, collabtext!, statbox!, ATLASTHEME, stackedhist
export Hist3D, collabtext!, statbox!

using StatsBase, Statistics, Measurements
export Weights
Expand Down Expand Up @@ -45,12 +45,25 @@ include("./displays.jl")
include("./arithmatics.jl")
nentries(h::Union{Hist1D, Hist2D, Hist3D}) = h.nentries[]

using MakieCore
include("./MakieThemes.jl")
export ATLASTHEME, stackedhist, stackedhist!, ratiohist, ratiohist!

function stackedhist end
function stackedhist! end

function ratiohist end
function ratiohist! end

function statbox! end
function collabtext! end

function __init__()

@static if !isdefined(Base, :get_extension)
@require Plots="91a5bcdd-55d7-5caf-9e0b-520d859cae80" include("./plots.jl")
@require Makie="ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a" include("./makie.jl")
@require CairoMakie="13f3f980-e62b-5c42-98c6-ff1f3baf88f0" include("./cairomakie.jl")
@require Plots="91a5bcdd-55d7-5caf-9e0b-520d859cae80" include("../ext/FHistPlotsExt.jl")
@require Makie="ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a" include("../ext/FHistMakieExt.jl")
@require CairoMakie="13f3f980-e62b-5c42-98c6-ff1f3baf88f0" include("../ext/FHistCairoMakieExt.jl")
end

end
Expand Down
27 changes: 27 additions & 0 deletions src/MakieThemes.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
"""

## Example
```
with_theme(ATLASTHEME) do
h1 = Hist1D(randn(10^4))
hist(h1; label="atlas style histogram")
end
```
"""
const ATLASTHEME = MakieCore.Attributes(
Axis = (
xtickalign=1, ytickalign=1,
xticksmirrored=1, yticksmirrored=1,
xminortickalign=1, yminortickalign=1,
xticksize=10, yticksize=10,
xminorticksize=6, yminorticksize=6,
xgridvisible = false, ygridvisible = false,
xminorticksvisible = true, yminorticksvisible = true,
limits = (nothing, nothing, 0, nothing),
),
Colorbar = (
colormap = :haline,
highclip = :red,
lowclip = :black
)
)
16 changes: 0 additions & 16 deletions src/cairomakie.jl

This file was deleted.