Expand description
Shared geometry for stacking panel-corner “furniture” clear of each
other — annotation_scale()/annotation_attribution()’s scale bar and
attribution text, bivariate_legend()’s square guide, and an ordinary
legend placed with legend_position_inside — so two of them anchored
to the same or adjacent corners don’t draw on top of one another
(sipemu/ggplot-rs#273).
Each corner geom draws in plot-layer order (the order layers were added
to the plot). Before drawing, it asks DrawBackend::corner_claims
what boxes earlier geoms in this render pass already placed,
stack_clears its own measured box away from its own anchor edge
until it no longer overlaps any of them, draws at the (possibly
shifted) result, then registers that box with
DrawBackend::claim_corner_box so a later geom in the same render
pass sees it too.
An ordinary inside legend (legend_position_inside) draws after
every geom (renderer.rs’s draw order: layers, then the legend), so
there’s no later geom for it to defer to in the usual way — instead
its box is pre-claimed before any geom draws, computed the same way
draw_legend_planned itself positions it (see
guide::legend::inside_legend_box), so attribution/scale-bar/bivariate
geoms drawn first still see it and stack clear of it.
Functions§
- rects_
intersect trueifaandboverlap with positive area — touching edges (sharing a boundary with zero-width overlap) don’t count, so two items placed flush against each other aren’t flagged as colliding.- stack_
clear - Shifts
rectalong the y axis, away from its own anchor edge, just far enough to clear every rect inclaimsit would otherwise overlap, plus [CORNER_STACK_GAP] of real clearance — “stack them” (#273).away_signis the direction away from the anchor edge:-1.0shifts up (decreases y), the right direction for a bottom-anchored corner’s items (they stack upward, away from the bottom edge); any other value shifts down (increases y), for a top-anchored corner. A claim with no horizontal overlap withrectis never a reason to move (rects_intersectrequires both axes).