Skip to content

Commit

Permalink
Merge pull request #48 from tomroh/devel
Browse files Browse the repository at this point in the history
Version 0.6.0
  • Loading branch information
tomroh authored Jan 17, 2022
2 parents dd8f6af + 3b23dfc commit 55994ec
Show file tree
Hide file tree
Showing 20 changed files with 222 additions and 61 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: 0.5.0
Version: 0.6.0
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
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export(addLegendAwesomeIcon)
export(addLegendBin)
export(addLegendFactor)
export(addLegendImage)
export(addLegendLine)
export(addLegendNumeric)
export(addLegendQuantile)
export(addLegendSize)
Expand Down
6 changes: 5 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
* updated layers control to handle special characters in group name. All non-alphanumeric characters are removed from the class names and
javascript selectors.

* added better error message for missing color and pal

* adding `addLegendLine` to add height only encoding of size based on values

# leaflegend 0.5.0

* updated example in README
Expand Down Expand Up @@ -42,7 +46,7 @@ legends

* new functions `addLegendSize`, `sizeNumeric`, and `sizeBreaks` were added to allow encoding size on symbols.

* `addLegendImage` supports multiple height and width paramaters for images where you want different sizes
* `addLegendImage` supports multiple height and width parameters for images where you want different sizes

* `addLegendImage` now supports using an svg URI from the output of `makeSymbol`.
To supply a custom svg URI, add the 'svgURI' class to the character vector.
Expand Down
85 changes: 77 additions & 8 deletions R/legend.R
Original file line number Diff line number Diff line change
Expand Up @@ -313,8 +313,8 @@ makeSymbol <- function(shape, width, height = width, color, fillColor = color,
),
'line' = htmltools::tags$line(
id = 'line',
x1 = 0 + strokewidth,
x2 = width + strokewidth,
x1 = 0,
x2 = width + strokewidth * 2,
y1 = height / 2 + strokewidth,
y2 = height / 2 + strokewidth,
stroke = color,
Expand Down Expand Up @@ -972,7 +972,7 @@ addLegendFactor <- function(map,
leaflegendAddControl(map, html = htmltools::tagList(htmlElements), className = className, group = group, ...)
}

#' Add a legend that for the sizing of symbols
#' Add a legend that for the sizing of symbols or the width of lines
#'
#' @param map
#'
Expand Down Expand Up @@ -1140,6 +1140,25 @@ addLegendFactor <- function(map,
#' breaks = 5,
#' group = 'Depth') %>%
#' addLayersControl(overlayGroups = c('Depth'))
#'
#' # Polyline Legend for Size
#' baseSize <- 10
#' lineColor <- '#00000080'
#' pal <- colorNumeric('Reds', atlStorms2005$MinPress)
#' leaflet() %>%
#' addTiles() %>%
#' addPolylines(data = atlStorms2005,
#' weight = ~sizeNumeric(values = MaxWind, baseSize = baseSize),
#' color = ~pal(MinPress),
#' popup = ~as.character(MaxWind)) %>%
#' addLegendLine(values = atlStorms2005$MaxWind,
#' title = 'MaxWind',
#' baseSize = baseSize,
#' width = 50,
#' color = lineColor) %>%
#' addLegendNumeric(pal = pal,
#' title = 'MinPress',
#' values = atlStorms2005$MinPress)
addLegendSize <- function(map,
pal,
values,
Expand All @@ -1161,6 +1180,7 @@ addLegendSize <- function(map,
shape <- match.arg(shape)
sizes <- sizeBreaks(values, breaks, baseSize)
if ( missing(color) ) {
stopifnot( missing(color) & !missing(pal))
colors <- pal(as.numeric(names(sizes)))
} else {
stopifnot(length(color) == 1 || length(color) == length(breaks))
Expand All @@ -1187,7 +1207,8 @@ addLegendSize <- function(map,
`stroke-width` = strokeWidth)
addLegendImage(map, images = symbols, labels = numberFormat(as.numeric(names(sizes))),
title = title, labelStyle = labelStyle,
orientation = orientation, width = sizes, height = sizes, group = group, className = className, ...)
orientation = orientation, width = sizes, height = sizes,
group = group, className = className, ...)

}

Expand Down Expand Up @@ -1228,6 +1249,7 @@ makeSizeIcons <- function(values,
shape <- match.arg(shape)
if ( missing(color) ) {
if ( missing(colorValues) ) {
stopifnot( all(missing(color), missing(pal), missing(colorValues)) )
colors <- pal(values)
} else {
colors <- pal(colorValues)
Expand Down Expand Up @@ -1264,6 +1286,53 @@ makeSizeIcons <- function(values,
...
)
}
#' @param width
#'
#' width in pixels of the lines
#'
#' @export
#'
#' @rdname addLegendSize
addLegendLine <- function(map,
pal,
values,
title = NULL,
labelStyle = '',
orientation = c('vertical', 'horizontal'),
width = 20,
color,
opacity = 1,
fillOpacity = opacity,
breaks = 5,
baseSize = 10,
numberFormat = function(x) {prettyNum(x, big.mark = ',', scientific = FALSE, digits = 1)},
group = NULL,
className = 'info legend leaflet-control',
...) {
shape <- 'rect'
sizes <- sizeBreaks(values, breaks, baseSize)
if ( missing(color) ) {
stopifnot( missing(color) & !missing(pal))
colors <- pal(as.numeric(names(sizes)))
} else {
stopifnot(length(color) == 1 || length(color) == length(breaks))
colors <- color
}
symbols <- Map(makeSymbol,
shape = 'rect',
width = width,
height = sizes,
color = 'transparent',
fillColor = colors,
opacity = opacity,
fillOpacity = fillOpacity,
`stroke-width` = 0)
addLegendImage(map, images = symbols, labels = numberFormat(as.numeric(names(sizes))),
title = title, labelStyle = labelStyle,
orientation = orientation, width = width, height = sizes,
group = group, className = className, ...)

}

#' Add a legend with Awesome Icons
#'
Expand Down Expand Up @@ -1328,17 +1397,17 @@ makeSizeIcons <- function(values,
#' spin = TRUE,
#' squareMarker = FALSE)
#' )
#' leaflet(quakes[1:3,]) |>
#' addTiles() |>
#' leaflet(quakes[1:3,]) %>%
#' addTiles() %>%
#' addAwesomeMarkers(lat = ~lat,
#' lng = ~long,
#' icon = iconSet) |>
#' icon = iconSet) %>%
#' addLegendAwesomeIcon(iconSet = iconSet,
#' orientation = 'horizontal',
#' title = htmltools::tags$div(
#' style = 'font-size: 20px;',
#' 'Awesome Icons'),
#' labelStyle = 'font-size: 16px;') |>
#' labelStyle = 'font-size: 16px;') %>%
#' addLegendAwesomeIcon(iconSet = iconSet,
#' orientation = 'vertical',
#' marker = FALSE,
Expand Down
2 changes: 1 addition & 1 deletion docs/404.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/LICENSE-text.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/LICENSE.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions docs/authors.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/index.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions docs/news/index.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ pandoc: 2.14.0.3
pkgdown: 2.0.1
pkgdown_sha: ~
articles: {}
last_built: 2021-12-05T17:43Z
last_built: 2022-01-17T15:37Z
urls:
reference: https://leaflegend.roh.engineering/reference
article: https://leaflegend.roh.engineering/articles
Expand Down
Loading

0 comments on commit 55994ec

Please sign in to comment.