Skip to content

Commit

Permalink
Merge pull request #824 from olivroy/doc
Browse files Browse the repository at this point in the history
Fix tm_text docs + update roxygenNote
  • Loading branch information
mtennekes authored Feb 6, 2024
2 parents 4bf91df + 957b0c1 commit a407842
Show file tree
Hide file tree
Showing 17 changed files with 95 additions and 79 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@ jobs:
- {os: macos-latest, r: 'release'}
- {os: windows-latest, r: 'release'}
- {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'}
- {os: ubuntu-latest, r: 'release'}
- {os: ubuntu-latest, r: 'oldrel-1'}

env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
R_KEEP_PKG_SOURCE: yes

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- uses: r-lib/actions/setup-pandoc@v2

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/pkgdown.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
permissions:
contents: write
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- uses: r-lib/actions/setup-pandoc@v2

Expand All @@ -41,7 +41,7 @@ jobs:

- name: Deploy to GitHub pages 🚀
if: github.event_name != 'pull_request'
uses: JamesIves/github-pages-deploy-action@v4.4.1
uses: JamesIves/github-pages-deploy-action@v4.5.0
with:
clean: false
branch: gh-pages
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/test-coverage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- uses: r-lib/actions/setup-r@v2
with:
Expand All @@ -31,7 +31,7 @@ jobs:
covr::codecov(
quiet = FALSE,
clean = FALSE,
install_path = file.path(Sys.getenv("RUNNER_TEMP"), "package")
install_path = file.path(normalizePath(Sys.getenv("RUNNER_TEMP"), winslash = "/"), "package")
)
shell: Rscript {0}

Expand All @@ -44,7 +44,7 @@ jobs:

- name: Upload test results
if: failure()
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: coverage-test-failures
path: ${{ runner.temp }}/package
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.3.0
RoxygenNote: 7.3.1
4 changes: 4 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,15 @@ S3method(tmapLeafletCompWidth,tm_scalebar)
S3method(tmapLeafletCompWidth,tm_title)
S3method(tmapLeafletLegPlot,tm_compass)
S3method(tmapLeafletLegPlot,tm_credits)
S3method(tmapLeafletLegPlot,tm_legend_standard_landscape)
S3method(tmapLeafletLegPlot,tm_legend_standard_portrait)
S3method(tmapLeafletLegPlot,tm_mouse_coordinates)
S3method(tmapLeafletLegPlot,tm_scalebar)
S3method(tmapLeafletLegPlot,tm_title)
S3method(tmapReproject,dimensions)
S3method(tmapReproject,sfc)
S3method(tmapReproject,stars)
S3method(tmapShape,Raster)
S3method(tmapShape,SpatRaster)
S3method(tmapShape,sf)
S3method(tmapShape,stars)
Expand Down Expand Up @@ -223,6 +226,7 @@ importFrom(grDevices,dev.size)
importFrom(grDevices,png)
importFrom(grDevices,rgb)
importFrom(htmlwidgets,saveWidget)
importFrom(leaflet,providers)
importFrom(rlang,expr)
importFrom(rlang,missing_arg)
importFrom(utils,browseURL)
4 changes: 4 additions & 0 deletions R/tm_layers_text.R
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@
#' groups can be switched on and off. Options: `"radio"` for radio buttons
#' (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 bgcol,bgcol.scale,bgcol.legend,bgcol.free Visual variable that determines
#' the background color. See Details.
#' @param bgcol_alpha,bgcol_alpha.scale,bgcol_alpha.legend,bgcol_alpha.free Visual variable that determines
#' the background color transparency. See Details.
#' @param ... to catch deprecated arguments from version < 4.0
#' @example ./examples/tm_text.R
#' @export
Expand Down
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()
}


9 changes: 5 additions & 4 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,15 +215,16 @@ 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)

}


#' @export
tmapLeafletLegPlot.tm_legend_standard_portrait = function(cmp, lf, o) {
tmapLeaflet_legend(cmp, lf, o, orientation = "vertical")
}

#' @export
tmapLeafletLegPlot.tm_legend_standard_landscape = function(cmp, lf, o) {
tmapLeaflet_legend(cmp, lf, o, orientation = "horizontal")
}
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
4 changes: 3 additions & 1 deletion R/tmapShape.R
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ tmapShape = function(shp, is.main, crs, bbox, unit, filter, shp_name, smeta, o,
}



#' @export
tmapShape.Raster = function(shp, is.main, crs, bbox, unit, filter, shp_name, smeta, o, tmf) {
tmapShape.SpatRaster(terra::rast(shp), is.main, crs, bbox, unit, filter, shp_name, smeta, o, tmf)
}
Expand Down Expand Up @@ -133,8 +133,10 @@ tmapShape.SpatRaster = function(shp, is.main, crs, bbox, unit, filter, shp_name,

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


if (!is.null(tmf)) make_by_vars(dt, tmf, smeta)


if (is.null(filter)) filter = rep(TRUE, nrow(dt))
dt[, ':='(sel__ = filter)] # tmapID__ = 1L:nrow(dt),
Expand Down
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
# tmap: thematic maps in R <img src="man/figures/logo.png" align="right" height="139" alt="" />

<!-- badges: start -->
[![R CMD CHECK](https://github.com/r-tmap/tmap/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/r-tmap/tmap/actions/workflows/R-CMD-check.yaml)
[![R-CMD-check](https://github.com/r-tmap/tmap/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/r-tmap/tmap/actions/workflows/R-CMD-check.yaml)
[![Codecov test coverage](https://codecov.io/gh/r-tmap/tmap/branch/master/graph/badge.svg)](https://app.codecov.io/gh/r-tmap/tmap?branch=master)
[![CRAN](http://www.r-pkg.org/badges/version/tmap)](https://cran.r-project.org/package=tmap)
[![CRAN checks](https://cranchecks.info/badges/worst/tmap)](https://cran.r-project.org/web/checks/check_results_tmap.html)
[![Downloads](http://cranlogs.r-pkg.org/badges/tmap?color=brightgreen)](https://www.r-pkg.org:443/pkg/tmap)
[![License](https://img.shields.io/badge/License-GPL%20v3-brightgreen.svg?style=flat)](http://www.gnu.org/licenses/gpl-3.0.html)
[![r-universe](https://r-tmap.r-universe.dev/badges/tmap)](https://r-tmap.r-universe.dev/tmap)

<!-- badges: end -->


Expand Down
7 changes: 7 additions & 0 deletions man/tm_basemap.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion man/tm_facets.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit a407842

Please sign in to comment.