Skip to content

Commit

Permalink
tmapMode added
Browse files Browse the repository at this point in the history
  • Loading branch information
mtennekes committed Apr 19, 2024
1 parent 14b907c commit 944fa94
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 9 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ export(tm_ylab)
export(tmapAddLayerOptions)
export(tmapGetShapeMeta1)
export(tmapGetShapeMeta2)
export(tmapMode)
export(tmapOutput)
export(tmapProxy)
export(tmapShape)
Expand Down
4 changes: 2 additions & 2 deletions R/process_meta.R
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ process_meta = function(o, d, cdt, aux) {
between.marginW = between.margin * lineW

fixedMargins = outer.margins + meta.buffers * 2 + meta.margins + xylab.margins + panel.xtab.size + grid.buffers + grid.margins
} else if (gs == "Leaflet") {
} else { #if (gs == "Leaflet") {
grid.buffers = rep(0, 4)
grid.margins = rep(0, 4)
fixedMargins = rep(0, 4)
Expand Down Expand Up @@ -336,7 +336,7 @@ process_meta = function(o, d, cdt, aux) {
}
}
}
} else if (gs == "Leaflet") {
} else { #if (gs == "Leaflet") {
orientation = if ((n == 1 && (pasp > masp)) || (n > 1 && (pasp < masp))) "horizontal" else "vertical"
}

Expand Down
4 changes: 2 additions & 2 deletions R/step4_plot.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ process_components = function(cdt, o) {
}


if (gs == "Leaflet") {
if (gs != "Grid") {
cdt[class == "out", class := "in"]
cdt[class == "autoout", class := "in"]
}
Expand Down Expand Up @@ -442,7 +442,7 @@ step4_plot = function(tm, vp, return.asp, show, knit, args) {
if (!o$legend.only) {
# workaround to move panels to titles in view mode
# TO DO: make this generic (e.g. component prep function?)
if (gs == "Leaflet") {
if (gs != "Grid") {
if (o$panel.type != "none") {
cdt = rbindlist(c(list(cdt), mapply(function(lab, i) {
data.table::data.table(by1__ = i,
Expand Down
2 changes: 1 addition & 1 deletion R/tmap_mode.R
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ tmap_mode = function(mode = NULL) {
if (is.null(mode)) {
message("current tmap mode is \"", current.mode, "\"")
} else {
if (!mode %in% modes) stop("Unknown mode. Available modes:", paste(modes, collapse = ", "))
if (!mode %in% modes) stop("Unknown mode. Available modes: ", paste(modes, collapse = ", "))
options(tmap.mode=mode)
if (show.messages) message("tmap mode set to '", mode, "'")
}
Expand Down
21 changes: 19 additions & 2 deletions R/tmap_options.R
Original file line number Diff line number Diff line change
@@ -1,9 +1,25 @@
#' Internal method for submitting a new mode
#'
#' Internal method for submitting a new mode
#'
#' @param id id of the mode: please use lowercase and one-word. This will be used with [tmap_mode()].
#' @param name name of the mode: please use title case. This will be used to recognize internal functions, e.g. `tmapLeafletInit`
#' @param ... mode specific options
#' @export
#' @keywords internal
tmapMode = function(id, name, ...) {
modes = tmap_options("modes")$modes

modes[[id]] = c(list(name = name), list(...))
tmap_options(modes = modes)
}


.defaultTmapOptions = structure(
list(
# mode specific options or default values
modes = list(plot = list(name = "Grid",
use.gradient = FALSE,
basemap.show = FALSE),
use.gradient = FALSE),
view = list(name = "Leaflet",
use.WebGL = FALSE,
legend.position = tm_pos_in(pos.h = "right", pos.v = "bottom", align.h = "left", align.v = "top", just.h = "left", just.v = "bottom"),
Expand Down Expand Up @@ -573,6 +589,7 @@
attr.outside.size = NA,
attr.position = c("right", "bottom"),
attr.just = c("left", "bottom"),
basemap.show = FALSE,
basemap.server = c("Esri.WorldGrayCanvas", "OpenStreetMap", "Esri.WorldTopoMap"),
basemap.alpha = 1,
basemap.zoom = NA,
Expand Down
3 changes: 3 additions & 0 deletions man/qtm.Rd

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

2 changes: 1 addition & 1 deletion man/tm_lines.Rd

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

2 changes: 1 addition & 1 deletion man/tm_polygons.Rd

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

19 changes: 19 additions & 0 deletions man/tmapMode.Rd

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

0 comments on commit 944fa94

Please sign in to comment.