Reflow the static legend instead of silently dropping entries#286
Conversation
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.
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
Merging this PR will not alter performance
Comparing Footnotes
|
Stacked on #285.
Problem
The browser legend scrolls (
overflow:auto) when it outgrows the plot rect. SVGand the native rasterizer cannot, and
_legend_layoutresolved that by drawingnames[:visible_count]and discarding the rest — no warning, no ellipsis, noaffordance.
Measured on one chart rendered both ways (
width=900,ncols=1):Confirmed in-browser on the 40/160 case: the legend slot holds all 40
legend_itemnodes and scrolls (scrollHeight626 vsclientHeight104),while the exported PNG showed
s00–s04and nothing else.Before / after
40 named series,
legend(ncols=1), 900×300, native PNG.Fix
Spend width before losing anything.
legend(ncols=)becomes a floor forstatic 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):
That also covers the case where the legend previously vanished entirely —
the quietest of the three failure modes.
max_fit_colsmoves out of the narrowing branch since the reflow needs it as anupper bound too. The browser path is untouched.
Found during a customizability audit.