Skip to content

Commit

Permalink
added tm_text bgcol and bgcol_alpha
Browse files Browse the repository at this point in the history
  • Loading branch information
mtennekes committed Feb 2, 2024
1 parent 8dc041b commit 91e22ad
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 13 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,4 @@ Config/testthat/edition: 3
Encoding: UTF-8
LazyData: true
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.2.3
RoxygenNote: 7.3.0
2 changes: 1 addition & 1 deletion R/tm_layers_text.R
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
#' (meaning only one group can be shown), `"check"` for check boxes (so multiple groups can be shown),
#' and `"none"` for no control (the group cannot be (de)selected).
#' @param ... to catch deprecated arguments from version < 4.0
#' @example ./examples/tm_lines.R
#' @example ./examples/tm_text.R
#' @export
tm_text = function(text = tm_const(),
text.scale = tm_scale(),
Expand Down
2 changes: 2 additions & 0 deletions R/tmapLeafletComp_leg_portrait.R
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ tmapLeaflet_legend_comp = function(comp, o) {
type = if ((!is.na(gp$fill[1]) && any(nchar(gp$fill) > 50)) || (!is.na(gp$fill_alpha[1]) && any(nchar(gp$fill_alpha) > 50)) ||
(!is.na(gp$col[1]) && any(nchar(gp$col) > 50)) || (!is.na(gp$col_alpha[1]) && any(nchar(gp$col_alpha) > 50))) {
"gradient"
} else if (any(c("bgcol", "bgcol_alpha") %in% varying)) {
"none"
} else {
"symbols"
}
Expand Down
5 changes: 4 additions & 1 deletion R/tmapLeafletLegend.R
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,10 @@ tmapLeaflet_legend = function(cmp, lf, o, orientation) {

legpos = leaflet_pos(cmp$position)

lf2 = if (cmp$type == "gradient") {
lf2 = if (cmp$typ == "none") {
#message("Text based legends not supported in view mode")
lf
} else if (cmp$type == "gradient") {
vary = if ("fill" %in% cmp$varying) "fillColor" else "color"
#vary_alpha = paste0(vary, "_alpha")

Expand Down
19 changes: 9 additions & 10 deletions R/tmapLeaflet_layers.R
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,14 @@ tmapLeafletText = function(shpTM, dt, gp, bbx, facet_row, facet_col, facet_page,
face_set = unique(gp$fontface)
col_set = unique(gp$col)

if (length(face_set) != 1) warning("Variable fontfaces not supported by view mode")
bgcol_set = unique(gp$bgcol)

if (any(bgcol_set != "#00000000")) {
message("Variable bgcol and bgcol_alpha not supported by view mode")
}


if (length(face_set) != 1) message("Variable fontfaces not supported by view mode")

vary = (length(cex_set) != 1) || (length(alpha_set) != 1) || (length(face_set) != 1) || (length(col_set) != 1)

Expand Down Expand Up @@ -353,15 +360,7 @@ tmapLeafletText = function(shpTM, dt, gp, bbx, facet_row, facet_col, facet_page,
}
assign_lf(lf, facet_row, facet_col, facet_page)

# if (o$use.WebGL) {
# lf |>
# leafgl::addGlPoints(sf::st_sf(shp), fillColor = gp$fill, radius = gp$size*10, fillOpacity = gp$fill_alpha, color = gp$col, opacity = gp$color_alpha, weight = gp$lwd, pane = pane, group = group) |>
# assign_lf(facet_row, facet_col, facet_page)
# } else {
# lf |>
# leaflet::addCircleMarkers(lng = coords[, 1], lat = coords[, 2], fillColor = gp$fill, radius = gp$size*4, fillOpacity = gp$fill_alpha, color = gp$col, opacity = gp$color_alpha, weight = gp$lwd, group = group, options = opt) |>
# assign_lf(facet_row, facet_col, facet_page)
# }


NULL
}
12 changes: 12 additions & 0 deletions examples/tm_text.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
tm_shape(World) +
tm_text(text = "name",
size = .4,
bgcol = "economy")

tm_shape(World) +
tm_text(text = "name",
size = .4,
bgcol = "economy",
bgcol.scale = tm_scale_categorical(values = cols4all::.P$hcl$cat$set2),
bgcol_alpha = "pop_est",
bgcol_alpha.scale = tm_scale_intervals(style = "kmeans"))
13 changes: 13 additions & 0 deletions sandbox/issues.R
Original file line number Diff line number Diff line change
Expand Up @@ -483,5 +483,18 @@ tm_basemap(c("Esri.WorldShadedRelief", "Stadia.StamenTerrain")) +
tm_tiles("Stadia.StamenTerrainLines") +
tm_tiles("Stadia.StamenTerrainLabels")

## bgcol

tm_shape(World) +
tm_text("name", bgcol = "green")

tm_shape(World) +
tm_text("name", bgcol = "economy")

tm_shape(World) +
tm_text(text = "name",
size = .4,
bgcol = "economy",
bgcol.scale = tm_scale_categorical(values = cols4all::.P$hcl$cat$set2),
bgcol_alpha = "pop_est",
bgcol_alpha.scale = tm_scale_intervals(style = "kmeans"))

0 comments on commit 91e22ad

Please sign in to comment.