Issue #303 margin adjustment for multi-line labels and titles#549
Issue #303 margin adjustment for multi-line labels and titles#549vincentarelbundock wants to merge 3 commits intograntmcdermott:mainfrom
Conversation
|
Super, thanks for taking this on. I kept meaning to, but couldn't find the time... |
|
Frankly, I'm not sure I can wrap my head entirely around the margins part of the code. But this seems to be working for the cases I investigated. So I'd say this is OK for review. |
grantmcdermott
left a comment
There was a problem hiding this comment.
Left a few quick comments while I had a sec.
I also have a slightly more involved refactor in mind for the core dynamic theme margin adjustment logic. tl;dr Right now, we do things a bit back to front; we assign title space up front and then remove it if it is absent, or increase if it has multiple lines per your PR here. I think we could simplify things for these dnymaic themes, by setting margins that assume no titles a priori and then make (multline) space for them if these titles are present. I'll take a crack at this later today, hopefully.
| left_margin_in = par("mai")[2] | ||
| # Keep roughly one glyph-width of room from the left device edge to avoid | ||
| # clipping of the outermost ylab line on compact multi-panel layouts. | ||
| edge_pad_in = 0.75 * csi * cex_ylab |
There was a problem hiding this comment.
I might be misunderstanding, but why calculate in inches (csi) instead of user coords (cxy)?
Where does 0.75 come from? Is it borrowed from one of the (hard-coded) based plot scaling factors? Or, just eye-balling?
| if (main_lines > 1L) { | ||
| # Keep line 1 aligned with single-line titles by shifting the centered | ||
| # multi-line block downward by half its extra line height. | ||
| if (is.null(line_main)) line_main = par("mgp")[3] + 1.1 |
There was a problem hiding this comment.
Should we be using get_tpar() here to get theme-specific settings instead of par()?
| if (ylab_lines == 0) omar[2] = omar[2] - 1 | ||
| if (main_lines == 0) omar[3] = omar[3] - 1 | ||
|
|
||
| if (xlab_lines > 1) omar[1] = omar[1] + (xlab_lines - 1) * par("cex.lab") |
There was a problem hiding this comment.
Should these par() cases be get_tpar() instead?
This change fixes dynamic margins when annotation text is missing (
NA,NULL, or empty) and when labels contain multiple lines.Internal changes:
text_line_count()to normalize line counting for labels/subtitles (treat missing text as 0 lines).main/sub/xlab/ylabinto facet margin logic and adjusted margins by line count (shrink for missing text, expand for multi-line text).subin legend layout, sosub = NAno longer reserves extra bottom space.Testing note: