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

Axis attributes when drawing pagination #595

Merged
merged 3 commits into from
Jan 31, 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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## v0.9.1 - 2025-01-31

- Fixed passing `axis` keyword to `draw(::Pagination, ...)` [#595](https://github.com/MakieOrg/AlgebraOfGraphics.jl/pull/595).

## v0.9.0 - 2025-01-30

- **Breaking**: `paginate` now splits facet plots into pages _after_ fitting scales and not _before_ [#593](https://github.com/MakieOrg/AlgebraOfGraphics.jl/pull/593). This means that, e.g., categorical color mappings are consistent across pages where before each page could have a different mapping if some groups were not represented on a given page. This change also makes pagination work with the split X and Y scales feature enabled by version 0.8.14. `paginate`'s return type changes from `PaginatedLayers` to `Pagination` because no layers are stored in that type anymore. The interface to use `Pagination` with `draw` and other functions doesn't change compared to `PaginatedLayers`. `paginate` now also accepts an optional second positional argument which are the scales that are normally passed to `draw` when not paginating, but which must be available prior to pagination to fit all scales accordingly.
Expand Down
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", "Julius Krumbiegel"]
version = "0.9.0"
version = "0.9.1"

[deps]
Accessors = "7d9f7c33-5ae7-4f3b-8dc6-eff91059b697"
Expand Down
11 changes: 10 additions & 1 deletion src/draw.jl
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,16 @@ function _draw(d::AbstractDrawable, scales::Scales;
ae = compute_axes_grid(d, scales; axis)
_draw(ae; figure, facet, legend, colorbar)
end
function _draw(ae::Matrix{AxisSpecEntries}; figure = (;), facet = (;), legend = (;), colorbar = (;))

function _draw(ae::Matrix{AxisSpecEntries}; axis = Dictionary{Symbol,Any}(), figure = Dictionary{Symbol,Any}(), facet = Dictionary{Symbol,Any}(), legend = Dictionary{Symbol,Any}(), colorbar = Dictionary{Symbol,Any}())

if !isempty(axis)
# merge in axis attributes here because pagination runs `compute_axes_grid`
# which in the normal `draw` pipeline consumes `axis`
ae = map(ae) do ase
Accessors.@set ase.axis.attributes = merge(ase.axis.attributes, axis)
end
end

fs, remaining_figure_kw = figure_settings(; pairs(figure)...)

Expand Down
18 changes: 15 additions & 3 deletions src/paginate.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,14 @@ end
Draw each element of `Pagination` `p` and return a `Vector{FigureGrid}`.
Keywords `kws` are passed to the underlying `draw` calls.
"""
draw(p::Pagination; kws...) = _draw.(p.each; kws...)
function draw(p::Pagination; axis = (;), figure = (;), facet = (;), legend = (;), colorbar = (;))
axis = _kwdict(axis)
figure = _kwdict(figure)
facet = _kwdict(facet)
legend = _kwdict(legend)
colorbar = _kwdict(colorbar)
_draw.(p.each; axis, figure, facet, legend, colorbar)
end

"""
draw(p::Pagination, i::Int; kws...)
Expand All @@ -36,11 +43,16 @@ Keywords `kws` are passed to the underlying `draw` call.

You can retrieve the number of elements using `length(p)`.
"""
function draw(p::Pagination, i::Int; kws...)
function draw(p::Pagination, i::Int; axis = (;), figure = (;), facet = (;), legend = (;), colorbar = (;))
if i ∉ 1:length(p)
throw(ArgumentError("Invalid index $i for Pagination with $(length(p)) entries."))
end
_draw(p.each[i]; kws...)
axis = _kwdict(axis)
figure = _kwdict(figure)
facet = _kwdict(facet)
legend = _kwdict(legend)
colorbar = _kwdict(colorbar)
_draw(p.each[i]; axis, figure, facet, legend, colorbar)
end

function draw(p::Pagination, ::Scales, args...; kws...)
Expand Down
14 changes: 13 additions & 1 deletion test/paginate.jl
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,16 @@ end
@test only(AlgebraOfGraphics.datavalues(cat2)) == "A"

@test_throws_message "Calling `draw` with a `Pagination` object and `scales` is invalid." draw(p, scl)
end
end

@testset "Axis attributes when drawing pagination" begin
spec = data((; x = 1:10, y = 11:20, group = repeat(["A", "B"]))) * mapping(:x, :y, layout = :group)
p = paginate(spec, layout = 1)
fgrid = draw(p, 1; axis = (; xlabelcolor = :tomato))
ax = only(fgrid.grid).axis
@test ax.xlabelcolor[] == Makie.to_color(:tomato)

fgrids = draw(p; axis = (; xlabelcolor = :tomato))
ax = only(fgrids[1].grid).axis
@test ax.xlabelcolor[] == Makie.to_color(:tomato)
end
Loading