Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
mtennekes committed Oct 13, 2023
1 parent f1c561d commit bb7b155
Showing 1 changed file with 23 additions and 12 deletions.
35 changes: 23 additions & 12 deletions R/process_meta.R
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit bb7b155

Please sign in to comment.