Skip to content

Commit

Permalink
done #797
Browse files Browse the repository at this point in the history
  • Loading branch information
mtennekes committed Oct 18, 2023
1 parent f0f00d6 commit 3e6ad93
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 28 deletions.
5 changes: 1 addition & 4 deletions R/tmapScaleBivariate.R
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,7 @@ tmapScaleBivariate = function(x1, x2, scale, legend, o, aes, layer, layer_args,
vals = res[[1]]$vid + (res[[2]]$vid - 1L) * n1

with(scale, {
fun_check = paste0("tmapValuesCheck_", aes)

are_valid = do.call(fun_check, args = list(x = values))
if (!are_valid) stop("Incorrect values for layer ", layer, ", aesthetic ", aes, "; values should conform aes ", aes, call. = FALSE)
check_values(layer, aes, values)

fun_getBVV = paste0("tmapValuesBVV_", aes)
VV = do.call(fun_getBVV, list(x = values, value.na = value.na, m = n1, n = n2, scale = values.scale * o$scale, rep = values.repeat, o = o))
Expand Down
3 changes: 2 additions & 1 deletion R/tmapScaleCategorical.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ tmapScaleCategorical = function(x1, scale, legend, o, aes, layer, layer_args, so
show.warnings <- o$show.warnings

with(scale, {

check_values(layer, aes, values)

nms = names(values) #color_names

# cast to factor if needed
Expand Down
5 changes: 1 addition & 4 deletions R/tmapScaleContinuous.R
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,7 @@ tmapScaleContinuous = function(x1, scale, legend, o, aes, layer, layer_args, sor
if (length(values.range) == 1 && !is.na(values.range[1])) values.range = c(0, values.range)


fun_check = paste0("tmapValuesCheck_", aes)

are_valid = do.call(fun_check, args = list(x = values))
if (!are_valid) stop("Incorrect values for layer ", layer, ", aesthetic ", aes, "; values should conform aes ", aes, call. = FALSE)
check_values(layer, aes, values)

fun_isdiv = paste0("tmapValuesIsDiv_", aes)

Expand Down
5 changes: 1 addition & 4 deletions R/tmapScaleDiscrete.R
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,7 @@ tmapScaleDiscrete = function(x1, scale, legend, o, aes, layer, layer_args, sortR

d_isdiv = rng[1] < 0 && rng[2] > 0

fun_check = paste0("tmapValuesCheck_", aes)

are_valid = do.call(fun_check, args = list(x = values))
if (!are_valid) stop("Incorrect values for layer ", layer, ", aesthetic ", aes, "; values should conform aes ", aes, call. = FALSE)
check_values(layer, aes, values)

fun_isdiv = paste0("tmapValuesIsDiv_", aes)

Expand Down
5 changes: 1 addition & 4 deletions R/tmapScaleIntervals.R
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,7 @@ tmapScaleIntervals = function(x1, scale, legend, o, aes, layer, layer_args, sort
}
if (length(values.range) == 1 && !is.na(values.range[1])) values.range = c(0, values.range)

fun_check = paste0("tmapValuesCheck_", aes)

are_valid = do.call(fun_check, args = list(x = values))
if (!are_valid) stop("Incorrect values for layer ", layer, ", aesthetic ", aes, "; values should conform aes ", aes, call. = FALSE)
check_values(layer, aes, values)

fun_isdiv = paste0("tmapValuesIsDiv_", aes)

Expand Down
5 changes: 1 addition & 4 deletions R/tmapScaleRank.R
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,7 @@ tmapScaleRank = function(x1, scale, legend, o, aes, layer, layer_args, sortRev,
if (length(values.range) == 1 && !is.na(values.range[1])) values.range = c(0, values.range)


fun_check = paste0("tmapValuesCheck_", aes)

are_valid = do.call(fun_check, args = list(x = values))
if (!are_valid) stop("Incorrect values for layer ", layer, ", aesthetic ", aes, "; values should conform aes ", aes, call. = FALSE)
check_values(layer, aes, values)

fun_isdiv = paste0("tmapValuesIsDiv_", aes)

Expand Down
13 changes: 6 additions & 7 deletions R/tmapScale_defaults.R
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
tmapValuesCheck_fill = function(x) {
(!is.null(getPalMeta(x[1])) || all(valid_colors(x))) && !is.numeric(x)
}

tmapValuesCheck_col = function(x) {
(!is.null(getPalMeta(x[1])) || all(valid_colors(x))) && !is.numeric(x)
((!is.null(getPalMeta(x[1])) && length(x) == 1L) || all(valid_colors(x))) && !is.numeric(x)
}

tmapValuesCheck_fill = function(x) {
tmapValuesCheck_col(x)
}

tmapValuesCheck_shape = function(x) {
isSymbol = function(s) {
Expand Down Expand Up @@ -411,10 +410,10 @@ tmapValuesCVV_fill = function(x, value.na, n, range, scale, rep, o) {
# process values
#palid = tmapPalId(x[1])

arecolors = valid_colors(x[1])
m = getPalMeta(x[1])

ispalette = !is.null(m) && (length(x) == 1) # the latter in case of ambiguity (e.g. "blue")
arecolors = valid_colors(x[1])
ispalette = !is.null(m) && !arecolors # the latter in case of ambiguity (e.g. "blue")

values = if (!ispalette && !arecolors) {
rep(x, length.out = n)
Expand Down
7 changes: 7 additions & 0 deletions R/tmapScale_misc.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
check_values = function(layer, aes, values) {
fun_check = paste0("tmapValuesCheck_", aes)

are_valid = do.call(fun_check, args = list(x = values))
if (!are_valid) stop("Incorrect values for layer ", layer, ", aesthetic ", aes, "; values should conform visual variable \"", aes, "\"", call. = FALSE)
}

get_scale_defaults = function(scale, o, aes, layer, cls, ct = NULL) {
within(scale, {
values = if (is.na(values[1])) {
Expand Down

0 comments on commit 3e6ad93

Please sign in to comment.