From 14a61e49a5c81a80da841ea055c79d15a002dc3b Mon Sep 17 00:00:00 2001 From: mtennekes Date: Thu, 21 Sep 2023 16:17:34 +0200 Subject: [PATCH] fixed #667 --- R/tmapLeafletLegend.R | 14 ++++++++++++++ R/tmapScaleContinuous.R | 5 ++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/R/tmapLeafletLegend.R b/R/tmapLeafletLegend.R index 7da23e45..50e26155 100644 --- a/R/tmapLeafletLegend.R +++ b/R/tmapLeafletLegend.R @@ -122,6 +122,16 @@ tmapLeaflet_legend = function(cmp, lf, o, orientation) { domain = val, na.color=colNA, alpha = FALSE) + + brks = pretty(cmp$limits, 7) + + trns = function(x) { + f = (x-cmp$limits[1]) / diff(cmp$limits) + y = cmp$tr$fun(cmp$limits) + x2 = y[1] + diff(y) * f + cmp$tr$rev(x2) + } + lf |> leaflegend::addLegendNumeric(position=legpos, orientation = orientation, group = group, @@ -129,6 +139,10 @@ tmapLeaflet_legend = function(cmp, lf, o, orientation) { width = {if (orientation == "vertical") 20 else 200}, pal=pal, values=val, + numberFormat = function(x) { + prettyNum(trns(x), format = "f", big.mark = ",", digits = + 3, scientific = FALSE) + }, #na.label = textNA, title=title, fillOpacity=cmp$gp3$alpha, diff --git a/R/tmapScaleContinuous.R b/R/tmapScaleContinuous.R index 464ada98..7307fe79 100644 --- a/R/tmapScaleContinuous.R +++ b/R/tmapScaleContinuous.R @@ -246,7 +246,7 @@ tmapScaleContinuous = function(x1, scale, legend, o, aes, layer, layer_args, sor labels = c(labels, label.na) attr(labels, "align") = labels.align } - #attr(vvalues, "style") = style + legend = within(legend, { @@ -257,7 +257,10 @@ tmapScaleContinuous = function(x1, scale, legend, o, aes, layer, layer_args, sor vneutral = value.neutral na.show = get("na.show", envir = parent.env(environment())) scale = "continuous" + tr = tr + limits = limits }) + # NOTE: tr and limits are included in the output to facilitate the transformation of the leaflet continuous legend ticks (https://github.com/rstudio/leaflet/issues/665) if (submit_legend) { if (bypass_ord) {