Skip to content

plot: add legend background colors - #808

Open
umrndem wants to merge 1 commit into
gonum:masterfrom
umrndem:feat/legend-background
Open

umrndem wants to merge 1 commit into
gonum:masterfrom
umrndem:feat/legend-background

Conversation

@umrndem

@umrndem umrndem commented Nov 16, 2026

Copy link
Copy Markdown

Fixes #691.

Add Legend.BackgroundColor to fill behind legend entries before drawing their thumbnails and labels. The default nil color keeps the background transparent; empty legends do not paint a background.

Calculate the legend rectangle from the same entry positions used by drawing, including offsets. This also corrects the previous horizontal anchoring and vertical extents. Plain-text glyph bounds account for descenders, italic overhangs, multiline labels and rotation. Entry drawing positions are preserved. Other text handlers retain their existing layout-bounds contract.

Add a public background example, image comparisons and geometry regressions covering all four corners, vertical positions/alignment, offsets, italic multiline text, rotation, empty legends and zero-size fonts. Regenerate only the standalone-legend golden (corrected outlines) and the new background golden.

Validation on Go 1.26.6 / Linux:

  • go test -trimpath -p 1 ./...: all packages pass.
  • Repository copyright, imports, formatting and coverage scripts pass.
  • Pinned Staticcheck 2025.1 passes.
  • The new geometry regression fails with the pre-review rectangle and passes with the corrected bounds; 72 layout configurations are checked against recorded glyph and thumbnail geometry.
  • Both PNG examples were generated and inspected locally.

-trimpath normalizes source paths for the existing recorder test. Without it, that unchanged package expects an import-relative path but receives this checkout's absolute path; its targeted test passes with the flag.

@kortschak kortschak left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, but I'd like to get @sbinet's review too.

@kortschak
kortschak requested a review from sbinet November 17, 2026 09:50
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.

plot: enable specifying legend background colour.

2 participants