Skip to content

Commit

Permalink
fixed #920
Browse files Browse the repository at this point in the history
  • Loading branch information
mtennekes committed Aug 28, 2024
1 parent 1f70f58 commit 7e0c857
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 14 deletions.
10 changes: 6 additions & 4 deletions R/step2_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,15 @@ step2_data = function(tm) {

plot.order = tml$plot.order

group = if (is.na(tml$group)) tmg$tms$shp_name else as.character(tml$group)
group.control = as.character(tml$group.control)


# args will be passed on to the scale functions (in case needed)
# they also will be used in step 3 (trans) and step 4 (mapping)
trans = mapply(getdts, tml$trans.aes, names(tml$trans.aes), SIMPLIFY = FALSE, MoreArgs = list(p = tp, q = tmf, o = o, dt = dt, shpvars = shpvars, layer = tml$layer, mfun = tml$mapping.fun, args = tml$trans.args, plot.order = plot.order))
trans = mapply(getdts, tml$trans.aes, names(tml$trans.aes), SIMPLIFY = FALSE, MoreArgs = list(p = tp, q = tmf, o = o, dt = dt, shpvars = shpvars, layer = tml$layer, group = group, mfun = tml$mapping.fun, args = tml$trans.args, plot.order = plot.order))

mapping = mapply(getdts, tml$mapping.aes, names(tml$mapping.aes), SIMPLIFY = FALSE, MoreArgs = list(p = gp, q = tmf, o = o, dt = dt, shpvars = shpvars, layer = tml$layer, mfun = tml$mapping.fun, args = tml$mapping.args, plot.order = plot.order))
mapping = mapply(getdts, tml$mapping.aes, names(tml$mapping.aes), SIMPLIFY = FALSE, MoreArgs = list(p = gp, q = tmf, o = o, dt = dt, shpvars = shpvars, layer = tml$layer, group = group, mfun = tml$mapping.fun, args = tml$mapping.args, plot.order = plot.order))

dts_trans = cbind_dts(lapply(trans, function(x) x$dt), plot.order)
trans_legend = lapply(trans, function(x) x$leg)
Expand All @@ -81,8 +85,6 @@ step2_data = function(tm) {
if (dev) timing_add(s4 = "combine")
if (dev) timing_add(s3 = paste0("layer ", tml$layer))

group = if (is.na(tml$group)) tmg$tms$shp_name else as.character(tml$group)
group.control = as.character(tml$group.control)

popup.data = if (!length(tml$popup.vars)) {
NULL
Expand Down
3 changes: 2 additions & 1 deletion R/step2_helper_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ update_crt = function(o, crt, v, mfun, unm, active) {
crt
}

getdts = function(aes, unm, p, q, o, dt, shpvars, layer, mfun, args, plot.order) {
getdts = function(aes, unm, p, q, o, dt, shpvars, layer, group, mfun, args, plot.order) {
dev = getOption("tmap.devel.mode")

nm = aes$aes
Expand Down Expand Up @@ -307,6 +307,7 @@ getdts = function(aes, unm, p, q, o, dt, shpvars, layer, mfun, args, plot.order)

apply_scale = function(s, l, crt, v, varname, ordname, legname, crtname, sortRev, bypass_ord) {
l = update_l(o = o, l = l, v = v, mfun = mfun, unm = unm, active = TRUE)
l$group = group
crt = update_crt(o = o, crt = crt, v = v, mfun = mfun, unm = unm, active = TRUE)

if (length(s) == 0) stop("mapping not implemented for aesthetic ", unm, call. = FALSE)
Expand Down
12 changes: 3 additions & 9 deletions R/tmapLeafletLegend.R
Original file line number Diff line number Diff line change
Expand Up @@ -84,19 +84,12 @@ make_equal_list = function(x) {


tmapLeaflet_legend = function(cmp, lf, o, orientation) {
group = "tmp" # TODO
group = cmp$group
leg_className = paste("info legend", gsub(" ", "", group, fixed = TRUE))
layerId = paste0("legend", sprintf("%02d", .TMAP_LEAFLET$leg_id)) # "legend401" #todo
.TMAP_LEAFLET$leg_id = .TMAP_LEAFLET$leg_id + 1

# if (length(cmp$gp$col) > 1 || all(is.na(cmp$gp$fill))) {
# pal = cmp$gp$col
# opacity = cmp$gp$col_alpha
# } else {
# pal = cmp$gp$fill
# opacity = cmp$gp$fill_alpha
# }


lab = cmp$labels
val = cmp$dvalues
title = if (nonempty_text(cmp$title)) expr_to_char(cmp$title) else NULL
Expand Down Expand Up @@ -203,6 +196,7 @@ tmapLeaflet_legend = function(cmp, lf, o, orientation) {


lf %>% leaflegend::addLegendImage(symbols$iconUrl,
group = group,
labels = lab,
width = symbols$iconWidth + 2*gp2$strokeWidth,
height = symbols$iconHeight + 2*gp2$strokeWidth,
Expand Down

0 comments on commit 7e0c857

Please sign in to comment.