From ae09c301a9207d8685a4324cb79e39756c40a4b1 Mon Sep 17 00:00:00 2001 From: Sebastian Gatscha Date: Mon, 12 Aug 2024 11:20:21 +0200 Subject: [PATCH] fix build warnings/errors, add docu --- DESCRIPTION | 5 +++-- NAMESPACE | 1 + R/clusterCharts.R | 23 ++++++++++++++----- R/leaflet.extras2-package.R | 1 + inst/examples/clustercharts_sum.R | 2 ++ man/addClusterCharts.Rd | 12 +++------- man/clusterchartOptions.Rd | 24 +++++++++++++++++--- tests/testthat/test-heightgraph.R | 1 - tests/testthat/test-movingmarker.R | 36 +++++++++++++++++------------- 9 files changed, 70 insertions(+), 35 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index dc781a3c..31a58752 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -27,9 +27,10 @@ Suggests: testthat (>= 2.1.0), fontawesome, htmlwidgets, + grDevices, + xfun, covr, - curl, - rmarkdown + curl URL: https://trafficonese.github.io/leaflet.extras2/, https://github.com/trafficonese/leaflet.extras2 BugReports: https://github.com/trafficonese/leaflet.extras2/issues RoxygenNote: 7.3.1 diff --git a/NAMESPACE b/NAMESPACE index 2904cabb..ee28a849 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -98,6 +98,7 @@ export(unsync) export(updateHexbin) export(velocityOptions) import(leaflet) +importFrom(grDevices,colorRampPalette) importFrom(htmltools,htmlDependency) importFrom(htmltools,tagGetAttribute) importFrom(htmltools,tagList) diff --git a/R/clusterCharts.R b/R/clusterCharts.R index 67d742a4..5f954c10 100644 --- a/R/clusterCharts.R +++ b/R/clusterCharts.R @@ -18,9 +18,11 @@ clusterchartsDependencies <- function() { #' addClusterCharts #' @description Adds cluster charts (either pie or bar charts) to a Leaflet map. -#' @param type The type of chart to use for clusters, either "pie" or "bar". +#' @param type The type of chart to use for clusters, either \code{c("pie","bar","horizontal","custom")}. #' @param categoryField The name of the feature property used to categorize the charts. #' @param categoryMap A data frame mapping categories to chart properties (label, color, icons, stroke). +#' @param icon Include an icon or a set of icons with \code{makeIcon} or \code{iconList} +#' @param html The html to include in the markers #' @param popup Use the column name given in popup to collect the feature property with this name. #' @param popupFields A string or vector of strings indicating the feature properties to include in popups. #' @param popupLabels A string or vector of strings indicating the labels for the popup fields. @@ -70,7 +72,8 @@ clusterchartsDependencies <- function() { #' , label = "brewery" #' ) addClusterCharts <- function( - map, lng = NULL, lat = NULL, layerId = NULL, group = NULL, type = c("pie","bar","horizontal","custom"), + map, lng = NULL, lat = NULL, layerId = NULL, group = NULL, + type = c("pie","bar","horizontal","custom"), options = clusterchartOptions(), icon = NULL, html = NULL, popup = NULL, popupOptions = NULL, label = NULL, labelOptions = NULL, @@ -158,9 +161,19 @@ addClusterCharts <- function( #' @param rmax The maximum radius of the clusters. #' @param size The size of the cluster markers. #' @param strokeWidth The stroke width in the chart. -#' @param width The width of the bar-chart. -#' @param height The height of the bar-chart. -#' @param innerRadius The inner radius of the pie-chart. +#' @param width The width of the bar-charts. +#' @param height The height of the bar-charts. +#' @param innerRadius The inner radius of the pie-charts. +#' @param labelBackground Should the label have a background? Default is `FALSE` +#' @param labelFill The label background color. Default is `white` +#' @param labelStroke The label stroke color. Default is `black` +#' @param labelColor The label color. Default is `black` +#' @param labelOpacity The label color. Default is `0.9` +#' @param aggregation If `type = "custom"` in the `addClusterCharts` function, this aggregation method will be used. +#' @param valueField If `type = "custom"` in the `addClusterCharts` function, the aggregation will be used on this column. +#' @param digits The amount of digits. Default is `2` +#' @param sortTitlebyCount Should the svg-title be sorted by count or by the categories. +#' #' @export clusterchartOptions <- function(rmax = 30, size = c(20, 20), width = 40, height = 50, diff --git a/R/leaflet.extras2-package.R b/R/leaflet.extras2-package.R index aca3ebdb..edb41e8c 100644 --- a/R/leaflet.extras2-package.R +++ b/R/leaflet.extras2-package.R @@ -7,6 +7,7 @@ #' @import leaflet #' @importFrom htmltools htmlDependency tagGetAttribute tags tagList #' @importFrom utils globalVariables adist packageVersion +#' @importFrom grDevices colorRampPalette ## usethis namespace: end NULL diff --git a/inst/examples/clustercharts_sum.R b/inst/examples/clustercharts_sum.R index e03c08e7..130e93b8 100644 --- a/inst/examples/clustercharts_sum.R +++ b/inst/examples/clustercharts_sum.R @@ -70,6 +70,8 @@ server <- function(input, output, session) { size = 40, # size = c(100,140), labelBackground = TRUE, + labelStroke = "orange", + labelColor = "gray", labelOpacity = 0.5, innerRadius = 20, aggregation = input$aggr, diff --git a/man/addClusterCharts.Rd b/man/addClusterCharts.Rd index 798b299f..a4bcb4bc 100644 --- a/man/addClusterCharts.Rd +++ b/man/addClusterCharts.Rd @@ -50,19 +50,13 @@ Human-friendly group names are permitted--they need not be short, identifier-style names. Any number of layers and even different types of layers (e.g. markers and polygons) can share the same group name.} -\item{type}{The type of chart to use for clusters, either "pie" or "bar".} +\item{type}{The type of chart to use for clusters, either \code{c("pie","bar","horizontal","custom")}.} \item{options}{Additional options for cluster charts (see \code{\link{clusterchartOptions}}).} -\item{icon}{the icon(s) for markers; an icon is represented by an R list of -the form \code{list(iconUrl = "?", iconSize = c(x, y))}, and you can use -\code{\link[leaflet]{icons}()} to create multiple icons; note when you use an R list -that contains images as local files, these local image files will be base64 -encoded into the HTML page so the icon images will still be available even -when you publish the map elsewhere} +\item{icon}{Include an icon or a set of icons with \code{makeIcon} or \code{iconList}} -\item{html}{the content of the control. May be provided as string or as HTML -generated with Shiny/htmltools tags} +\item{html}{The html to include in the markers} \item{popup}{Use the column name given in popup to collect the feature property with this name.} diff --git a/man/clusterchartOptions.Rd b/man/clusterchartOptions.Rd index 12155d48..6894ba82 100644 --- a/man/clusterchartOptions.Rd +++ b/man/clusterchartOptions.Rd @@ -27,13 +27,31 @@ clusterchartOptions( \item{size}{The size of the cluster markers.} -\item{width}{The width of the bar-chart.} +\item{width}{The width of the bar-charts.} -\item{height}{The height of the bar-chart.} +\item{height}{The height of the bar-charts.} \item{strokeWidth}{The stroke width in the chart.} -\item{innerRadius}{The inner radius of the pie-chart.} +\item{innerRadius}{The inner radius of the pie-charts.} + +\item{labelBackground}{Should the label have a background? Default is `FALSE`} + +\item{labelFill}{The label background color. Default is `white`} + +\item{labelStroke}{The label stroke color. Default is `black`} + +\item{labelColor}{The label color. Default is `black`} + +\item{labelOpacity}{The label color. Default is `0.9`} + +\item{aggregation}{If `type = "custom"` in the `addClusterCharts` function, this aggregation method will be used.} + +\item{valueField}{If `type = "custom"` in the `addClusterCharts` function, the aggregation will be used on this column.} + +\item{digits}{The amount of digits. Default is `2`} + +\item{sortTitlebyCount}{Should the svg-title be sorted by count or by the categories.} } \description{ Adds options for clusterCharts diff --git a/tests/testthat/test-heightgraph.R b/tests/testthat/test-heightgraph.R index 1118760b..e3b3da34 100644 --- a/tests/testthat/test-heightgraph.R +++ b/tests/testthat/test-heightgraph.R @@ -28,7 +28,6 @@ data <- structure(list( ## TESTS ####################### test_that("heightgraph", { library(sf) - library(geojsonsf) data <- st_transform(data, 4326) data <- data.frame(st_coordinates(data)) diff --git a/tests/testthat/test-movingmarker.R b/tests/testthat/test-movingmarker.R index d48f4dec..0bfdccfe 100644 --- a/tests/testthat/test-movingmarker.R +++ b/tests/testthat/test-movingmarker.R @@ -17,11 +17,12 @@ df <- new("SpatialLinesDataFrame", data = structure(list(Name = structure(1L, le test_that("movingmarker", { - m <- leaflet() %>% + m <- expect_warning( + leaflet() %>% addMovingMarker(data = df, movingOptions = movingMarkerOptions(autostart = TRUE, loop = TRUE), label="I am a pirate!", - popup="Arrr") + popup="Arrr")) expect_is(m, "leaflet") expect_equal(m$x$calls[[1]]$method, "addMovingMarker") @@ -52,11 +53,13 @@ test_that("movingmarker", { ## Data is Simple Feature LINESTRING df1 <- sf::st_as_sf(df) - m <- leaflet() %>% + m <- expect_warning( + leaflet() %>% addMovingMarker(data = df1, movingOptions = movingMarkerOptions(autostart = TRUE, loop = TRUE), label="I am a pirate!", popup="Arrr") + ) expect_is(m, "leaflet") expect_equal(m$x$calls[[1]]$method, "addMovingMarker") deps <- findDependencies(m) @@ -64,49 +67,52 @@ test_that("movingmarker", { ## Data is Simple Feature POINT df1 <- sf::st_as_sf(df)[1,] - df1 <- sf::st_cast(df1, "POINT") - m <- leaflet() %>% + df1 <- expect_warning(sf::st_cast(df1, "POINT")) + m <- expect_warning( + leaflet() %>% addMovingMarker(data = df1, movingOptions = movingMarkerOptions(autostart = TRUE, loop = TRUE), label="I am a pirate!", popup="Arrr") + ) expect_is(m, "leaflet") expect_equal(m$x$calls[[1]]$method, "addMovingMarker") - + dfsf <- sf::st_as_sf(df) + dfsf <- expect_warning(st_cast(dfsf, "POINT")) + dfsf <- st_transform(dfsf, 4326) m <- leaflet() %>% - addMovingMarker(data = df) %>% + addMovingMarker(data = dfsf) %>% startMoving() expect_is(m, "leaflet") expect_equal(m$x$calls[[length(m$x$calls)]]$method, "startMoving") m <- leaflet() %>% - addMovingMarker(data = df) %>% + addMovingMarker(data = dfsf) %>% startMoving() expect_is(m, "leaflet") expect_equal(m$x$calls[[length(m$x$calls)]]$method, "startMoving") m <- leaflet() %>% - addMovingMarker(data = df) %>% + addMovingMarker(data = dfsf) %>% stopMoving() expect_is(m, "leaflet") expect_equal(m$x$calls[[length(m$x$calls)]]$method, "stopMoving") m <- leaflet() %>% - addMovingMarker(data = df) %>% + addMovingMarker(data = dfsf) %>% pauseMoving() expect_is(m, "leaflet") expect_equal(m$x$calls[[length(m$x$calls)]]$method, "pauseMoving") m <- leaflet() %>% - addMovingMarker(data = df) %>% + addMovingMarker(data = dfsf) %>% resumeMoving() expect_is(m, "leaflet") expect_equal(m$x$calls[[length(m$x$calls)]]$method, "resumeMoving") - m <- leaflet() %>% - addMovingMarker(data = df) %>% + addMovingMarker(data = dfsf) %>% addLatLngMoving(latlng = list(33, -67), duration = 2000) expect_is(m, "leaflet") expect_equal(m$x$calls[[length(m$x$calls)]]$method, "addLatLngMoving") @@ -114,7 +120,7 @@ test_that("movingmarker", { expect_equal(m$x$calls[[length(m$x$calls)]]$args[[3]], 2000) m <- leaflet() %>% - addMovingMarker(data = df) %>% + addMovingMarker(data = dfsf) %>% moveToMoving(latlng = list(33, -67), duration = 2000) expect_is(m, "leaflet") expect_equal(m$x$calls[[length(m$x$calls)]]$method, "moveToMoving") @@ -122,7 +128,7 @@ test_that("movingmarker", { expect_equal(m$x$calls[[length(m$x$calls)]]$args[[3]], 2000) m <- leaflet() %>% - addMovingMarker(data = df) %>% + addMovingMarker(data = dfsf) %>% addStationMoving(pointIndex = 2, duration = 5000) expect_is(m, "leaflet") expect_equal(m$x$calls[[length(m$x$calls)]]$method, "addStationMoving")