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

Break mergeable up so that it's extensible #592

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

## Unreleased
- Breaks up `mergeable(::ProcessedLayer)` into `mergeable(layer.plottype, layer.primary)` for dispatch purposes. This should enable `mergeable` to be extended by other packages that define recipes [#592](https://github.com/MakieOrg/AlgebraOfGraphics.jl/pull/592).

## 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 Expand Up @@ -129,4 +132,4 @@
- **Breaking**: Analyses now require parentheses (i.e. `linear()` instead of `linear`).
- **Breaking**: Rename `layout_x` and `layout_y` to `col` and `row`.
- **Breaking**: Rename `wts` keyword argument to `weights`.
- **Breaking**: `categorical` has been replaced by `nonnumeric`.
- **Breaking**: `categorical` has been replaced by `nonnumeric`.
37 changes: 28 additions & 9 deletions src/algebra/layer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -425,18 +425,37 @@
# Determine whether entries from a `ProcessedLayer` should be merged
function mergeable(processedlayer::ProcessedLayer)
plottype, primary = processedlayer.plottype, processedlayer.primary
# merge violins for correct renormalization
plottype <: Violin && return true
# merge stacked or dodged barplots
plottype <: Union{BarPlot,CrossBar} && return true
# merge waterfall plots
plottype <: Waterfall && return true
# merge dodged boxplots
plottype <: BoxPlot && haskey(primary, :dodge) && return true
# do not merge by default
return mergeable(plottype, primary)
end

# Default fallback implementation
"""
mergeable(plottype::Type{<: Plot}, primary::Dictionaries.AbstractDictionary)::Bool

Return whether the entries for the layer with `plottype` and `primary` should be merged.
Merging means that all the data will be passed to a single plot call, instead of creating
one plot object per scale.

Return `true` if they **should** be merged, and `false` if **not** (the default).

Extending packages should also extend this function on their own plot types
if they deem it necessary. For example, beeswarm plots and violin plots
need to be merged for correctness.
"""
function mergeable(plottype::Type{<: Plot}, primary)
return false
end

# merge violins for correct renormalization
mergeable(::Type{<: Violin}, primary) = true
# merge stacked or dodged barplots
mergeable(::Type{<: Union{BarPlot, CrossBar}}, primary) = true
# merge waterfall plots
mergeable(::Type{<: Waterfall}, primary) = true

Check warning on line 454 in src/algebra/layer.jl

View check run for this annotation

Codecov / codecov/patch

src/algebra/layer.jl#L454

Added line #L454 was not covered by tests
# merge dodged boxplots
mergeable(::Type{<: BoxPlot}, primary) = haskey(primary, :dodge)


# This method works on a list of "sliced" `ProcessedLayer`s
function concatenate(pls::AbstractVector{ProcessedLayer})
pl = first(pls)
Expand Down
Loading