Skip to content

Commit 636d518

Browse files
authored
Axis attributes when drawing pagination (#595)
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.
1 parent 3caab7d commit 636d518

File tree

5 files changed

+43
-6
lines changed

5 files changed

+43
-6
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## v0.9.1 - 2025-01-31
4+
5+
- Fixed passing `axis` keyword to `draw(::Pagination, ...)` [#595](https://github.com/MakieOrg/AlgebraOfGraphics.jl/pull/595).
6+
37
## v0.9.0 - 2025-01-30
48

59
- **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.

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "AlgebraOfGraphics"
22
uuid = "cbdf2221-f076-402e-a563-3d30da359d67"
33
authors = ["Pietro Vertechi", "Julius Krumbiegel"]
4-
version = "0.9.0"
4+
version = "0.9.1"
55

66
[deps]
77
Accessors = "7d9f7c33-5ae7-4f3b-8dc6-eff91059b697"

src/draw.jl

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,16 @@ function _draw(d::AbstractDrawable, scales::Scales;
157157
ae = compute_axes_grid(d, scales; axis)
158158
_draw(ae; figure, facet, legend, colorbar)
159159
end
160-
function _draw(ae::Matrix{AxisSpecEntries}; figure = (;), facet = (;), legend = (;), colorbar = (;))
160+
161+
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}())
162+
163+
if !isempty(axis)
164+
# merge in axis attributes here because pagination runs `compute_axes_grid`
165+
# which in the normal `draw` pipeline consumes `axis`
166+
ae = map(ae) do ase
167+
Accessors.@set ase.axis.attributes = merge(ase.axis.attributes, axis)
168+
end
169+
end
161170

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

src/paginate.jl

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,14 @@ end
2626
Draw each element of `Pagination` `p` and return a `Vector{FigureGrid}`.
2727
Keywords `kws` are passed to the underlying `draw` calls.
2828
"""
29-
draw(p::Pagination; kws...) = _draw.(p.each; kws...)
29+
function draw(p::Pagination; axis = (;), figure = (;), facet = (;), legend = (;), colorbar = (;))
30+
axis = _kwdict(axis)
31+
figure = _kwdict(figure)
32+
facet = _kwdict(facet)
33+
legend = _kwdict(legend)
34+
colorbar = _kwdict(colorbar)
35+
_draw.(p.each; axis, figure, facet, legend, colorbar)
36+
end
3037

3138
"""
3239
draw(p::Pagination, i::Int; kws...)
@@ -36,11 +43,16 @@ Keywords `kws` are passed to the underlying `draw` call.
3643
3744
You can retrieve the number of elements using `length(p)`.
3845
"""
39-
function draw(p::Pagination, i::Int; kws...)
46+
function draw(p::Pagination, i::Int; axis = (;), figure = (;), facet = (;), legend = (;), colorbar = (;))
4047
if i 1:length(p)
4148
throw(ArgumentError("Invalid index $i for Pagination with $(length(p)) entries."))
4249
end
43-
_draw(p.each[i]; kws...)
50+
axis = _kwdict(axis)
51+
figure = _kwdict(figure)
52+
facet = _kwdict(facet)
53+
legend = _kwdict(legend)
54+
colorbar = _kwdict(colorbar)
55+
_draw(p.each[i]; axis, figure, facet, legend, colorbar)
4456
end
4557

4658
function draw(p::Pagination, ::Scales, args...; kws...)

test/paginate.jl

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,4 +77,16 @@ end
7777
@test only(AlgebraOfGraphics.datavalues(cat2)) == "A"
7878

7979
@test_throws_message "Calling `draw` with a `Pagination` object and `scales` is invalid." draw(p, scl)
80-
end
80+
end
81+
82+
@testset "Axis attributes when drawing pagination" begin
83+
spec = data((; x = 1:10, y = 11:20, group = repeat(["A", "B"]))) * mapping(:x, :y, layout = :group)
84+
p = paginate(spec, layout = 1)
85+
fgrid = draw(p, 1; axis = (; xlabelcolor = :tomato))
86+
ax = only(fgrid.grid).axis
87+
@test ax.xlabelcolor[] == Makie.to_color(:tomato)
88+
89+
fgrids = draw(p; axis = (; xlabelcolor = :tomato))
90+
ax = only(fgrids[1].grid).axis
91+
@test ax.xlabelcolor[] == Makie.to_color(:tomato)
92+
end

0 commit comments

Comments
 (0)