Skip to content

Commit

Permalink
fixed part of revdev issues #908
Browse files Browse the repository at this point in the history
  • Loading branch information
mtennekes committed Oct 24, 2024
1 parent 87f2041 commit ddeb257
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 43 deletions.
32 changes: 15 additions & 17 deletions R/tm_facets.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
#' @param columns Variable that specifies the columns (only for a facet grid)
#' @param pages Variable that specifies the pages (only for a facet grid)
#' @param as.layers show facets as layers?
#' @param nrows Number of rows
#' @param ncols Number of columns
#' @param nrow Number of rows
#' @param ncol Number of columns
#' @param byrow Should facets be wrapped by row?
#' @param orientation For facet stack: horizontal or vertical?
#' @param free.coords Logical. If the `by` argument is specified, should each
Expand Down Expand Up @@ -53,8 +53,8 @@ tm_facets = function(by = NULL,
columns = NULL,
pages = NULL,
as.layers = FALSE,
nrows = NA,
ncols = NA,
nrow = NA,
ncol = NA,
byrow = TRUE,
orientation = NA,
free.coords = NA,
Expand All @@ -77,11 +77,9 @@ tm_facets = function(by = NULL,
v3_start_message()

v3_list_init()
drop.empty.facets = v3_impute(args, "showNA", NA, paste0("drop.empty.facets = ", !args$showNA))
drop.empty.facets = v3_impute(args, "showNA", TRUE, paste0("drop.empty.facets = ", !args$showNA))
na.text = v3_impute(args, "textNA", NA, "na.text")
ncols = v3_impute(args, "ncol", NA, "ncols")
nrows = v3_impute(args, "nrow", NA, "nrows")
drop.units = v3_impute(args, "drop.shapes", NA, "drop.units")
drop.units = v3_impute(args, "drop.shapes", TRUE, "drop.units")
v3_tm_facets(arg_list = v3_list_get())

if (any(substr(names(args), 1, 12) == "free.scales.")) {
Expand Down Expand Up @@ -117,8 +115,8 @@ tm_facets = function(by = NULL,
columns = columns,
as.layers = as.layers,
pages = pages,
nrows = nrows,
ncols = ncols,
nrows = nrow,
ncols = ncol,
orientation = orientation,
free.coords = free.coords,
drop.units = drop.units,
Expand Down Expand Up @@ -157,27 +155,27 @@ tm_facets_grid = function(rows = NULL,
#' @param ... passed on to `tm_facets()`
#' @name tm_facets_wrap
tm_facets_wrap = function(by = "VARS__",
nrows = NA,
ncols = NA,
nrow = NA,
ncol = NA,
byrow = TRUE,
...) {
args = list(...)
calls = names(match.call(expand.dots = TRUE)[-1])
tm = do.call("tm_facets", c(list(by = by, nrows = nrows, ncols = ncols, byrow = byrow, type = "wrap"), args[setdiff(names(args), "type")]))
tm = do.call("tm_facets", c(list(by = by, nrow = nrow, ncol = ncol, byrow = byrow, type = "wrap"), args[setdiff(names(args), "type")]))
tm[[1]]$calls = calls
tm
}

#' @export
#' @rdname tm_facets
tm_facets_pagewise = function(by = "VARS__",
nrows = 1,
ncols = 1,
nrow = 1,
ncol = 1,
byrow = TRUE,
...) {
args = list(...)
calls = unique(c(names(match.call(expand.dots = TRUE)[-1]), "nrows", "ncols"))
tm = do.call("tm_facets", c(list(by = by, nrows = nrows, ncols = ncols, byrow = byrow, type = "page"), args[setdiff(names(args), "type")]))
calls = unique(c(names(match.call(expand.dots = TRUE)[-1]), "nrow", "ncol"))
tm = do.call("tm_facets", c(list(by = by, nrow = nrow, ncol = ncol, byrow = byrow, type = "page"), args[setdiff(names(args), "type")]))
tm[[1]]$calls = calls
tm
}
Expand Down
50 changes: 32 additions & 18 deletions R/tm_layout.R
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# NEED TO SYNC THIS WITH tmap_options
# generate all options with:
# generate all options with:
# args = intersect(names(tmap_options_mode("view")),names(tmap_options_mode("plot")))
# cat(paste(args, collapse = ", "))


#' Layout options
#'
#'
#' Set of tmap options that are directly related to the layout.
#'
#'
#' @param modes,crs,facet.max,facet.flip,raster.max.cells,show.messages,show.warnings,output.format,output.size,output.dpi,output.dpi.animation,value.const,value.na,value.null,value.blank,values.var,values.range,value.neutral,scales.var,scale.misc.args See [tmap_options()]
#' @param label.format,label.na,scale,asp,bg.color,outer.bg.color,frame,frame.lwd,frame.r,frame.double.line,outer.margins,inner.margins,inner.margins.extra,meta.margins,meta.auto.margins,between.margin,component.offset,component.stack.margin See [tmap_options()]
#' @param grid.mark.height,xylab.height,coords.height,xlab.show,xlab.text,xlab.size,xlab.color,xlab.rotation,xlab.space,xlab.fontface,xlab.fontfamily,xlab.side,ylab.show,ylab.text,ylab.size,ylab.color,ylab.rotation,ylab.space,ylab.fontface,ylab.fontfamily,ylab.side See [tmap_options()]
Expand All @@ -22,9 +22,9 @@
#' @param earth.boundary,earth.boundary.color,earth.boundary.lwd,earth.datum,space.color,attr.color,max.categories,legend.hist.bg.color,legend.hist.bg.alpha,legend.hist.size,legend.hist.height,legend.hist.width,attr.outside,attr.outside.position,attr.outside.size,attr.position,attr.just,basemap.server,basemap.alpha,basemap.zoom,overlays,overlays.alpha,alpha,colorNA,symbol.size.fixed,dot.size.fixed,text.size.variable,bbox,check.and.fix,set.bounds,set.view,set.zoom.limits,name,basemap.show See [tmap_options()]
#' @param title,main.title deprecated See [tm_title()]
#' @param ... used to catch other deprecated arguments
#' @example ./examples/tm_layout.R
#' @example ./examples/tm_layout.R
#' @name tm_layout
#' @export
#' @export
tm_layout = function(
modes, crs, facet.max, facet.flip,
raster.max.cells, show.messages, show.warnings,
Expand Down Expand Up @@ -84,30 +84,36 @@ tm_layout = function(
text.size.variable, bbox, check.and.fix, set.bounds, set.view, set.zoom.limits, name, basemap.show,
title = NULL,
main.title = NULL,
view.legend.position = NULL,
...

) {
args = lapply(as.list(match.call()[-1]), eval, envir = parent.frame())

fun = if ("called_from" %in% names(args)) {
args$called_from
} else {
"tm_layout"
}

if (!missing(modes) && is.character(modes)) {
title = modes
args$modes = NULL
}


if (!is.null(view.legend.position)) {
args$legend.position = args$view.legend.position
args$legend.position = NULL
}

if (!is.null(title) || (!is.null(main.title))) {
title1 = if (!is.null(title)) {
title.args = args[substr(names(args), 1, 5) == "title"]
title.args$title = NULL
names(title.args) = substr(names(title.args), 7, nchar(names(title.args)))

v3_title(fun)

if (!("position" %in% names(title.args))) title.args$position = tm_pos_in("left", "top")
args$title = NULL
do.call(tm_title, c(list(text = title), title.args))
Expand All @@ -134,9 +140,9 @@ tm_layout = function(
}

#' View mode options
#'
#'
#' View mode options. These options are specific to the view mode.
#'
#'
#' @param use.WebGL use webGL layers with leafgl
#' @param control.position position of the control attribute
#' @param control.bases base layers
Expand All @@ -146,29 +152,37 @@ tm_layout = function(
#' In view mode, this is passed on to [setMaxBounds()][leaflet::setMaxBounds()]
#' @param set.view numeric vector that determines the view.
#' Either a vector of three: `lng`, `lat`, and `zoom`, or a single value:
#' `zoom`. See [setView()][leaflet::setView()].
#' `zoom`. See [setView()][leaflet::setView()].
#' Only applicable if `bbox` is not specified
#' @param set.zoom.limits numeric vector of two that set the minimum and maximum
#' zoom levels (see [tileOptions()][leaflet::tileOptions()]).
#' @param leaflet.options options passed on to
#' [leafletOptions()][leaflet::leafletOptions()]
#' @param view.legend.position deprecated. Use `legend.position`from `tm_layout()` instead.
#' @export
tm_view = function(use.WebGL,
control.position,
control.position,
control.bases,
control.overlays,
set.bounds,
set.view,
set.zoom.limits,
leaflet.options) {
leaflet.options,
view.legend.position = NULL) {
args = lapply(as.list(match.call()[-1]), eval, envir = parent.frame())

if (!is.null(view.legend.position)) {
args$legend.position = view.legend.position
args$view.legend.position = NULL
}

do.call(tm_options, args)
}

#' Plot mode options
#'
#'
#' Plot mode options. This option is specific to the plot mode.
#'
#'
#' @param use.gradient Use gradient fill using [linearGradient()][grid::linearGradient()]
#' @export
tm_plot = function(use.gradient) {
Expand Down
5 changes: 4 additions & 1 deletion R/tmap_options.R
Original file line number Diff line number Diff line change
Expand Up @@ -618,7 +618,10 @@ tmapMode = function(id, name, ...) {
tiles.alpha = 1,
tiles.zoom = NA,

attr.color = "black"
attr.color = "black",

# not in tmap4 -> backward comp?
view.legend.position = NA
),
style = "white",
specified = character()
Expand Down
12 changes: 6 additions & 6 deletions man/tm_facets.Rd

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

1 change: 1 addition & 0 deletions man/tm_layout.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_view.Rd

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

0 comments on commit ddeb257

Please sign in to comment.