Skip to content

Reflow the static legend instead of silently dropping entries#286

Merged
Alek99 merged 1 commit into
alek/fix-csp-font-srcfrom
alek/fix-legend-truncation
Jul 25, 2026
Merged

Reflow the static legend instead of silently dropping entries#286
Alek99 merged 1 commit into
alek/fix-csp-font-srcfrom
alek/fix-legend-truncation

Conversation

@Alek99

@Alek99 Alek99 commented Jul 25, 2026

Copy link
Copy Markdown
Member

Stacked on #285.

Problem

The browser legend scrolls (overflow:auto) when it outgrows the plot rect. SVG
and the native rasterizer cannot, and _legend_layout resolved that by drawing
names[:visible_count] and discarding the rest — no warning, no ellipsis, no
affordance.

Measured on one chart rendered both ways (width=900, ncols=1):

series height in browser in SVG/PNG dropped warnings
20 420 20 20 0 0
30 420 30 21 9 0
40 420 40 21 19 0
40 160 40 5 35 0

Confirmed in-browser on the 40/160 case: the legend slot holds all 40
legend_item nodes and scrolls (scrollHeight 626 vs clientHeight 104),
while the exported PNG showed s00s04 and nothing else.

Before / after

40 named series, legend(ncols=1), 900×300, native PNG.

Before — 12 of 40 After — 40 of 40
before after

Fix

Spend width before losing anything. legend(ncols=) becomes a floor for
static output: the exporters widen past it, up to what the plot rect affords at
the minimum cell width, so a tall series list reflows into columns. Every case
in the table above now draws all of its entries.

When the rect cannot hold every entry even at full width, keep the ones that fit
and warn with the achieved row × column count — allowed, but never silent (§28):

RuntimeWarning: legend shows 18 of 60 entries in static export: the plot rect
fits 6 row(s) by 3 column(s) and a static legend cannot scroll the way the
browser one does. Raise the chart height, pass a larger legend(ncols=...), or
name fewer series to keep every entry.

That also covers the case where the legend previously vanished entirely
the quietest of the three failure modes.

max_fit_cols moves out of the narrowing branch since the reflow needs it as an
upper bound too. The browser path is untouched.

Found during a customizability audit.

The browser legend scrolls when it outgrows the plot rect; SVG and the native
rasterizer cannot, and `_legend_layout` resolved that by rendering
`names[:visible_count]` and discarding the rest with no warning. A 40-series
chart at 900x300 exported a legend showing 12 entries — the other 28 vanished
from the PNG while every one of them was present and scrollable in the browser.

Spend width before losing anything: `legend(ncols=)` becomes a floor for static
output, and the exporters widen past it up to what the plot rect affords at the
minimum cell width, so a tall series list reflows into columns. The 40-series
case above now draws all 40.

When the rect cannot hold every entry even at full width, keep the ones that fit
and warn with the achieved row x column count, so the drop is allowed but never
silent (§28). That also covers the case where the legend previously disappeared
entirely, which was the quietest failure of the three.

`max_fit_cols` moves out of the narrowing branch since the reflow needs it as an
upper bound too. The browser path is untouched.
@coderabbitai

coderabbitai Bot commented Jul 25, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 0b6131ac-723d-4f3e-9ae0-f97d555e8861

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch alek/fix-legend-truncation

Comment @coderabbitai help to get the list of available commands.

@codspeed-hq

codspeed-hq Bot commented Jul 25, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 102 untouched benchmarks
⏩ 2 skipped benchmarks1


Comparing alek/fix-legend-truncation (248e423) with alek/fix-csp-font-src (16c662e)

Open in CodSpeed

Footnotes

  1. 2 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@Alek99
Alek99 merged commit 71d7409 into alek/fix-csp-font-src Jul 25, 2026
23 checks passed
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