From 71652849997180b540f731bcfc162c264905b982 Mon Sep 17 00:00:00 2001 From: Anshul Singhvi Date: Mon, 27 Jan 2025 15:45:51 -0500 Subject: [PATCH 1/4] Break `mergeable` up so that it's extensible --- src/algebra/layer.jl | 37 ++++++++++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/src/algebra/layer.jl b/src/algebra/layer.jl index 230147446..9ed753d8b 100644 --- a/src/algebra/layer.jl +++ b/src/algebra/layer.jl @@ -422,18 +422,37 @@ end # 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::AbstractDict)::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::AbstractDict) 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 +# 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) From 985a6a663d3f15004132434eb663be4bc2644cee Mon Sep 17 00:00:00 2001 From: Anshul Singhvi Date: Mon, 27 Jan 2025 15:52:33 -0500 Subject: [PATCH 2/4] Update CHANGELOG.md --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e70186783..71434162d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ # 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 have recipes [#592](https://github.com/MakieOrg/AlgebraOfGraphics.jl/pull/592). ## v0.8.14 - 2025-01-16 @@ -127,4 +128,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`. \ No newline at end of file +- **Breaking**: `categorical` has been replaced by `nonnumeric`. From 9eca5c996704baf7f7b51a112d3609bf7e9ec76a Mon Sep 17 00:00:00 2001 From: Anshul Singhvi Date: Mon, 27 Jan 2025 16:09:23 -0500 Subject: [PATCH 3/4] Dict -> Dictionary --- src/algebra/layer.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/algebra/layer.jl b/src/algebra/layer.jl index 9ed753d8b..152d5a32e 100644 --- a/src/algebra/layer.jl +++ b/src/algebra/layer.jl @@ -427,7 +427,7 @@ end # Default fallback implementation """ - mergeable(plottype::Type{<: Plot}, primary::AbstractDict)::Bool + 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 @@ -439,7 +439,7 @@ 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::AbstractDict) +function mergeable(plottype::Type{<: Plot}, primary::AbstractDictionary) return false end From 0dab39235734a6561a745df791ed913c38839327 Mon Sep 17 00:00:00 2001 From: Anshul Singhvi Date: Tue, 28 Jan 2025 10:44:09 -0500 Subject: [PATCH 4/4] remove type constraint on fallback definition --- src/algebra/layer.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/algebra/layer.jl b/src/algebra/layer.jl index 152d5a32e..e3c58f46e 100644 --- a/src/algebra/layer.jl +++ b/src/algebra/layer.jl @@ -439,7 +439,7 @@ 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::AbstractDictionary) +function mergeable(plottype::Type{<: Plot}, primary) return false end