Skip to content

Commit

Permalink
Axis attributes when drawing pagination (#595)
Browse files Browse the repository at this point in the history
Doing `p = paginate(...); draw(p; axis = (; xlabelcolor = :red))` wasn't
working because `axis` is already consumed into `AxisSpecEntries` in the
normal pipeline. This PR fixes that by merging `axis` into the existing
specs.
  • Loading branch information
jkrumbiegel authored Jan 31, 2025
1 parent 3caab7d commit 636d518
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 6 deletions.
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

2 comments on commit 636d518

@jkrumbiegel
Copy link
Member Author

Choose a reason for hiding this comment

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

@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/124084

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

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.9.1 -m "<description of version>" 636d5184d9000267bd16a4745c62a156c052ce4e
git push origin v0.9.1

Please sign in to comment.