Skip to content

Commit

Permalink
facet labels also inherit visible from title (#350)
Browse files Browse the repository at this point in the history
  • Loading branch information
piever authored Feb 16, 2022
1 parent 5c42bcb commit 9b08603
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "AlgebraOfGraphics"
uuid = "cbdf2221-f076-402e-a563-3d30da359d67"
authors = ["Pietro Vertechi <[email protected]>"]
version = "0.6.4"
version = "0.6.5"

[deps]
Colors = "5ae59095-9a9b-59fe-a467-6f913c188581"
Expand Down
25 changes: 15 additions & 10 deletions src/facet.jl
Original file line number Diff line number Diff line change
Expand Up @@ -37,28 +37,30 @@ end
## Label computation and layout

# facet labels
function labels!(fig, aes, scale, dir)
function facet_labels!(fig, aes, scale, dir)
# reference axis to extract attributes
ax = first(nonemptyaxes(aes))
color = ax.titlecolor
font = ax.titlefont
textsize = ax.titlesize
visible = ax.titlevisible

padding_index = dir == :row ? 1 : 3
facetlabelpadding = lift(ax.titlegap) do gap
padding = lift(ax.titlegap) do gap
return ntuple(i -> i == padding_index ? gap : 0f0, 4)
end

return map(plotvalues(scale), datavalues(scale)) do index, label
rotation = dir == :row ? -π/2 : 0.0
figpos = dir == :col ? fig[1, index, Top()] : dir == :row ? fig[index, size(aes, 2), Right()] : fig[index..., Top()]
Label(figpos, to_string(label); rotation, padding=facetlabelpadding, color, font, textsize)
figpos = dir == :col ? fig[1, index, Top()] :
dir == :row ? fig[index, size(aes, 2), Right()] : fig[index..., Top()]
return Label(figpos, to_string(label); rotation, padding, color, font, textsize, visible)
end
end

col_labels!(fig, aes, scale) = labels!(fig, aes, scale, :col)
row_labels!(fig, aes, scale) = labels!(fig, aes, scale, :row)
panel_labels!(fig, aes, scale) = labels!(fig, aes, scale, :layout)
col_labels!(fig, aes, scale) = facet_labels!(fig, aes, scale, :col)
row_labels!(fig, aes, scale) = facet_labels!(fig, aes, scale, :row)
panel_labels!(fig, aes, scale) = facet_labels!(fig, aes, scale, :layout)

# Consistent axis labels

Expand Down Expand Up @@ -86,7 +88,8 @@ function span_label!(fig, aes, var)
pos = var == :x ? (size(aes, 1), :) : (:, 1)
index, side, Side = var == :x ? (4, :bottom, Bottom) : (2, :left, Left)

padding = lift(getattr(ax, :labelpadding), (protrusionsobservable(ae.axis) for ae in aes[pos...])...) do p, xs...
protrusions = (protrusionsobservable(ae.axis) for ae in aes[pos...])
padding = lift(getattr(ax, :labelpadding), protrusions...) do p, xs...
protrusion = maximum(x -> getproperty(x, side), xs)
return ntuple(i -> i == index ? protrusion + p : 0f0, 4)
end
Expand Down Expand Up @@ -211,7 +214,8 @@ end
hide_xdecorations!(ax) = hidexdecorations!(ax; grid=false, minorgrid=false)
hide_ydecorations!(ax) = hideydecorations!(ax; grid=false, minorgrid=false)

function hideinnerdecorations!(aes::AbstractArray{AxisEntries}; hidexdecorations, hideydecorations, wrap)
function hideinnerdecorations!(aes::AbstractArray{AxisEntries};
hidexdecorations, hideydecorations, wrap)
I, J = size(aes)

if hideydecorations
Expand All @@ -223,7 +227,8 @@ function hideinnerdecorations!(aes::AbstractArray{AxisEntries}; hidexdecorations
if hidexdecorations
for i in 1:I-1, j in 1:J
if wrap && isempty(aes[i+1,j].entries)
# In facet_wrap, don't hide x decorations if axis below is empty, but instead improve alignment.
# In facet_wrap, don't hide x decorations if axis below is empty,
# but instead improve alignment.
aes[i,j].axis.alignmode = Mixed(bottom=Protrusion(0))
else
hide_xdecorations!(aes[i,j])
Expand Down

2 comments on commit 9b08603

@piever
Copy link
Collaborator Author

@piever piever commented on 9b08603 Feb 16, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register()

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/54779

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.6.5 -m "<description of version>" 9b08603c02c86ba3ba38677ee63318d1d3f7d740
git push origin v0.6.5

Please sign in to comment.