Skip to content

Commit

Permalink
fix build warnings/errors, add docu
Browse files Browse the repository at this point in the history
  • Loading branch information
trafficonese committed Aug 12, 2024
1 parent 2a8756e commit ae09c30
Show file tree
Hide file tree
Showing 9 changed files with 70 additions and 35 deletions.
5 changes: 3 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ export(unsync)
export(updateHexbin)
export(velocityOptions)
import(leaflet)
importFrom(grDevices,colorRampPalette)
importFrom(htmltools,htmlDependency)
importFrom(htmltools,tagGetAttribute)
importFrom(htmltools,tagList)
Expand Down
23 changes: 18 additions & 5 deletions R/clusterCharts.R
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions R/leaflet.extras2-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#' @import leaflet
#' @importFrom htmltools htmlDependency tagGetAttribute tags tagList
#' @importFrom utils globalVariables adist packageVersion
#' @importFrom grDevices colorRampPalette
## usethis namespace: end
NULL

Expand Down
2 changes: 2 additions & 0 deletions inst/examples/clustercharts_sum.R
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
12 changes: 3 additions & 9 deletions man/addClusterCharts.Rd

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

24 changes: 21 additions & 3 deletions man/clusterchartOptions.Rd

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

1 change: 0 additions & 1 deletion tests/testthat/test-heightgraph.R
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
36 changes: 21 additions & 15 deletions tests/testthat/test-movingmarker.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down Expand Up @@ -52,77 +53,82 @@ 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)
expect_equal(deps[[length(deps)]]$name, "lfx-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")
expect_length(m$x$calls[[length(m$x$calls)]]$args[[2]], 2)
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")
expect_length(m$x$calls[[length(m$x$calls)]]$args[[2]], 2)
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")
Expand Down

0 comments on commit ae09c30

Please sign in to comment.