Skip to content

Commit

Permalink
fixed scalebar width #919
Browse files Browse the repository at this point in the history
  • Loading branch information
mtennekes committed Aug 24, 2024
1 parent 397dbcd commit 72f9a58
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
2 changes: 2 additions & 0 deletions R/tmapGridComp.R
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,8 @@ tmapGridCompWidth.tm_scalebar = function(comp, o) {
comp$WnativeID = 3
if (!is.null(comp$breaks)) {
comp$WnativeRange = tail(comp$breaks, 1) - comp$breaks[1]# + (comp$breaks[2] - comp$breaks[1]) * 2
comp$Wextra_line = textS * o$lin# for fitting break labels

}

comp
Expand Down
13 changes: 11 additions & 2 deletions R/tmapGridLegend.R
Original file line number Diff line number Diff line change
Expand Up @@ -304,8 +304,17 @@ tmapGridLegend = function(comp, o, facet_row = NULL, facet_col = NULL, facet_pag
#newIn = min(totW, bb_facet * cmp$width)
newIn = min(totW, cmp$Win)
} else {
# in case breaks are defined: allow the total width to be used (as upper bound)
newIn = totW
# in case breaks are defined: compute width

# for fitting breaks (half of last 'breaks' word + width of units text)
Wextra = (ceiling(nchar(tail(cmp$breaks, 1)) / 2) + 2 + nchar(cmp$units$unit)) * cmp$Wextra_line # for fitting break labels

# bbw are number of (CRS) units of map width, totalCoords translated to scalebar units
totalCoords = bbw * cmp$units$to

Wcomp = bb_facet * (cmp$WnativeRange / totalCoords) + Wextra

newIn = min(totW, Wcomp)
}

margins = sum(head(as.numeric(cmp$wsu[-cmp$WnativeID]), -1))
Expand Down

0 comments on commit 72f9a58

Please sign in to comment.