From bb7b15569c5eaf14e6e079fe8860ff9346411f8d Mon Sep 17 00:00:00 2001 From: mtennekes Date: Fri, 13 Oct 2023 14:30:07 +0200 Subject: [PATCH] #795 --- R/process_meta.R | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/R/process_meta.R b/R/process_meta.R index 4afcb453..5f1ebc6a 100644 --- a/R/process_meta.R +++ b/R/process_meta.R @@ -208,30 +208,41 @@ process_meta = function(o, d, cdt, aux) { rep(0, 4) } - grid.margins = if (grid.show && !grid.labels.inside.frame) { - + + + grid.labels.show = rep(grid.labels.show, length.out = 2) # also happens in tmapGridGridPrep + if (grid.show && any(grid.labels.show) && !grid.labels.inside.frame) { proj = sf::st_crs(bbx) if (!is.na(o$grid.crs)) { bbx_orig <- bbx bbx <- suppressWarnings(bb(bbx, current.projection = proj, projection = o$grid.crs)) } - gridx = pretty30(bbx[c(1,3)], n=5, longlat = !is.na(o$grid.crs) && sf::st_is_longlat(proj)) - gridy = pretty30(bbx[c(2,4)], n=5, longlat = !is.na(o$grid.crs) && sf::st_is_longlat(proj)) - - xbbstringWin <- max(convertWidth(stringWidth(do.call("fancy_breaks", c(list(vec=gridx, intervals=FALSE), grid.labels.format))), "inch", valueOnly = TRUE)) * grid.labels.size - ybbstringWin <- max(convertWidth(stringWidth(do.call("fancy_breaks", c(list(vec=gridy, intervals=FALSE), grid.labels.format))), "inch", valueOnly = TRUE)) * grid.labels.size - lineHin <- convertHeight(unit(grid.labels.size, "lines"), "inch", valueOnly=TRUE) - xgridHin <- ifelse(!is.na(grid.labels.space.x), grid.labels.space.x * lineHin, ifelse(grid.labels.rot[1] %in% c(0, 180), 1.375 * lineHin, xbbstringWin + lineHin * .75) + grid.labels.margin.x * lineHin) - ygridWin <- ifelse(!is.na(grid.labels.space.y), grid.labels.space.y * lineHin, ifelse(grid.labels.rot[2] %in% c(0, 180), ybbstringWin + lineHin * .75, 1.375 * lineHin) + grid.labels.margin.y * lineHin) + if (grid.labels.show[1]) { + gridx = pretty30(bbx[c(1,3)], n=5, longlat = !is.na(o$grid.crs) && sf::st_is_longlat(proj)) + xbbstringWin <- max(convertWidth(stringWidth(do.call("fancy_breaks", c(list(vec=gridx, intervals=FALSE), grid.labels.format))), "inch", valueOnly = TRUE)) * grid.labels.size + xgridHin <- ifelse(!is.na(grid.labels.space.x), grid.labels.space.x * lineHin, ifelse(grid.labels.rot[1] %in% c(0, 180), 1.375 * lineHin, xbbstringWin + lineHin * .75) + grid.labels.margin.x * lineHin) + + } else { + xgridHin = 0 + } + + if (grid.labels.show[2]) { + gridy = pretty30(bbx[c(2,4)], n=5, longlat = !is.na(o$grid.crs) && sf::st_is_longlat(proj)) + ybbstringWin <- max(convertWidth(stringWidth(do.call("fancy_breaks", c(list(vec=gridy, intervals=FALSE), grid.labels.format))), "inch", valueOnly = TRUE)) * grid.labels.size + ygridWin <- ifelse(!is.na(grid.labels.space.y), grid.labels.space.y * lineHin, ifelse(grid.labels.rot[2] %in% c(0, 180), ybbstringWin + lineHin * .75, 1.375 * lineHin) + grid.labels.margin.y * lineHin) + } else { + ygridWin = 0 + } marks_new = c(xgridHin, ygridWin, xgridHin, ygridWin) / lin - as.integer(c("bottom", "left", "top", "right") %in% grid.labels.pos) * marks_new * c(lineH, lineW, lineH, lineW) + grid.margins = as.integer(c("bottom", "left", "top", "right") %in% grid.labels.pos) * marks_new * c(lineH, lineW, lineH, lineW) } else { - rep(0, 4) + grid.margins = rep(0, 4) } + between.marginH = between.margin * lineH between.marginW = between.margin * lineW