Skip to content

Commit

Permalink
fixed #383 and added backward-comp with legend.hist
Browse files Browse the repository at this point in the history
  • Loading branch information
mtennekes committed Mar 7, 2024
1 parent c6ed554 commit 346bb91
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 22 deletions.
4 changes: 4 additions & 0 deletions R/tm_layers_lines.R
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,10 @@ tm_lines = function(col = tm_const(),

lwd.legend = do.call("tm_legend", lwd.legend.args)

if ("legend.hist" %in% names(args) && args$legend.hist) {
col.chart = tm_chart_histogram()
# to do: histogram title
}
}


Expand Down
9 changes: 7 additions & 2 deletions R/tm_layers_polygons.R
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ tm_polygons = function(fill = tm_const(),
fill.legend = tm_legend(),
fill.chart = tm_chart_none(),
fill.free = NA,
#fill.chart = tm_chart_none(),
col = tm_const(),
col.scale = tm_scale(),
col.legend = tm_legend(),
Expand Down Expand Up @@ -180,7 +179,7 @@ tm_polygons = function(fill = tm_const(),

fill.scale = do.call("tm_scale", args = fill.scale.args)

if ("col" %in% names(args_called) && (args_called$called_from != "fill")) {
if ("col" %in% names(args_called) && (is.null(args_called$called_from) || (args_called$called_from != "fill"))) {
fill = col
col = tm_const()
}
Expand All @@ -203,6 +202,12 @@ tm_polygons = function(fill = tm_const(),
reverse = imp("legend.reverse", FALSE))

fill.legend = do.call("tm_legend", fill.legend.args)

if ("legend.hist" %in% names(args) && args$legend.hist) {
fill.chart = tm_chart_histogram()
# to do: histogram title
}

}


Expand Down
5 changes: 5 additions & 0 deletions R/tm_layers_raster.R
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,11 @@ tm_raster = function(col = tm_shape_vars(),
reverse = imp("legend.reverse", FALSE))

col.legend = do.call("tm_legend", col.legend.args)

if ("legend.hist" %in% names(args) && args$legend.hist) {
col.chart = tm_chart_histogram()
# to do: histogram title
}
}

# needed for color maps without categories (then tm_scale_categorical is used without legend, unless called)
Expand Down
9 changes: 8 additions & 1 deletion R/tm_layers_symbols.R
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ tm_symbols = function(size = tm_const(),
size.legend = res$size.legend
shape.scale = res$shape.scale
shape.legend = res$shape.legend
fill.chart = res$fill.chart
}


Expand Down Expand Up @@ -388,6 +389,10 @@ v3_symbols = function(args, args_called) {

shape.legend = do.call("tm_legend", shape.legend.args)

if ("legend.hist" %in% names(args) && args$legend.hist) {
fill.chart = tm_chart_histogram()
# to do: histogram title
}

list(fill = fill,
col = col,
Expand All @@ -397,7 +402,8 @@ v3_symbols = function(args, args_called) {
size.scale = size.scale,
size.legend = size.legend,
shape.scale = shape.scale,
shape.legend = shape.legend)
shape.legend = shape.legend,
fill.chart = fill.chart)
} else {
NULL
}
Expand Down Expand Up @@ -454,6 +460,7 @@ tm_bubbles = function(size = tm_const(),
size.legend = res$size.legend
shape.scale = res$shape.scale
shape.legend = res$shape.legend
fill.chart = res$fill.chart
}

tm_element_list(tm_element(
Expand Down
33 changes: 25 additions & 8 deletions R/tm_layers_text.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@
#' own legend. For facet wraps and stacks ([tm_facets_wrap()] and [tm_facets_stack()])
#' there is only one facet dimension, so the `.free` argument requires only one logical value.
#'
#' @param text,text.scale,text.legend,text.free Visual variable that determines
#' @param text,text.scale,text.legend,text.chart,text.free Visual variable that determines
#' the text. See details.
#' @param size,size.scale,size.legend,size.free Visual variable that determines
#' @param size,size.scale,size.legend,size.chart,size.free Visual variable that determines
#' the font size. See details.
#' @param col,col.scale,col.legend,col.free Visual variable that determines
#' @param col,col.scale,col.legend,col.chart,col.free Visual variable that determines
#' the col color. See details.
#' @param col_alpha,col_alpha.scale,col_alpha.legend,col_alpha.free Visual variable that determines
#' @param col_alpha,col_alpha.scale,col_alpha.legend,col_alpha.chart,col_alpha.free Visual variable that determines
#' the border color alpha transparency. See Details.
#' @param fontface,fontface.scale,fontface.legend,fontface.free Visual variable that determines
#' @param fontface,fontface.scale,fontface.legend,fontface.chart,fontface.free Visual variable that determines
#' the font face. See Details.
#' @param fontfamily The font family. See [gpar()][grid::gpar()] for details.
#' @param shadow Shadow behind the text. Logical or color.
Expand All @@ -53,41 +53,48 @@
#' 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
#' @param bgcol,bgcol.scale,bgcol.legend,bgcol.chart,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
#' @param bgcol_alpha,bgcol_alpha.scale,bgcol_alpha.legend,bgcol_alpha.chart,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
tm_text = function(text = tm_const(),
text.scale = tm_scale(),
text.legend = tm_legend(),
text.chart = tm_chart_none(),
text.free = NA,
size = tm_const(),
size.scale = tm_scale(),
size.legend = tm_legend(),
size.chart = tm_chart_none(),
size.free = NA,
col = tm_const(),
col.scale = tm_scale(),
col.legend = tm_legend(),
col.chart = tm_chart_none(),
col.free = NA,
col_alpha = tm_const(),
col_alpha.scale = tm_scale(),
col_alpha.legend = tm_legend(),
col_alpha.chart = tm_chart_none(),
col_alpha.free = NA,
fontface = tm_const(),
fontface.scale = tm_scale(),
fontface.legend = tm_legend(),
fontface.chart = tm_chart_none(),
fontface.free = NA,
fontfamily = "",
bgcol = tm_const(),
bgcol.scale = tm_scale(),
bgcol.legend = tm_legend(),
bgcol.chart = tm_chart_none(),
bgcol.free = NA,
bgcol_alpha = tm_const(),
bgcol_alpha.scale = tm_scale(),
bgcol_alpha.legend = tm_legend(),
bgcol_alpha.chart = tm_chart_none(),
bgcol_alpha.free = NA,
shadow = FALSE,
plot.order = tm_plot_order("AREA", reverse = FALSE, na.order = "bottom"),
Expand Down Expand Up @@ -192,7 +199,10 @@ tm_text = function(text = tm_const(),
orientation = ifelse(imp("legend.size.is.portrait", TRUE), "portrait", "landscape"),
reverse = imp("legend.size.reverse", FALSE))


if ("legend.hist" %in% names(args) && args$legend.hist) {
col.chart = tm_chart_histogram()
# to do: histogram title
}

#}
}
Expand All @@ -208,36 +218,43 @@ tm_text = function(text = tm_const(),
value = text,
scale = text.scale,
legend = text.legend,
chart = text.chart,
free = text.free),
size = tmapScale(aes = "size",
value = size,
scale = size.scale,
legend = size.legend,
chart = size.chart,
free = size.free),
col = tmapScale(aes = "col",
value = col,
scale = col.scale,
legend = col.legend,
chart = col.chart,
free = col.free),
col_alpha = tmapScale(aes = "col_alpha",
value = col_alpha,
scale = col_alpha.scale,
legend = col_alpha.legend,
chart = col_alpha.chart,
free = col_alpha.free),
bgcol = tmapScale(aes = "bgcol",
value = bgcol,
scale = bgcol.scale,
legend = bgcol.legend,
chart = bgcol.chart,
free = bgcol.free),
bgcol_alpha = tmapScale(aes = "bgcol_alpha",
value = bgcol_alpha,
scale = bgcol_alpha.scale,
legend = bgcol_alpha.legend,
chart = bgcol_alpha.chart,
free = bgcol_alpha.free),
fontface = tmapScale(aes = "fontface",
value = fontface,
scale = fontface.scale,
legend = fontface.legend,
chart = fontface.chart,
free = fontface.free)),

gpar = tmapGpar(fill = NA,
Expand Down
8 changes: 4 additions & 4 deletions R/tmapScaleRGB.R
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ tmapScaleRGB = function(x1, x2, x3, scale, legend, chart, o, aes, layer, layer_a
}


tmapScaleAsIs = function(x1, scale, legend, o, aes, layer, layer_args, sortRev, bypass_ord, submit_legend = TRUE) {
tmapScaleAsIs = function(x1, scale, legend, chart, o, aes, layer, layer_args, sortRev, bypass_ord, submit_legend = TRUE) {
legend = list(title = NA,
nitems = 0,
labels = NA,
Expand All @@ -67,11 +67,11 @@ tmapScaleAsIs = function(x1, scale, legend, o, aes, layer, layer_args, sortRev,

if (submit_legend) {
if (bypass_ord) {
format_aes_results(values, legend = legend)
format_aes_results(values, legend = legend, chart = chart)
} else {
format_aes_results(values, ord = 1L, legend = legend)
format_aes_results(values, ord = 1L, legend = legend, chart = chart)
}
} else {
list(vals = values, ids = 1L, legend = legend, bypass_ord = bypass_ord)
list(vals = values, ids = 1L, legend = legend, chart = chart, bypass_ord = bypass_ord)
}
}
21 changes: 14 additions & 7 deletions man/tm_text.Rd

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

1 comment on commit 346bb91

@mtennekes
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.