Skip to content

Commit

Permalink
fixed hovering #851
Browse files Browse the repository at this point in the history
  • Loading branch information
mtennekes committed Jun 25, 2024
1 parent c73a378 commit 5c921cd
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 28 deletions.
5 changes: 2 additions & 3 deletions R/tm_layers_lines.R
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ opt_tm_lines = function(lines.only = "ifany") {
#' @param options options passed on to the corresponding `opt_<layer_function>` function
#' @param popup.vars names of data variables that are shown in the popups in `"view"` mode. Set popup.vars to `TRUE` to show all variables in the shape object. Set popup.vars to `FALSE` to disable popups. Set popup.vars to a character vector of variable names to those those variables in the popups. The default (`NA`) depends on whether visual variables (e.g.`col`) are used. If so, only those are shown. If not all variables in the shape object are shown.
#' @param popup.format list of formatting options for the popup values. See the argument `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 `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.
#' @param hover name of the data variable that specifies the hover labels
#'
#' @param hover name of the data variable that specifies the hover labels (view mode only). Set to `FALSE` to disable hover labels. By default `FALSE`, unless `id` is specified. In that case, it is set to `id`,
#' @param id name of the data variable that specifies the indices of the spatial features. Only used for `"view"` mode.
#' @param lines.only should only line geometries of the shape object (defined in [tm_shape()]) be plotted, or also other geometry types (like polygons)? By default `"ifany"`, which means `TRUE` in case a geometry collection is specified.
#' @param ... to catch deprecated arguments from version < 4.0
Expand Down Expand Up @@ -83,7 +82,7 @@ tm_lines = function(col = tm_const(),
group.control = "check",
popup.vars = NA,
popup.format = list(),
hover = "",
hover = NA,
id = "",
options = opt_tm_lines(),
...) {
Expand Down
4 changes: 2 additions & 2 deletions R/tm_layers_polygons.R
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ opt_tm_polygons = function(polygons.only = "ifany") {
#' it is applied to all numeric variables of `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.
#' @param hover name of the data variable that specifies the hover labels
#' @param hover name of the data variable that specifies the hover labels (view mode only). Set to `FALSE` to disable hover labels. By default `FALSE`, unless `id` is specified. In that case, it is set to `id`,
#' @param id name of the data variable that specifies the indices of the spatial
#' features. Only used for `"view"` mode.
#' @param polygons.only should only polygon geometries of the shape object (defined in [tm_shape()]) be plotted? By default `"ifany"`, which means `TRUE` in case a geometry collection is specified.
Expand Down Expand Up @@ -120,7 +120,7 @@ tm_polygons = function(fill = tm_const(),
group.control = "check",
popup.vars = NA,
popup.format = list(),
hover = "",
hover = NA,
id = "",
options = opt_tm_polygons(),
...) {
Expand Down
5 changes: 2 additions & 3 deletions R/tm_layers_symbols.R
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,7 @@ opt_tm_squares = opt_tm_symbols
#' variables. If one list of formatting options is provided, it is applied to
#' all numeric variables of `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.
#' @param hover name of the data variable that specifies the hover labels
#'
#' @param hover name of the data variable that specifies the hover labels (view mode only). Set to `FALSE` to disable hover labels. By default `FALSE`, unless `id` is specified. In that case, it is set to `id`,
#' @param id name of the data variable that specifies the indices of the spatial features.
#' Only used for `"view"` mode.
#' @param points.only should only point geometries of the shape object (defined in [tm_shape()]) be plotted? By default `"ifany"`, which means `TRUE` in case a geometry collection is specified.
Expand Down Expand Up @@ -161,7 +160,7 @@ tm_symbols = function(size = tm_const(),
group.control = "check",
popup.vars = NA,
popup.format = list(),
hover = "",
hover = NA,
id = "",
options = opt_tm_symbols(),
...) {
Expand Down
7 changes: 3 additions & 4 deletions R/tmapLeaflet_layers.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ tmapLeafletPolygons = function(shpTM, dt, pdt, popup.format, hdt, idt, gp, bbx,
popups = NULL
} else {
pdt = pdt[match(dt$tmapID__, pdt$tmapID__)][, tmapID__ := NULL]

popups = view_format_popups(id = hdt, titles = names(pdt), values = pdt, format = popup.format)
popups = view_format_popups(id = idt, titles = names(pdt), values = pdt, format = popup.format)
}


Expand Down Expand Up @@ -72,7 +71,7 @@ tmapLeafletLines = function(shpTM, dt, pdt, popup.format, hdt, idt, gp, bbx, fac
popups = NULL
} else {
pdt = pdt[match(dt$tmapID__, pdt$tmapID__)][, tmapID__ := NULL]
popups = view_format_popups(id = hdt, titles = names(pdt), values = pdt, format = popup.format)
popups = view_format_popups(id = idt, titles = names(pdt), values = pdt, format = popup.format)
}

gp = impute_gp(gp, dt)
Expand Down Expand Up @@ -111,7 +110,7 @@ tmapLeafletSymbols = function(shpTM, dt, pdt, popup.format, hdt, idt, gp, bbx, f
} else {
pdt = pdt[match(dt$tmapID__, pdt$tmapID__)][, tmapID__ := NULL]

popups = view_format_popups(id = hdt, titles = names(pdt), values = pdt, format = popup.format)
popups = view_format_popups(id = idt, titles = names(pdt), values = pdt, format = popup.format)
}

gp = impute_gp(gp, dt)
Expand Down
1 change: 0 additions & 1 deletion R/view_format_popups.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ view_format_popups <- function(id=NULL, titles, format, values) {
function(x) x
}
})

if (!is.null(id)) {
labels <- paste("<b>", h[[1]](id), "</b>", sep="")
} else {
Expand Down
15 changes: 0 additions & 15 deletions R/view_functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,6 @@
# gpl$data[[gpl[[var_names]]]]
# }

get_popups <- function(gpl, type) {
var_names <- paste(type, "names", sep=".")
var_vars <- paste(type, "popup.vars", sep=".")
var_format <- paste(type, "popup.format", sep=".")

dt <- gpl$data

if (is.na(gpl[[var_vars]][1])) {
popups <- NULL
} else {
popups <- view_format_popups(dt[[gpl[[var_names]]]], gpl[[var_vars]], gpl[[var_format]], dt[, gpl[[var_vars]], drop=FALSE])
}
popups
}

#
# working_internet <- function(url = "https://www.google.com") {
# # test the http capabilities of the current R build
Expand Down

0 comments on commit 5c921cd

Please sign in to comment.