diff --git a/DESCRIPTION b/DESCRIPTION index 1245a66..94ef768 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: leaflegend Type: Package Title: Add Custom Legends to 'leaflet' Maps -Version: 1.2.0 +Version: 1.2.1 Authors@R: c( person("Thomas", "Roh", email = "thomas@roh.engineering", role = c("aut", "cre")), person("Ricardo Rodrigo", "Basa", email = "radbasa@gmail.com", role = c("ctb"))) diff --git a/NEWS.md b/NEWS.md index fca753d..c01eaad 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,9 @@ +# leaflegend 1.2.1 + +* `addLegendNumeric` now has the ability to use manual tick breaks and labels +when the `bins` argument is a numeric vector greater than length 1. This +only applies to vertically oriented legends. + # leaflegend 1.2.0 * `addLegendNumeric` gains `labelStyle` argument and significant improvements diff --git a/R/legend.R b/R/legend.R index 46289bf..9f4da0a 100644 --- a/R/legend.R +++ b/R/legend.R @@ -1106,8 +1106,7 @@ addSymbols <- function( leaflet::addMarkers(map = map, lng = lng, lat = lat, icon = iconSymbols, data = data, ...) } else { - leaflet::addMarkers(map = map, icon = iconSymbols, - data = data, ...) + leaflet::addMarkers(map = map, icon = iconSymbols, data = data, ...) } } #' @export @@ -1142,10 +1141,9 @@ addSymbolsSize <- function( fillOpacity = fillOpacity, strokeWidth = strokeWidth, width = sizes, data = data, ...) } else { - addSymbols(map = map, shape = shape, color = color, - fillColor = fillColor, opacity = opacity, - fillOpacity = fillOpacity, strokeWidth = strokeWidth, - width = sizes, data = data, ...) + addSymbols(map = map, shape = shape, color = color, fillColor = fillColor, + opacity = opacity, fillOpacity = fillOpacity, strokeWidth = strokeWidth, + width = sizes, data = data, ...) } } @@ -1658,11 +1656,8 @@ addLegendQuantile <- function(map, probs <- attr(pal, 'colorArgs')[['probs']] values <- parseValues(values = values, data = data) if ( is.null(numberFormat) ) { - labels <- sprintf(' %3.0f%%%s%3.0f%%', - probs[-length(probs)] * 100, - between, + labels <- sprintf(' %3.0f%%%s%3.0f%%', probs[-length(probs)] * 100, between, probs[-1] * 100) - } else { breaks <- stats::quantile(x = values, probs = probs, na.rm = TRUE) labels <- numberFormat(breaks) diff --git a/tests/testthat/test-legend.R b/tests/testthat/test-legend.R index 0d8322c..8214df6 100644 --- a/tests/testthat/test-legend.R +++ b/tests/testthat/test-legend.R @@ -495,10 +495,21 @@ testthat::test_that('Numeric Legend', { tickWidth = -1) %>% testthat::expect_error() # test results - numVert <- m %>% addLegendNumeric(pal = pal, values = c(1, NA, 3)) + numVert <- m %>% addLegendNumeric(pal = pal, values = c(1, NA, 3), + decreasing = TRUE) numHori <- m %>% addLegendNumeric(pal = pal, values = c(1, NA, 3), orientation = 'horizontal', width = 100, height = 20) + numVert %>% + testthat::expect_no_error() + numHori %>% + testthat::expect_no_error() + m %>% + addLegendNumeric(pal = pal, values = ~x, bins = c(10, 11)) %>% + testthat::expect_error() + m %>% + addLegendNumeric(pal = pal, values = ~x, bins = c(1, 3)) %>% + testthat::expect_no_error() # numVert %>% # getElement('x') %>% # getElement('calls') %>% @@ -629,6 +640,10 @@ testthat::test_that('Categorical Legends', { values = ~x, numberFormat = 'fun') %>% testthat::expect_error() + m %>% addLegendQuantile(pal = palQuantile, + values = ~x, + numberFormat = NULL) %>% + testthat::expect_no_error() # test Bin args m %>% addLegendBin(pal = palBin, orientation = 'up') %>%