Skip to content

Commit

Permalink
adding tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tomroh committed May 3, 2024
1 parent 642cee0 commit 3e01a41
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 12 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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")))
Expand Down
6 changes: 6 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
15 changes: 5 additions & 10 deletions R/legend.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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, ...)
}
}

Expand Down Expand Up @@ -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)
Expand Down
17 changes: 16 additions & 1 deletion tests/testthat/test-legend.R
Original file line number Diff line number Diff line change
Expand Up @@ -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') %>%
Expand Down Expand Up @@ -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') %>%
Expand Down

0 comments on commit 3e01a41

Please sign in to comment.