Skip to content

Commit

Permalink
added backwards comp with continuous scale with using 'breaks' #639
Browse files Browse the repository at this point in the history
  • Loading branch information
mtennekes committed Jul 18, 2024
1 parent 64f0cd3 commit 5bdba07
Show file tree
Hide file tree
Showing 5 changed files with 175 additions and 96 deletions.
54 changes: 35 additions & 19 deletions R/tm_layers_lines.R
Original file line number Diff line number Diff line change
Expand Up @@ -114,25 +114,41 @@ tm_lines = function(col = tm_const(),
.TMAP$v3_list$mult = TRUE
}
# v3 visual variable: col
col.scale.args = list(n = v3_impute(args, "n", 5),
style = style,
style.args = v3_impute(args, "style.args", list()),
breaks = v3_impute(args, "breaks", NULL),
interval.closure = v3_impute(args, "interval.closure", "left"),
drop.levels = v3_impute(args, "drop.levels", FALSE),
midpoint = v3_impute(args, "midpoint", NULL),
as.count = v3_impute(args, "as.count", NA),
values = v3_impute(args, "palette", NA, "values"),
values.repeat = !v3_impute(args, "stretch.palette", TRUE, "values.repeat"),
values.range = v3_impute(args, "contrast", NA, "values.range"),
values.scale = 1,
value.na = v3_impute(args, "colorNA", NA, "value.na"),
value.null = v3_impute(args, "colorNULL", NA, "value.null"),
value.neutral = NA,
labels = v3_impute(args, "labels", NULL),
label.na = v3_impute(args, "textNA", NA, "label.na"),
label.null = NA,
label.format = v3_impute(args, "legend.format", list(), "label.format"))
col.scale.args = c(list(n = v3_impute(args, "n", 5),
style = style,
style.args = v3_impute(args, "style.args", list())),
if (style %in% c("cont", "log10")) {
c({
if (!is.null(args$breaks)) {
if (length(args$breaks) > 2) {
list(ticks = v3_impute(args, "breaks", NULL, "ticks"))
} else {
list(ticks = v3_impute(args, "breaks", NULL, "limits"))
}
} else {
list()
}
},
list(outliers.trunc = c(TRUE, FALSE)))
} else {
list(breaks = v3_impute(args, "breaks", NULL),
interval.closure = v3_impute(args, "interval.closure", "left"),
drop.levels = v3_impute(args, "drop.levels", FALSE))
},
list(midpoint = v3_impute(args, "midpoint", NULL),
as.count = v3_impute(args, "as.count", NA),
values = v3_impute(args, "palette", NA, "values"),
values.repeat = !v3_impute(args, "stretch.palette", TRUE, "values.repeat"),
values.range = v3_impute(args, "contrast", NA, "values.range"),
values.scale = 1,
value.na = v3_impute(args, "colorNA", NA, "value.na"),
value.null = v3_impute(args, "colorNULL", NA, "value.null"),
value.neutral = NA,
labels = v3_impute(args, "labels", NULL),
label.na = v3_impute(args, "textNA", "Missing", "label.na"),
label.null = NA,
label.format = v3_impute(args, "legend.format", list(), "label.format")))

col.scale.args$fun_pref = if (style == "cat") {
"categorical"
} else if (style %in% c("fixed", "sd", "equal", "pretty", "quantile",
Expand Down
55 changes: 36 additions & 19 deletions R/tm_layers_polygons.R
Original file line number Diff line number Diff line change
Expand Up @@ -155,25 +155,42 @@ tm_polygons = function(fill = tm_const(),
.TMAP$v3_list$mult = TRUE
}

fill.scale.args = list(n = v3_impute(args, "n", 5),
style = style,
style.args = v3_impute(args, "style.args", list()),
breaks = v3_impute(args, "breaks", NULL),
interval.closure = v3_impute(args, "interval.closure", "left"),
drop.levels = v3_impute(args, "drop.levels", FALSE),
midpoint = v3_impute(args, "midpoint", NULL),
as.count = v3_impute(args, "as.count", NA),
values = v3_impute(args, "palette", NA, "values"),
values.repeat = !v3_impute(args, "stretch.palette", TRUE, "values.repeat"),
values.range = v3_impute(args, "contrast", NA, "values.range"),
values.scale = 1,
value.na = v3_impute(args, "colorNA", NA, "value.na"),
value.null = v3_impute(args, "colorNULL", NA, "value.null"),
value.neutral = NA,
labels = v3_impute(args, "labels", NULL),
label.na = v3_impute(args, "textNA", "Missing", "label.na"),
label.null = NA,
label.format = v3_impute(args, "legend.format", list(), "label.format"))


fill.scale.args = c(list(n = v3_impute(args, "n", 5),
style = style,
style.args = v3_impute(args, "style.args", list())),
if (style %in% c("cont", "log10")) {
c({
if (!is.null(args$breaks)) {
if (length(args$breaks) > 2) {
list(ticks = v3_impute(args, "breaks", NULL, "ticks"))
} else {
list(ticks = v3_impute(args, "breaks", NULL, "limits"))
}
} else {
list()
}
},
list(outliers.trunc = c(TRUE, FALSE)))
} else {
list(breaks = v3_impute(args, "breaks", NULL),
interval.closure = v3_impute(args, "interval.closure", "left"),
drop.levels = v3_impute(args, "drop.levels", FALSE))
},
list(midpoint = v3_impute(args, "midpoint", NULL),
as.count = v3_impute(args, "as.count", NA),
values = v3_impute(args, "palette", NA, "values"),
values.repeat = !v3_impute(args, "stretch.palette", TRUE, "values.repeat"),
values.range = v3_impute(args, "contrast", NA, "values.range"),
values.scale = 1,
value.na = v3_impute(args, "colorNA", NA, "value.na"),
value.null = v3_impute(args, "colorNULL", NA, "value.null"),
value.neutral = NA,
labels = v3_impute(args, "labels", NULL),
label.na = v3_impute(args, "textNA", "Missing", "label.na"),
label.null = NA,
label.format = v3_impute(args, "legend.format", list(), "label.format")))


fill.scale.args$fun_pref = if (style[1] == "cat") {
Expand Down
53 changes: 34 additions & 19 deletions R/tm_layers_raster.R
Original file line number Diff line number Diff line change
Expand Up @@ -100,25 +100,40 @@ tm_raster = function(col = tm_shape_vars(),
.TMAP$v3_list$mult = TRUE
}
# v3 visual variable: col
col.scale.args = list(n = v3_impute(args, "n", 5),
style = style,
style.args = v3_impute(args, "style.args", list()),
breaks = v3_impute(args, "breaks", NULL),
interval.closure = v3_impute(args, "interval.closure", "left"),
drop.levels = v3_impute(args, "drop.levels", FALSE),
midpoint = v3_impute(args, "midpoint", NULL),
as.count = v3_impute(args, "as.count", NA),
values = v3_impute(args, "palette", NA, "values"),
values.repeat = !v3_impute(args, "stretch.palette", TRUE, "values.repeat"),
values.range = v3_impute(args, "contrast", NA, "values.range"),
values.scale = 1,
value.na = v3_impute(args, "colorNA", NA, "value.na"),
value.null = v3_impute(args, "colorNULL", NA, "value.null"),
value.neutral = NA,
labels = v3_impute(args, "labels", NULL),
label.na = v3_impute(args, "textNA", NA, "label.na"),
label.null = NA,
label.format = v3_impute(args, "legend.format", list(), "label.format"))
col.scale.args = c(list(n = v3_impute(args, "n", 5),
style = style,
style.args = v3_impute(args, "style.args", list())),
if (style %in% c("cont", "log10")) {
c({
if (!is.null(args$breaks)) {
if (length(args$breaks) > 2) {
list(ticks = v3_impute(args, "breaks", NULL, "ticks"))
} else {
list(ticks = v3_impute(args, "breaks", NULL, "limits"))
}
} else {
list()
}
},
list(outliers.trunc = c(TRUE, FALSE)))
} else {
list(breaks = v3_impute(args, "breaks", NULL),
interval.closure = v3_impute(args, "interval.closure", "left"),
drop.levels = v3_impute(args, "drop.levels", FALSE))
},
list(midpoint = v3_impute(args, "midpoint", NULL),
as.count = v3_impute(args, "as.count", NA),
values = v3_impute(args, "palette", NA, "values"),
values.repeat = !v3_impute(args, "stretch.palette", TRUE, "values.repeat"),
values.range = v3_impute(args, "contrast", NA, "values.range"),
values.scale = 1,
value.na = v3_impute(args, "colorNA", NA, "value.na"),
value.null = v3_impute(args, "colorNULL", NA, "value.null"),
value.neutral = NA,
labels = v3_impute(args, "labels", NULL),
label.na = v3_impute(args, "textNA", "Missing", "label.na"),
label.null = NA,
label.format = v3_impute(args, "legend.format", list(), "label.format")))
col.scale.args$fun_pref = if (style == "cat") {
"categorical"
} else if (style %in% c("fixed", "sd", "equal", "pretty", "quantile",
Expand Down
53 changes: 34 additions & 19 deletions R/tm_layers_symbols.R
Original file line number Diff line number Diff line change
Expand Up @@ -291,25 +291,40 @@ v3_symbols = function(args, args_called) {
}

# v3 visual variable: fill
fill.scale.args = list(n = v3_impute(args, "n", 5),
style = style,
style.args = v3_impute(args, "style.args", list()),
breaks = v3_impute(args, "breaks", NULL),
interval.closure = v3_impute(args, "interval.closure", "left"),
drop.levels = v3_impute(args, "drop.levels", FALSE),
midpoint = v3_impute(args, "midpoint", NULL),
as.count = v3_impute(args, "as.count", NA),
values = v3_impute(args, "palette", NA, "values"),
values.repeat = !v3_impute(args, "stretch.palette", TRUE, "values.repeat"),
values.range = v3_impute(args, "contrast", NA, "values.range"),
values.scale = 1,
value.na = v3_impute(args, "colorNA", NA, "value.na"),
value.null = v3_impute(args, "colorNULL", NA, "value.null"),
value.neutral = NA,
labels = v3_impute(args, "labels", NULL),
label.na = v3_impute(args, "textNA", NA, "label.na"),
label.null = NA,
label.format = v3_impute(args, "legend.format", list(), "label.format"))
fill.scale.args = c(list(n = v3_impute(args, "n", 5),
style = style,
style.args = v3_impute(args, "style.args", list())),
if (style %in% c("cont", "log10")) {
c({
if (!is.null(args$breaks)) {
if (length(args$breaks) > 2) {
list(ticks = v3_impute(args, "breaks", NULL, "ticks"))
} else {
list(ticks = v3_impute(args, "breaks", NULL, "limits"))
}
} else {
list()
}
},
list(outliers.trunc = c(TRUE, FALSE)))
} else {
list(breaks = v3_impute(args, "breaks", NULL),
interval.closure = v3_impute(args, "interval.closure", "left"),
drop.levels = v3_impute(args, "drop.levels", FALSE))
},
list(midpoint = v3_impute(args, "midpoint", NULL),
as.count = v3_impute(args, "as.count", NA),
values = v3_impute(args, "palette", NA, "values"),
values.repeat = !v3_impute(args, "stretch.palette", TRUE, "values.repeat"),
values.range = v3_impute(args, "contrast", NA, "values.range"),
values.scale = 1,
value.na = v3_impute(args, "colorNA", NA, "value.na"),
value.null = v3_impute(args, "colorNULL", NA, "value.null"),
value.neutral = NA,
labels = v3_impute(args, "labels", NULL),
label.na = v3_impute(args, "textNA", "Missing", "label.na"),
label.null = NA,
label.format = v3_impute(args, "legend.format", list(), "label.format")))
fill.scale.args$fun_pref = if (style == "cat") {
"categorical"
} else if (style %in% c("fixed", "sd", "equal", "pretty", "quantile",
Expand Down
56 changes: 36 additions & 20 deletions R/tm_layers_text.R
Original file line number Diff line number Diff line change
Expand Up @@ -260,33 +260,49 @@ tm_text = function(text = tm_const(),
style = style[1]
.TMAP$v3_list$mult = TRUE
}
col.scale.args = list(n = v3_impute(args, "n", 5),
style = style,
style.args = v3_impute(args, "style.args", list()),
breaks = v3_impute(args, "breaks", NULL),
interval.closure = v3_impute(args, "interval.closure", "left"),
drop.levels = v3_impute(args, "drop.levels", FALSE),
midpoint = v3_impute(args, "midpoint", NULL),
as.count = v3_impute(args, "as.count", NA),
values = v3_impute(args, "palette", NA, "values"),
values.repeat = !v3_impute(args, "stretch.palette", TRUE, "values.repeat"),
values.range = v3_impute(args, "contrast", NA, "values.range"),
values.scale = 1,
value.na = v3_impute(args, "colorNA", NA, "value.na"),
value.null = v3_impute(args, "colorNULL", NA, "value.null"),
value.neutral = NA,
labels = v3_impute(args, "labels", NULL),
label.na = v3_impute(args, "textNA", "Missing", "label.na"),
label.null = NA,
label.format = v3_impute(args, "legend.format", list(), "label.format"))
col.scale.args = c(list(n = v3_impute(args, "n", 5),
style = style,
style.args = v3_impute(args, "style.args", list())),
if (style %in% c("cont", "log10")) {
c({
if (!is.null(args$breaks)) {
if (length(args$breaks) > 2) {
list(ticks = v3_impute(args, "breaks", NULL, "ticks"))
} else {
list(ticks = v3_impute(args, "breaks", NULL, "limits"))
}
} else {
list()
}
},
list(outliers.trunc = c(TRUE, FALSE)))
} else {
list(breaks = v3_impute(args, "breaks", NULL),
interval.closure = v3_impute(args, "interval.closure", "left"),
drop.levels = v3_impute(args, "drop.levels", FALSE))
},
list(midpoint = v3_impute(args, "midpoint", NULL),
as.count = v3_impute(args, "as.count", NA),
values = v3_impute(args, "palette", NA, "values"),
values.repeat = !v3_impute(args, "stretch.palette", TRUE, "values.repeat"),
values.range = v3_impute(args, "contrast", NA, "values.range"),
values.scale = 1,
value.na = v3_impute(args, "colorNA", NA, "value.na"),
value.null = v3_impute(args, "colorNULL", NA, "value.null"),
value.neutral = NA,
labels = v3_impute(args, "labels", NULL),
label.na = v3_impute(args, "textNA", "Missing", "label.na"),
label.null = NA,
label.format = v3_impute(args, "legend.format", list(), "label.format")))

col.scale.args$fun_pref = if (style == "cat") {
"categorical"
} else if (style %in% c("fixed", "sd", "equal", "pretty", "quantile", "kmeans", "hclust", "bclust", "fisher", "jenks", "dpih", "headtails", "log10_pretty")) {
"intervals"
} else if (style == "cont") {
"continuous"
} else if (style == "log10") {
"continuous_log"
"continuous_log10"
} else {
stop("unknown style")
}
Expand Down

0 comments on commit 5bdba07

Please sign in to comment.