Skip to content

Commit

Permalink
Use magrittr pipe for 4.0 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
olivroy committed Feb 5, 2024
1 parent 53511be commit 3cf87ae
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 37 deletions.
14 changes: 7 additions & 7 deletions R/tmapGridInit.R
Original file line number Diff line number Diff line change
Expand Up @@ -181,19 +181,19 @@ tmapGridInit = function(o, return.asp = FALSE, vp) {

p = rep(cols4all::c4a("brewer.paired"), 3)

gt = gt |>
add_to_gt(grid::rectGrob(gp=grid::gpar(fill = p[1])), row = 1:(nr), col = 1:(nc)) |> # outer
add_to_gt(grid::rectGrob(gp=grid::gpar(fill = p[2])), row = 2:(nr-1), col = 2:(nc-1)) |> # meta buffer out
add_to_gt(grid::rectGrob(gp=grid::gpar(fill = p[3])), row = 3:(nr-2), col = 3:(nc-2)) |> # meta margins
add_to_gt(grid::rectGrob(gp=grid::gpar(fill = p[2])), row = 4:(nr-3), col = 4:(nc-3)) |> # meta buffer in
gt = gt %>%
add_to_gt(grid::rectGrob(gp=grid::gpar(fill = p[1])), row = 1:(nr), col = 1:(nc)) %>% # outer
add_to_gt(grid::rectGrob(gp=grid::gpar(fill = p[2])), row = 2:(nr-1), col = 2:(nc-1)) %>% # meta buffer out
add_to_gt(grid::rectGrob(gp=grid::gpar(fill = p[3])), row = 3:(nr-2), col = 3:(nc-2)) %>% # meta margins
add_to_gt(grid::rectGrob(gp=grid::gpar(fill = p[2])), row = 4:(nr-3), col = 4:(nc-3)) %>% # meta buffer in
add_to_gt(grid::rectGrob(gp=grid::gpar(fill = p[4])), row = 5:(nr-4), col = 5:(nc-4)) # xylab
if (o$panel.type == "xtab") {
#add_to_gt(grid::rectGrob(gp=grid::gpar(fill = p[5])), row = 6:(nr-5), col = 6:(nc-5)) # panel buffer
gt = add_to_gt(gt, grid::rectGrob(gp=grid::gpar(fill = p[5])), row = 6:(nr-5), col = 6:(nc-5)) # panel
}

gt = gt |>
add_to_gt(grid::rectGrob(gp=grid::gpar(fill = p[6])), row = 7:(nr-6), col = 7:(nc-6)) |> # grid buffer
gt = gt %>%
add_to_gt(grid::rectGrob(gp=grid::gpar(fill = p[6])), row = 7:(nr-6), col = 7:(nc-6)) %>% # grid buffer
add_to_gt(grid::rectGrob(gp=grid::gpar(fill = p[7])), row = 8:(nr-7), col = 8:(nc-7)) # grid


Expand Down
8 changes: 4 additions & 4 deletions R/tmapLeafletComp.R
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ tmapLeafletCompWidth.tm_compass = function(comp, o) {
#' @method tmapLeafletLegPlot tm_compass
#' @export
tmapLeafletLegPlot.tm_compass = function(comp, lf, o) {
lf |> leafem::addLogo(system.file(paste0("img/compass_", comp$type, ".png"), package = "tmap"), src = "local", position = leaflet_pos(comp$position), width = 120, height = 120)
lf %>% leafem::addLogo(system.file(paste0("img/compass_", comp$type, ".png"), package = "tmap"), src = "local", position = leaflet_pos(comp$position), width = 120, height = 120)
}


Expand Down Expand Up @@ -113,7 +113,7 @@ tmapLeafletCompWidth.tm_scalebar = function(comp, o) {
#' @method tmapLeafletLegPlot tm_scalebar
#' @export
tmapLeafletLegPlot.tm_scalebar = function(comp, lf, o) {
lf |> leaflet::addScaleBar(position = leaflet_pos(comp$position))
lf %>% leaflet::addScaleBar(position = leaflet_pos(comp$position))
}


Expand Down Expand Up @@ -142,7 +142,7 @@ tmapLeafletCompWidth.tm_credits = function(comp, o) {
#' @method tmapLeafletLegPlot tm_credits
#' @export
tmapLeafletLegPlot.tm_credits = function(comp, lf, o) {
#lf |> leafem::addLogo(system.file(paste0("img/credits_", comp$type, ".png"), package = "tmap"), src = "local", position = paste(unlist(comp$position[c("pos.v", "pos.h")]), collapse = ""), width = 120, height = 120)
#lf %>% leafem::addLogo(system.file(paste0("img/credits_", comp$type, ".png"), package = "tmap"), src = "local", position = paste(unlist(comp$position[c("pos.v", "pos.h")]), collapse = ""), width = 120, height = 120)
message("tm_credits not implemented yet for view mode")
lf
}
Expand Down Expand Up @@ -172,7 +172,7 @@ tmapLeafletCompWidth.tm_mouse_coordinates = function(comp, o) {
#' @method tmapLeafletLegPlot tm_mouse_coordinates
#' @export
tmapLeafletLegPlot.tm_mouse_coordinates = function(comp, lf, o) {
lf |> leafem::addMouseCoordinates()
lf %>% leafem::addMouseCoordinates()
}


6 changes: 3 additions & 3 deletions R/tmapLeafletLegend.R
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ tmapLeaflet_legend = function(cmp, lf, o, orientation) {
cmp$tr$rev(x2)
}

lf |> leaflegend::addLegendNumeric(position=legpos,
lf %>% leaflegend::addLegendNumeric(position=legpos,
orientation = orientation,
group = group,
height = {if (orientation == "horizontal") 20 else 200},
Expand Down Expand Up @@ -201,7 +201,7 @@ tmapLeaflet_legend = function(cmp, lf, o, orientation) {



lf |> leaflegend::addLegendImage(symbols$iconUrl,
lf %>% leaflegend::addLegendImage(symbols$iconUrl,
labels = lab,
width = symbols$iconWidth,
height = symbols$iconHeight,
Expand All @@ -215,7 +215,7 @@ tmapLeaflet_legend = function(cmp, lf, o, orientation) {
className = leg_className)
}
backg <- htmltools::tags$style(paste0("#", layerId, " { background: ", substr(cmp$bg.color,1,7), "; opacity: ", cmp$bg.alpha, "}"))
lf2 |> htmlwidgets::prependContent(backg)
lf2 %>% htmlwidgets::prependContent(backg)

}

Expand Down
6 changes: 3 additions & 3 deletions R/tmapLeafletShape.R
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
tmapLeafletShape = function(bbx, facet_row, facet_col, facet_page, o) {
bbx = unname(bbx)
get_lf(facet_row, facet_col, facet_page) |>
leaflet::fitBounds(bbx[1], bbx[2], bbx[3], bbx[4]) |>
view_set_bounds(bbx, o) |>
get_lf(facet_row, facet_col, facet_page) %>%
leaflet::fitBounds(bbx[1], bbx[2], bbx[3], bbx[4]) %>%
view_set_bounds(bbx, o) %>%
assign_lf(facet_row, facet_col, facet_page)
NULL
}
Expand Down
38 changes: 19 additions & 19 deletions R/tmapLeaflet_layers.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ tmapLeafletPolygons = function(shpTM, dt, pdt, popup.format, hdt, idt, gp, bbx,
shp3 = suppressWarnings(sf::st_cast(shp2, "POLYGON"))
gp3 = lapply(gp, function(gpi) {if (length(gpi) == 1) gpi else gpi[shp3$id]})
popups2 = popups[shp3$id]
lf |>
leafgl::addGlPolygons(data = shp3, color = gp3$col, opacity = gp3$col_alpha, fillColor = gp3$fill, fillOpacity = gp3$fill_alpha, weight = gp3$lwd, group = group, pane = pane, popup = popups2) |>
lf %>%
leafgl::addGlPolygons(data = shp3, color = gp3$col, opacity = gp3$col_alpha, fillColor = gp3$fill, fillOpacity = gp3$fill_alpha, weight = gp3$lwd, group = group, pane = pane, popup = popups2) %>%
assign_lf(facet_row, facet_col, facet_page)
} else {
lf |>
leaflet::addPolygons(data = shp, layerId = idt, label = hdt, color = gp$col, opacity = gp$col_alpha, fillColor = gp$fill, fillOpacity = gp$fill_alpha, weight = gp$lwd, options = opt, group = group, dashArray = lty2dash(gp$lty), popup = popups) |>
lf %>%
leaflet::addPolygons(data = shp, layerId = idt, label = hdt, color = gp$col, opacity = gp$col_alpha, fillColor = gp$fill, fillOpacity = gp$fill_alpha, weight = gp$lwd, options = opt, group = group, dashArray = lty2dash(gp$lty), popup = popups) %>%
assign_lf(facet_row, facet_col, facet_page)
}
NULL
Expand Down Expand Up @@ -83,12 +83,12 @@ tmapLeafletLines = function(shpTM, dt, pdt, popup.format, hdt, idt, gp, bbx, fac
shp2 = sf::st_sf(id = 1:length(shp), geom = shp)
shp3 = suppressWarnings(sf::st_cast(shp2, "LINESTRING"))
gp3 = lapply(gp, function(gpi) {if (length(gpi) == 1) gpi else gpi[shp3$id]})
lf |>
leafgl::addGlPolylines(data = shp3, color = gp3$col, opacity = gp3$col_alpha, weight = gp3$lwd, pane = pane, group = group) |>
lf %>%
leafgl::addGlPolylines(data = shp3, color = gp3$col, opacity = gp3$col_alpha, weight = gp3$lwd, pane = pane, group = group) %>%
assign_lf(facet_row, facet_col, facet_page)
} else {
lf |>
leaflet::addPolylines(data = shp, layerId = idt, label = hdt, color = gp$col, opacity = gp$col_alpha, weight = gp$lwd, group = group, options = opt, dashArray = lty2dash(gp$lty), popup = popups) |>
lf %>%
leaflet::addPolylines(data = shp, layerId = idt, label = hdt, color = gp$col, opacity = gp$col_alpha, weight = gp$lwd, group = group, options = opt, dashArray = lty2dash(gp$lty), popup = popups) %>%
assign_lf(facet_row, facet_col, facet_page)

}
Expand Down Expand Up @@ -129,7 +129,7 @@ tmapLeafletSymbols = function(shpTM, dt, pdt, popup.format, hdt, idt, gp, bbx, f
if (o$use.WebGL) {
vary = vapply(dt, function(x)any(x!=x[1]), FUN.VALUE = logical(1))[c("col", "shape", "lwd", "lty", "fill_alpha", "col_alpha")]
if (any(vary)) warning("WegGL enabled: the only supported visual variables are: fill and size. The visual variable(s) ", paste(names(vary)[vary], collapse = ", "), " are not supported. Disable WebGL to show them.", call. = FALSE)
lf |> leafgl::addGlPoints(sf::st_sf(shp), fillColor = gp2$fillColor, radius = gp2$width, fillOpacity = gp2$fillOpacity[1], pane = pane, group = group) |>
lf %>% leafgl::addGlPoints(sf::st_sf(shp), fillColor = gp2$fillColor, radius = gp2$width, fillOpacity = gp2$fillOpacity[1], pane = pane, group = group) %>%
assign_lf(facet_row, facet_col, facet_page)
} else {

Expand Down Expand Up @@ -160,20 +160,20 @@ tmapLeafletSymbols = function(shpTM, dt, pdt, popup.format, hdt, idt, gp, bbx, f
}
}

lf |> leaflet::addMarkers(lng = coords[, 1], lat = coords[, 2],
icon = symbols, group = group, layerId = idt, label = hdt, popup = popups) |>
lf %>% leaflet::addMarkers(lng = coords[, 1], lat = coords[, 2],
icon = symbols, group = group, layerId = idt, label = hdt, popup = popups) %>%
assign_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) |>
# 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) |>
# 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)
# }

Expand Down Expand Up @@ -247,8 +247,8 @@ tmapLeafletRaster = function(shpTM, dt, gp, pdt, popup.format, hdt, idt, bbx, fa

lf = get_lf(facet_row, facet_col, facet_page)

lf |>
leafem::addStarsImage(shp2, band = 1, colors = pal_col, opacity = pal_opacity, group = group) |>
lf %>%
leafem::addStarsImage(shp2, band = 1, colors = pal_col, opacity = pal_opacity, group = group) %>%
assign_lf(facet_row, facet_col, facet_page)
} else {
#shp2 = st_as_stars(list(values = tmapID), dimensions = shp)
Expand Down Expand Up @@ -330,7 +330,7 @@ tmapLeafletText = function(shpTM, dt, gp, bbx, facet_row, facet_col, facet_page,


if (!vary) {
lf = lf |> addLabelOnlyMarkers(lng = coords[, 1], lat = coords[,2],
lf = lf %>% addLabelOnlyMarkers(lng = coords[, 1], lat = coords[,2],
label=text,
group=group,
#layerId = ids,
Expand All @@ -344,7 +344,7 @@ tmapLeafletText = function(shpTM, dt, gp, bbx, facet_row, facet_col, facet_page,
options = markerOptions(pane = pane))
} else {
for (i in 1:length(text)) {
lf = lf |> addLabelOnlyMarkers(lng = coords[i,1], lat = coords[i,2],
lf = lf %>% addLabelOnlyMarkers(lng = coords[i,1], lat = coords[i,2],
label=text[i],
group=group,
#layerId = ids[i],
Expand Down
2 changes: 1 addition & 1 deletion R/tmapShape.R
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ tmapShape.SpatRaster = function(shp, is.main, crs, bbox, unit, filter, shp_name,

names(ctabs) = dtcols
names(cats) = dtcols

# tmf not defined?
make_by_vars(dt, tmf, smeta)

if (is.null(filter)) filter = rep(TRUE, nrow(dt))
Expand Down

0 comments on commit 3cf87ae

Please sign in to comment.