diff --git a/R/step1_helper_facets.R b/R/step1_helper_facets.R index a3fe99ce..5e686eee 100644 --- a/R/step1_helper_facets.R +++ b/R/step1_helper_facets.R @@ -189,6 +189,13 @@ step1_rearrange_facets = function(tmo, o) { } if (length(popup.vars)) add_used_vars(popup.vars) + + if (is.na(hover)) { + hover = id + } else if (is.logical(hover)) { + hover = ifelse(hover, id, "") + } + if (hover != "" && !hover %in% smeta$vars) rlang::arg_match0(hover, smeta$vars, "hover label", error_call = NULL) if (hover != "") add_used_vars(hover) if (id != "" && !id %in% smeta$vars) rlang::arg_match0(id, smeta$vars, arg_nm = "id", error_call = NULL) diff --git a/R/tmapGridComp_leg_landscape.R b/R/tmapGridComp_leg_landscape.R index f519ec64..920bb208 100644 --- a/R/tmapGridComp_leg_landscape.R +++ b/R/tmapGridComp_leg_landscape.R @@ -30,7 +30,10 @@ tmapGridCompHeight.tm_legend_standard_landscape = function(comp, o) { height = get_legend_option(comp$item.height, comp$type) - item_height = if (comp$type == "symbols") max(height, comp$gpar$size / textS) else height + item_height = if (comp$type == "symbols") { + shps = rep(comp$gpar$shape, length.out = nlev) + max(height, rep(comp$gpar$size, length.out = nlev) / textS * ifelse(shps > 999, comp$layer_args$icon.scale, 1)) + } else height itemHsIn = grid::unit(item_height * textS * o$lin, units = "inch") titleP = comp$title.padding[c(3,1)] * titleS * o$lin @@ -76,7 +79,8 @@ tmapGridCompWidth.tm_legend_standard_landscape = function(comp, o) { # for the latter two, there are 3 ways of stretching the legend: padding (space between items), items (widths of all items), or itemsNNA (widths of non-NA items) if (comp$type == "symbols") { - item_widths = pmax(width, rep(comp$gpar$size / textS, length.out = nlev), labelW) + shps = rep(comp$gpar$shape, length.out = nlev) + item_widths = pmax(width, rep(comp$gpar$size / textS, length.out = nlev) * ifelse(shps > 999, comp$layer_args$icon.scale, 1), labelW) comp$stretch = if (!is.na(comp$width)) "padding" else "none" } else if (comp$type %in% c("rect", "lines")) { item_widths = pmax(rep(width, nlev), labelW) @@ -327,8 +331,19 @@ tmapGridLegPlot.tm_legend_standard_landscape = function(comp, o, fH, fW) { #grItems = mapply(function(i, gpari) gridCell(i+3, 2, grid::rectGrob(gp = gpari)), 1:nlev, gpars, SIMPLIFY = FALSE) grItems = mapply(function(id, gpari) gridCell(6, id, grid::linesGrob(x = grid::unit(c(0.5,0.5), "npc"), gp = gpari)), comp$item_ids, gpars, SIMPLIFY = FALSE) } else if (comp$type == "symbols") { - if (length(gp$size) == 1) gp$size = min(gp$size, min(get_legend_option(comp$item.height, "symbols"), + shps = rep(comp$gpar$shape, length.out = comp$nitems) + + + # * ifelse(shps > 999, comp$layer_args$icon.scale, 1) + + + if (length(gp$size) == 1) { + gp$size = min(gp$size, min(get_legend_option(comp$item.height, "symbols"), get_legend_option(comp$item.width, "symbols")) * comp$textS) + } else { + shps = rep(gp$shape, length.out = nlev) + gp$size = rep(gp$size, length.out = nlev) * ifelse(shps > 999, comp$layer_args$icon.scale, 1) + } gpars = gp_to_gpar(gp, split_to_n = nlev, o = o, type = comp$type) # scale down (due to facet use) @@ -356,8 +371,8 @@ tmapGridLegPlot.tm_legend_standard_landscape = function(comp, o, fH, fW) { } grid::gTree(children=grbs, vp=viewport(x=0.5, y=0.5, - width=unit(gpari$size*2/3, "lines"), - height=unit(gpari$size*2/3, "lines"))) + width=unit(gpari$size*9/10, "lines"), + height=unit(gpari$size*9/10, "lines"))) } else { if (diffAlpha) { grid::grobTree( diff --git a/R/tmapGridComp_leg_portrait.R b/R/tmapGridComp_leg_portrait.R index 268e0701..a988ff1a 100644 --- a/R/tmapGridComp_leg_portrait.R +++ b/R/tmapGridComp_leg_portrait.R @@ -49,7 +49,8 @@ tmapGridCompHeight.tm_legend_standard_portrait = function(comp, o) { # for the latter two, there are 3 ways of stretching the legend: padding (space between items), items (heights of all items), or itemsNNA (heights of non-NA items) if (comp$type == "symbols") { - item_heights = pmax(height, rep(comp$gpar$size / textS, length.out = nlev)) + shps = rep(comp$gpar$shape, length.out = nlev) + item_heights = pmax(height, rep(comp$gpar$size / textS, length.out = nlev) * ifelse(shps > 999, comp$layer_args$icon.scale, 1)) comp$stretch = if (!is.na(comp$height)) "padding" else "none" } else if (comp$type %in% c("rect", "lines", "bivariate")) { item_heights = rep(height, nlev) @@ -150,7 +151,10 @@ tmapGridCompWidth.tm_legend_standard_portrait = function(comp, o) { width = get_legend_option(comp$item.width, comp$type) - item_widths = if (comp$type == "symbols") pmax(width, rep(comp$gpar$size / textS, length.out = comp$nitems)) else rep(width, length.out = ni) + item_widths = if (comp$type == "symbols") { + shps = rep(comp$gpar$shape, length.out = comp$nitems) + pmax(width, rep(comp$gpar$size / textS, length.out = comp$nitems) * ifelse(shps > 999, comp$layer_args$icon.scale, 1)) + } else rep(width, length.out = ni) if (comp$type == "bivariate") { @@ -522,18 +526,14 @@ tmapGridLegPlot.tm_legend_standard_portrait = function(comp, o, fH, fW) { shapeLib = get("shapeLib", envir = .TMAP) justLib = get("justLib", envir = .TMAP) - +#browser() grItems = mapply(function(id, gpari, gpari1, gpari2) { grobs = if (gpari$shape > 999) { - grbs = if (gpari$lwd == 0) { - gList(shapeLib[[gpari$shape-999]]) - } else { - gList(shapeLib[[gpari$shape-999]], rectGrob(gp=gpar(fill=NA, col=gpari$col, lwd=gpari$lwd))) - } + grbs = gList(shapeLib[[gpari$shape-999]]) grid::gTree(children=grbs, vp=viewport(x=0.5, y=0.5, - width=unit(gpari$size*2/3, "lines"), - height=unit(gpari$size*2/3, "lines"))) + width=unit(gpari$size*9/10 * comp$layer_args$icon.scale, "lines"), + height=unit(gpari$size*9/10 * comp$layer_args$icon.scale, "lines"))) } else { if (diffAlpha) { grid::grobTree( diff --git a/R/tmapGridSymbols.R b/R/tmapGridSymbols.R index c288c096..ffaea099 100644 --- a/R/tmapGridSymbols.R +++ b/R/tmapGridSymbols.R @@ -72,13 +72,9 @@ tmapGridSymbols = function(shpTM, dt, gp, bbx, facet_row, facet_col, facet_page, if (!is.na(shi) && shi>999) { - size = gp$size[i]*2/3 * args$icon.scale + size = gp$size[i]*9/10 * args$icon.scale lwdid = if (length(gp$lwd) == 1L) 1 else i - grbs <- if (gp$lwd[lwdid] == 0) { - gList(shapeLib[[shi-999]]) - } else { - gList(shapeLib[[shi-999]], rectGrob(gp=gpar(fill=NA, col=gp$col[i], lwd=gp$lwd[lwdid]))) - } + grbs <- gList(shapeLib[[shi-999]]) gTree(children=grbs, vp=viewport(x=grid::unit(coords[i,1] + justx * size, "native"), y=grid::unit(coords[i,2] + justy * size, "native"), width=unit(size, "lines"), diff --git a/R/tmapLeafletLegend.R b/R/tmapLeafletLegend.R index dde83d5b..d2f88d8b 100644 --- a/R/tmapLeafletLegend.R +++ b/R/tmapLeafletLegend.R @@ -182,14 +182,15 @@ tmapLeaflet_legend = function(cmp, lf, o, orientation) { if (length(sid)) { iconLib <- get("shapeLib", envir = .TMAP)[sn[sid]-999] symbols_icons <- merge_icons(iconLib) - size = gp2$width[sid] / gp2$baseSize + + size = gp2$width[sid] / gp2$baseSize * cmp$layer_args$icon.scale/3 for (i in seq_along(sid)) { symbols$iconUrl[sid[i]] = symbols_icons$iconUrl[i] symbols$iconWidth[sid[i]] <- symbols_icons$iconWidth[i] * size[i] symbols$iconHeight[sid[i]] <- symbols_icons$iconHeight[i] * size[i] if (all(c("iconAnchorX", "iconAnchorY") %in% names(symbols_icons))) { - symbols$iconAnchorX[sid[i]] <- symbols_icons$iconAnchorX[i] * size[i] + symbols$iconAnchorX[sid[i]] <- symbols_icons$iconAnchorX[i] * size[i] symbols$iconAnchorY[sid[i]] <- symbols_icons$iconAnchorY[i] * size[i] } diff --git a/R/tmapLeaflet_layers.R b/R/tmapLeaflet_layers.R index ae888321..96963792 100644 --- a/R/tmapLeaflet_layers.R +++ b/R/tmapLeaflet_layers.R @@ -149,7 +149,7 @@ tmapLeafletSymbols = function(shpTM, dt, pdt, popup.format, hdt, idt, gp, bbx, f symbols_icons <- merge_icons(iconLib) size = gp2$width[sid] / gp2$baseSize - size[sid] = size[sid] * args$icon.scale/3 # icon.scale is set to 1 in view mode + size[sid] = size[sid] * args$icon.scale/3 for (i in seq_along(sid)) { symbols$iconUrl[sid[i]] = symbols_icons$iconUrl[i] diff --git a/R/tmapScaleBivariate.R b/R/tmapScaleBivariate.R index 625df712..5d0d123a 100644 --- a/R/tmapScaleBivariate.R +++ b/R/tmapScaleBivariate.R @@ -75,6 +75,8 @@ tmapScaleBivariate = function(x1, x2, scale, legend, chart, o, aes, layer, layer legend$vvalues = pal legend$vneutral = pal[4] legend$na.show = na + legend$layer_args = layer_args + chartFun = paste0("tmapChart", toTitleCase(chart$summary)) diff --git a/R/tmapScaleCategorical.R b/R/tmapScaleCategorical.R index 9ca5fab8..60540637 100644 --- a/R/tmapScaleCategorical.R +++ b/R/tmapScaleCategorical.R @@ -185,6 +185,7 @@ tmapScaleCategorical = function(x1, scale, legend, chart, o, aes, layer, layer_a icon_scale = icon_scale na.show = get("na.show", envir = parent.env(environment())) scale = "categorical" + layer_args = layer_args }) diff --git a/R/tmapScaleContinuous.R b/R/tmapScaleContinuous.R index f0707363..fe196c45 100644 --- a/R/tmapScaleContinuous.R +++ b/R/tmapScaleContinuous.R @@ -326,6 +326,7 @@ tmapScaleContinuous = function(x1, scale, legend, chart, o, aes, layer, layer_ar scale = "continuous" tr = tr limits = limits + layer_args = layer_args }) # NOTE: tr and limits are included in the output to facilitate the transformation of the leaflet continuous legend ticks (https://github.com/rstudio/leaflet/issues/665) #vvalues_mids = sapply(cont_split(vvalues), "[", nvv/2) diff --git a/R/tmapScaleDiscrete.R b/R/tmapScaleDiscrete.R index b483ae43..976eaad2 100644 --- a/R/tmapScaleDiscrete.R +++ b/R/tmapScaleDiscrete.R @@ -166,6 +166,7 @@ tmapScaleDiscrete = function(x1, scale, legend, chart, o, aes, layer, layer_args vneutral = value.neutral na.show = get("na.show", envir = parent.env(environment())) scale = "discrete" + layer_args = layer_args }) chartFun = paste0("tmapChart", toTitleCase(chart$summary)) diff --git a/R/tmapScaleIntervals.R b/R/tmapScaleIntervals.R index ce2093c9..9c6a5319 100644 --- a/R/tmapScaleIntervals.R +++ b/R/tmapScaleIntervals.R @@ -186,6 +186,7 @@ tmapScaleIntervals = function(x1, scale, legend, chart, o, aes, layer, layer_arg vneutral = value.neutral na.show = get("na.show", envir = parent.env(environment())) scale = "intervals" + layer_args = layer_args }) chartFun = paste0("tmapChart", toTitleCase(chart$summary)) diff --git a/man/tm_cartogram.Rd b/man/tm_cartogram.Rd index a896f180..893e8a9f 100644 --- a/man/tm_cartogram.Rd +++ b/man/tm_cartogram.Rd @@ -63,7 +63,7 @@ numeric data variables. If one list of formatting options is provided, it is applied to all numeric variables of \code{popup.vars}. Also, a (named) list of lists can be provided. In that case, each list of formatting options is applied to the named variable.} - \item{\code{hover}}{name of the data variable that specifies the hover labels} + \item{\code{hover}}{name of the data variable that specifies the hover labels (view mode only). Set to \code{FALSE} to disable hover labels. By default \code{FALSE}, unless \code{id} is specified. In that case, it is set to \code{id},} \item{\code{id}}{name of the data variable that specifies the indices of the spatial features. Only used for \code{"view"} mode.} }} diff --git a/man/tm_lines.Rd b/man/tm_lines.Rd index 95c936bd..620c07c5 100644 --- a/man/tm_lines.Rd +++ b/man/tm_lines.Rd @@ -36,7 +36,7 @@ tm_lines( group.control = "check", popup.vars = NA, popup.format = list(), - hover = "", + hover = NA, id = "", options = opt_tm_lines(), ... @@ -67,7 +67,7 @@ tm_lines( \item{popup.format}{list of formatting options for the popup values. See the argument \code{legend.format} for options. Only applicable for numeric data variables. If one list of formatting options is provided, it is applied to all numeric variables of \code{popup.vars}. Also, a (named) list of lists can be provided. In that case, each list of formatting options is applied to the named variable.} -\item{hover}{name of the data variable that specifies the hover labels} +\item{hover}{name of the data variable that specifies the hover labels (view mode only). Set to \code{FALSE} to disable hover labels. By default \code{FALSE}, unless \code{id} is specified. In that case, it is set to \code{id},} \item{id}{name of the data variable that specifies the indices of the spatial features. Only used for \code{"view"} mode.} diff --git a/man/tm_polygons.Rd b/man/tm_polygons.Rd index 76910fef..78c47511 100644 --- a/man/tm_polygons.Rd +++ b/man/tm_polygons.Rd @@ -48,7 +48,7 @@ tm_polygons( group.control = "check", popup.vars = NA, popup.format = list(), - hover = "", + hover = NA, id = "", options = opt_tm_polygons(), ... @@ -107,7 +107,7 @@ it is applied to all numeric variables of \code{popup.vars}. Also, a (named) list of lists can be provided. In that case, each list of formatting options is applied to the named variable.} -\item{hover}{name of the data variable that specifies the hover labels} +\item{hover}{name of the data variable that specifies the hover labels (view mode only). Set to \code{FALSE} to disable hover labels. By default \code{FALSE}, unless \code{id} is specified. In that case, it is set to \code{id},} \item{id}{name of the data variable that specifies the indices of the spatial features. Only used for \code{"view"} mode.} diff --git a/man/tm_symbols.Rd b/man/tm_symbols.Rd index c115de07..27d3ab0e 100644 --- a/man/tm_symbols.Rd +++ b/man/tm_symbols.Rd @@ -86,7 +86,7 @@ tm_symbols( group.control = "check", popup.vars = NA, popup.format = list(), - hover = "", + hover = NA, id = "", options = opt_tm_symbols(), ... @@ -251,7 +251,7 @@ variables. If one list of formatting options is provided, it is applied to all numeric variables of \code{popup.vars}. Also, a (named) list of lists can be provided. In that case, each list of formatting options is applied to the named variable.} -\item{hover}{name of the data variable that specifies the hover labels} +\item{hover}{name of the data variable that specifies the hover labels (view mode only). Set to \code{FALSE} to disable hover labels. By default \code{FALSE}, unless \code{id} is specified. In that case, it is set to \code{id},} \item{id}{name of the data variable that specifies the indices of the spatial features. Only used for \code{"view"} mode.} diff --git a/man/tmap_internal.Rd b/man/tmap_internal.Rd new file mode 100644 index 00000000..b1433410 --- /dev/null +++ b/man/tmap_internal.Rd @@ -0,0 +1,94 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/tm_element.R, R/tmapGpar.R, R/tmapScale_.R, +% R/tmapTrans.R +\name{tm_element} +\alias{tm_element} +\alias{tm_element_list} +\alias{tmapGpar} +\alias{tmapTpar} +\alias{tmapUsrCls} +\alias{tmapScale} +\alias{tmapTransCentroid} +\alias{tmapTransRaster} +\alias{tmapTransPolygons} +\alias{tmapTransLines} +\alias{tmapTransCartogram} +\title{Internal methods for tmap extensions} +\usage{ +tm_element(..., subclass = NULL) + +tm_element_list(...) + +tmapGpar( + fill = NULL, + col = NULL, + shape = NULL, + size = NULL, + fill_alpha = NULL, + col_alpha = NULL, + lty = NULL, + lwd = NULL, + linejoin = NULL, + lineend = NULL, + ... +) + +tmapTpar(...) + +tmapUsrCls(x) + +tmapScale(aes, value, scale, legend, chart, free) + +tmapTransCentroid( + shpTM, + xmod = NULL, + ymod = NULL, + ord__, + plot.order, + args, + scale +) + +tmapTransRaster(shpTM, ord__, plot.order, args) + +tmapTransPolygons(shpTM, ord__, plot.order, args, scale) + +tmapTransLines(shpTM, ord__, plot.order, args, scale) + +tmapTransCartogram(shpTM, size, ord__, plot.order, args, scale) +} +\arguments{ +\item{...}{args} + +\item{subclass}{subclass} + +\item{fill, col, shape, size, fill_alpha, col_alpha, lty, lwd, linejoin, lineend}{visual variables} + +\item{x}{x} + +\item{aes}{aes} + +\item{value}{value} + +\item{scale}{scale} + +\item{legend}{legend} + +\item{chart}{chart} + +\item{free}{free} + +\item{shpTM}{shpTM} + +\item{xmod, ymod}{xmod and ymod} + +\item{ord__}{ord} + +\item{plot.order}{plot.order} + +\item{args}{args} +} +\description{ +Internal methods for tmap extensions +} +\keyword{internal}