Skip to content

Add plot_layout(guides="collect") for composition-wide legend collection#1063

Merged
has2k1 merged 3 commits into
mainfrom
guides-collect
May 21, 2026
Merged

Add plot_layout(guides="collect") for composition-wide legend collection#1063
has2k1 merged 3 commits into
mainfrom
guides-collect

Conversation

@has2k1
Copy link
Copy Markdown
Owner

@has2k1 has2k1 commented May 21, 2026

Patchwork-style guide collection across composed plots. Adding plot_layout(guides="collect") to a composition gathers the legends from its descendants, dedupes by hash, and draws a single set at that level instead of one per plot.

has2k1 added 3 commits May 15, 2026 19:05
`guide` and `guides` each expose `_bind_source(plot)` and
`_bind_owner(owner)` instead of a single `setup` that greedily
binds layers/mapping/scales (per source plot) and theme/figure
(per renderer) at once. Lift `_assemble_guides` and the
figure-attach + `targets.legends` write out of the `guides` class
into module-level free functions that take theme/figure/targets as
explicit parameters. Add a `LegendOwner` Protocol so a future
composition-level renderer can satisfy the same binding contract
a `ggplot` does today.

Pure refactor; no public-API change; no behaviour change.
Adds `guides="collect" | "keep" | None` to `plot_layout`, modelled
on patchwork. `"collect"` hoists guides from descendant plots into
a single shared legend at the composition level; `"keep"` blocks
propagation through a subtree; `None` is transparent.

Both `ggplot.guides` and `Compose.guides` are now `guides()`
instances; `guides.draw()` dispatches on its `_owner` to either
the per-plot path or the cross-plot collect path. `guide_legend.merge`
unions `_layer_parameters` so a merged guide overlays glyphs from
every contributing plot. `composition_*_space` reserves room for
the collected legend, and `set_legends_position` works for both
plot and composition owners via a new `owner` property on the
side-spaces classes.

`test_nested_collect` is marked `xfail` — nested guide owners
render correctly but the top-level layout engine only reserves
space for the root composition's legend, so the nested legend
isn't positioned. Tracked separately.
`guide_area()` (a `plot_spacer` subclass) marks a cell in a composition
that should hold the legend produced by `plot_layout(guides="collect")`.
It must be a direct child of the collecting composition — nested
guide_areas belong to their own sub-grid and are not reached by an
outer collector. When no guide_area is eligible, collected guides fall
back to side placement.
@has2k1 has2k1 merged commit 9dc3f22 into main May 21, 2026
14 checks passed
@has2k1 has2k1 deleted the guides-collect branch May 21, 2026 20:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant