Skip to content

Commit

Permalink
Merge pull request #830 from olivroy/misc
Browse files Browse the repository at this point in the history
Misc edits
  • Loading branch information
mtennekes committed Feb 9, 2024
2 parents 5bc5644 + 2f10429 commit d5ff7c7
Show file tree
Hide file tree
Showing 20 changed files with 235 additions and 170 deletions.
3 changes: 3 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ S3method(tmapGridCompHeight,tm_scalebar)
S3method(tmapGridCompHeight,tm_title)
S3method(tmapGridCompPrepare,tm_compass)
S3method(tmapGridCompPrepare,tm_credits)
S3method(tmapGridCompPrepare,tm_legend_standard_landscape)
S3method(tmapGridCompPrepare,tm_legend_standard_portrait)
S3method(tmapGridCompPrepare,tm_mouse_coordinates)
S3method(tmapGridCompPrepare,tm_scalebar)
Expand Down Expand Up @@ -82,10 +83,12 @@ S3method(tmapReproject,sfc)
S3method(tmapReproject,stars)
S3method(tmapShape,Raster)
S3method(tmapShape,SpatRaster)
S3method(tmapShape,SpatVector)
S3method(tmapShape,sf)
S3method(tmapShape,stars)
S3method(tmapSplitShp,default)
S3method(tmapSplitShp,stars)
S3method(tmapSubsetShp,Raster)
S3method(tmapSubsetShp,SpatRaster)
S3method(tmapSubsetShp,SpatVector)
S3method(tmapSubsetShp,sf)
Expand Down
3 changes: 0 additions & 3 deletions R/print.R
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
#' Draw thematic map
#'
#' Draw thematic map.
#'
#' @param x tmap object.
#' @param return.asp should the aspect ratio be returned?
#' @param show show the map
#' @param vp viewport (for `"plot"` mode)
#' @param ... not used
#' @export
#' @method print tmap
print.tmap = function(x, return.asp = FALSE, show = TRUE, vp = NULL, ...) {
dev = getOption("tmap.devel.mode")
if (dev) timing_init()
Expand Down
20 changes: 8 additions & 12 deletions R/tm_components.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,32 @@
#'
#' @param text text of the title
#' @param size font size of the title
#' @param color color
#' @param color font color of the title
#' @param padding padding
#' @param fontface font face
#' @param fontface font face, bold, italic
#' @param fontfamily font family
#' @param stack stack
#' @param just just
#' @param frame frame
#' @param frame.lwd frame.lwd
#' @param frame.lwd frame line width
#' @param frame.r frame.r
#' @param bg.color bg.color
#' @param bg.alpha bg.alpha
#' @param bg.color Background color
#' @param bg.alpha Background transparency
#' @param position position
#' @param width width
#' @param height height
#' @param width,height width and height of the title box.
#' @param group.frame group.frame
#' @param resize.as.group resize.as.group
#' @param z z
#' @export
#' @rdname tm_title
#' @name tm_title
tm_title = function(text, size, color, padding, fontface, fontfamily, stack, just, frame, frame.lwd, frame.r, bg.color, bg.alpha, position, width, height, group.frame, resize.as.group, z) {
args = lapply(as.list(match.call()[-1]), eval, envir = parent.frame())
if (!("z" %in% names(args))) args$z = as.integer(NA)
tm_element_list(do.call(tm_element, c(args, list(subclass = c("tm_title", "tm_component")))))
}

#' @export
#' @param ... passed on to tm_title
#' @param ... passed on to `tm_title()`
#' @rdname tm_title
#' @name tm_title_in
tm_title_in = function(text, ..., position = tm_pos_in("left", "top")) {
args = lapply(as.list(match.call()[-1]), eval, envir = parent.frame())
if (!("z" %in% names(args))) args$z = as.integer(NA)
Expand Down Expand Up @@ -199,7 +195,7 @@ tm_scalebar = function(breaks,
#' @inheritDotParams tm_scalebar
#' @export
tm_scale_bar = function(...) {
warning("As of version 4.0, tm_scale_bar has been renamed to tm_scalebar and is therefore deprecated", call. = FALSE)
warning("As of version 4.0, 'tm_scale_bar()' is deprecated. Please use 'tm_scalebar()' instead.", call. = FALSE)
tm_scalebar(...)
# can also be
# stop("As of version 4.0, tm_scale_bar has been renamed to tm_scalebar and is therefore deprecated. tm_scalebar also has new argument names.", call. = FALSE)
Expand Down
7 changes: 1 addition & 6 deletions R/tm_element.R
Original file line number Diff line number Diff line change
Expand Up @@ -82,24 +82,19 @@ replace_last_tmap_by_correct_call = function(mc, lt) {



#' Print tm_element
#'
#' Print tm_element
#'
#' @param x x
#' @param ... passed on
#' @export
#' @method print tm_element
#' @rdname print.tm_element
#' @name print.tm_element
#' @keywords internal
print.tm_element = function(x, ...) {
cat("tm_element object\n")
str(x, 2)
}

#' @rdname print.tm_element
#' @name print.tm_shape
#' @method print tm_shape
#' @export
print.tm_shape = function(x, ...) {
NextMethod()
Expand Down
33 changes: 22 additions & 11 deletions R/tm_layers_aux.R
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,18 @@ tm_tiles = function(server = NULL, alpha = NULL, zoom = NULL, zindex = NA, group
#' @export
leaflet::providers

#' @name tm_graticules
#' @rdname tm_grid

#' Coordinate grid / graticule lines
#'
#' Draw latitude and longitude graticules. It creates a [`tmap-element`] that draws coordinate grid lines. It serves as a
#' layer that can be drawn anywhere between other layers. See [tm_grid()] for
#' drawing horizontal lines.
#'
#' @inheritParams tm_grid
#' @inheritDotParams tm_grid
#' @export
#' @example ./examples/tm_grid.R

tm_graticules = function(x = NA,
y = NA,
n.x = NA,
Expand All @@ -77,11 +86,13 @@ tm_graticules = function(x = NA,

#' Coordinate grid / graticule lines
#'
#' @description
#' * `tm_grid()` draws horizontal and vertical lines according to the
#' coordinate system of the (master) shape object.
#'
#' Creates a [`tmap-element`] that draws coordinate grid lines. It serves as a
#' layer that can be drawn anywhere between other layers.
#' By default, `tm_grid()` draws horizontal and vertical lines according to the
#' coordinate system of the (master) shape object. Latitude and longitude
#' graticules are drawn with `tm_graticules()`.
#' layer that can be drawn anywhere between other layers. See [tm_graticules()]
#' to draw latitude and longitude graticules.
#'
#' @param x X coordinates for vertical grid lines. If `NA`, it is specified
#' with a pretty scale and `n.x`.
Expand Down Expand Up @@ -130,16 +141,16 @@ tm_graticules = function(x = NA,
#' instead of using negative coordinates for west and south (so it assumes that
#' the coordinates are positive in the north-east direction).
#' @param labels.margin.x Margin between tick labels of x axis and the frame.
#' Note that when `labels.inside.frame == FALSE` and `ticks == TRUE`,
#' Note that when `labels.inside.frame = FALSE` and `ticks = TRUE`,
#' the ticks will be adjusted accordingly.
#' @param labels.margin.y Margin between tick labels of y axis and the frame.
#' Note that when `labels.inside.frame == FALSE` and `ticks == TRUE`,
#' Note that when `labels.inside.frame = FALSE` and `ticks = TRUE`,
#' the ticks will be adjusted accordingly.
#' @param labels.space.x Space that is used for the labels and ticks for the x-axis
#' when `labels.inside.frame == FALSE`. By default, it is determined automatically
#' when `labels.inside.frame = FALSE`. By default, it is determined automatically
#' using the widths and heights of the tick labels. The unit of this parameter is text line height.
#' @param labels.space.y Space that is used for the labels and ticks for the y-axis
#' when `labels.inside.frame == FALSE`. By default, it is determined automatically
#' when `labels.inside.frame = FALSE`. By default, it is determined automatically
#' using the widths and heights of the tick labels. The unit of this parameter is text line height.
#' @param labels.inside.frame Show labels inside the frame? By default `FALSE`.
#' @param ticks If `labels.inside.frame = FALSE`, should ticks can be drawn between the labels and the frame?
Expand All @@ -161,7 +172,7 @@ tm_graticules = function(x = NA,
#' 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 ... Arguments passed on to [tm_grid()]
#' @param ... Used to catch deprecated arguments from tmap v3.
#' @export
#' @example ./examples/tm_grid.R
tm_grid = function(x = NA,
Expand Down
11 changes: 0 additions & 11 deletions R/tmapGetShapeMeta.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ tmapGetShapeMeta2 = function(shp, smeta, o) {
}


#' @method tmapGetShapeMeta1 stars
#' @export
tmapGetShapeMeta1.stars = function(shp, o) {
d = stars::st_dimensions(shp)
Expand Down Expand Up @@ -54,14 +53,12 @@ tmapGetShapeMeta1.stars = function(shp, o) {
dims_vals = dims_vals)
}

#' @method tmapGetShapeMeta1 Raster
#' @export
tmapGetShapeMeta1.Raster = function(shp, o) {
tmapGetShapeMeta1.SpatRaster(terra::rast(shp), o)
}


#' @method tmapGetShapeMeta2 stars
#' @export
tmapGetShapeMeta2.stars = function(shp, smeta, o) {
smeta$vars_levs = lapply(seq_len(length(shp)), function(i) {
Expand All @@ -72,7 +69,6 @@ tmapGetShapeMeta2.stars = function(shp, smeta, o) {
}


#' @method tmapGetShapeMeta2 SpatRaster
#' @export
tmapGetShapeMeta2.SpatRaster = function(shp, smeta, o) {
if (terra::ncell(shp) > o$raster.max.cells) {
Expand All @@ -88,7 +84,6 @@ tmapGetShapeMeta2.SpatRaster = function(shp, smeta, o) {
smeta
}

#' @method tmapGetShapeMeta2 SpatVector
#' @export
tmapGetShapeMeta2.SpatVector = function(shp, smeta, o) {

Expand All @@ -101,7 +96,6 @@ tmapGetShapeMeta2.SpatVector = function(shp, smeta, o) {
}


#' @method tmapGetShapeMeta2 sf
#' @export
tmapGetShapeMeta2.sf = function(shp, smeta, o) {
vars = setdiff(names(shp), attr(shp, "sf_column"))
Expand All @@ -113,7 +107,6 @@ tmapGetShapeMeta2.sf = function(shp, smeta, o) {
}


#' @method tmapGetShapeMeta1 sf
#' @export
tmapGetShapeMeta1.sf = function(shp, o) {
vars = setdiff(names(shp), attr(shp, "sf_column"))
Expand All @@ -128,7 +121,6 @@ tmapGetShapeMeta1.sf = function(shp, o) {
}


#' @method tmapGetShapeMeta2 sfc
#' @export
tmapGetShapeMeta2.sfc = function(shp, smeta, o) {
vars = character(0)
Expand All @@ -137,7 +129,6 @@ tmapGetShapeMeta2.sfc = function(shp, smeta, o) {
}


#' @method tmapGetShapeMeta1 sfc
#' @export
tmapGetShapeMeta1.sfc = function(shp, o) {
vars = character(0)
Expand All @@ -153,7 +144,6 @@ tmapGetShapeMeta1.sfc = function(shp, o) {



#' @method tmapGetShapeMeta1 SpatRaster
#' @export
tmapGetShapeMeta1.SpatRaster = function(shp, o) {
vars = names(shp)
Expand All @@ -168,7 +158,6 @@ tmapGetShapeMeta1.SpatRaster = function(shp, o) {

}

#' @method tmapGetShapeMeta1 SpatVector
#' @export
tmapGetShapeMeta1.SpatVector = function(shp, o) {
vars = names(shp)
Expand Down
Loading

0 comments on commit d5ff7c7

Please sign in to comment.