Skip to content

Commit

Permalink
Style code (GHA)
Browse files Browse the repository at this point in the history
  • Loading branch information
trafficonese committed Sep 1, 2024
1 parent 1dde496 commit e580d92
Show file tree
Hide file tree
Showing 18 changed files with 189 additions and 100 deletions.
2 changes: 1 addition & 1 deletion R/tangram.R
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ tangram_deps <- function() {
addTangram <- function(map, scene = NULL, layerId = NULL, group = NULL,
options = NULL) {
if ((is.null(scene) || !is.character(scene) ||
(!gsub(".*\\.", "", scene) %in% c("yaml", "zip")))) {
(!gsub(".*\\.", "", scene) %in% c("yaml", "zip")))) {
stop(
"The scene must point to a valid .yaml or .zip file.\n",
"See the documentation for further information."
Expand Down
9 changes: 6 additions & 3 deletions R/timeslider.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ timesliderDependencies <- function() {
htmlDependency(
"lfx-timeslider", "1.0.0",
src = system.file("htmlwidgets/lfx-timeslider",
package = "leaflet.extras2"),
package = "leaflet.extras2"
),
stylesheet = "jquery-ui.css",
script = c(
"jquery-ui.min.js",
Expand Down Expand Up @@ -109,8 +110,10 @@ addTimeslider <- function(map, data, radius = 10,

## Add Deps and invoke Leaflet
map$dependencies <- c(map$dependencies, timesliderDependencies())
invokeMethod(map, NULL, "addTimeslider", data, options,
popupOptions, labelOptions) %>%
invokeMethod(
map, NULL, "addTimeslider", data, options,
popupOptions, labelOptions
) %>%
expandLimits(bbox[c(2, 4)], bbox[c(1, 3)])
}

Expand Down
3 changes: 2 additions & 1 deletion R/velocity.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ velocityDependencies <- function() {
htmlDependency(
"lfx-velocity", "1.0.0",
src = system.file("htmlwidgets/lfx-velocity",
package = "leaflet.extras2"),
package = "leaflet.extras2"
),
script = c(
"leaflet-velocity.js",
"leaflet-velocity-bindings.js"
Expand Down
4 changes: 3 additions & 1 deletion data-raw/data-raw.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
gibs_layerslink <- paste0(
system.file("htmlwidgets/lfx-gibs",
package = "leaflet.extras2"), "/gibs_layers_meta.json")
package = "leaflet.extras2"
), "/gibs_layers_meta.json"
)
gibs_layers <- jsonify::from_json(json = gibs_layerslink, simplify = TRUE)
gibs_layers <- data.frame(do.call(rbind, gibs_layers), stringsAsFactors = FALSE)
gibs_layers$title <- as.character(gibs_layers$title)
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-arrowhead.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ test_that("arrowhead", {
"addArrowhead"
)
expect_true(all(names(m$x$calls[[1]]$args[[10]]) %in%
c("yawn", "size", "frequency", "proportionalToTotal")))
c("yawn", "size", "frequency", "proportionalToTotal")))

m <- leaflet() %>% clearArrowhead("groupname")
m$x$calls[[length(m$x$calls)]]$method == "clearArrowhead"
Expand Down
110 changes: 73 additions & 37 deletions tests/testthat/test-clustercharts.R
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
test_that("clustercharts", {

## data ##########
data <- sf::st_as_sf(breweries91)
data$category <- sample(c("Schwer", "Mäßig",
"Leicht", "kein Schaden"),
size = nrow(data), replace = TRUE)
data$category <- sample(
c(
"Schwer", "Mäßig",
"Leicht", "kein Schaden"
),
size = nrow(data), replace = TRUE
)
data$label <- paste0(data$brewery, "<br>", data$address)
data$id <- paste0("ID", seq.int(nrow(data)))
data$popup <- paste0("<h6>", data$brewery,
"</h6><div>", data$address, "</div>")
data$popup <- paste0(
"<h6>", data$brewery,
"</h6><div>", data$address, "</div>"
)
data$tosum <- sample(1:100, nrow(data), replace = TRUE)
data$tosumlabel <- paste("Sum: ", data$tosum)
data$web <- gsub(">(.*?)<", ">", data$tosum, "<", data$web)
data$web <- ifelse(is.na(data$web), "",
paste0("<div class='markerhtml'>", data$web, "</div>"))
paste0("<div class='markerhtml'>", data$web, "</div>")
)

## simple example ##########
m <- leaflet() %>%
Expand Down Expand Up @@ -62,8 +68,10 @@ test_that("clustercharts", {
labels = c("Schwer", "Mäßig", "Leicht", "kein Schaden"),
colors = c("lightblue", "orange", "lightyellow", "lightgreen")
),
popupFields = c("id", "brewery", "address",
"zipcode", "category", "tosum"),
popupFields = c(
"id", "brewery", "address",
"zipcode", "category", "tosum"
),
popupLabels = c("id", "Brauerei", "Addresse", "PLZ", "Art", "tosum")
)
deps <- findDependencies(m)
Expand All @@ -82,8 +90,10 @@ test_that("clustercharts", {
labels = c("Schwer", "Mäßig", "Leicht", "kein Schaden"),
colors = c("lightblue", "orange", "lightyellow", "lightgreen")
),
popupFields = c("id", "brewery", "address",
"zipcode", "category", "tosum")
popupFields = c(
"id", "brewery", "address",
"zipcode", "category", "tosum"
)
)
deps <- findDependencies(m)
expect_equal(deps[[length(deps)]]$name, "lfx-clustercharts")
Expand All @@ -108,8 +118,10 @@ test_that("clustercharts", {
addClusterCharts(
data = data,
categoryMap =
data.frame(colors = c("lightblue", "orange",
"lightyellow", "lightgreen"))
data.frame(colors = c(
"lightblue", "orange",
"lightyellow", "lightgreen"
))
)
)

Expand Down Expand Up @@ -141,8 +153,10 @@ test_that("clustercharts", {
data = data,
categoryField = "category",
categoryMap =
data.frame(colors = c("lightblue", "orange",
"lightyellow", "lightgreen"))
data.frame(colors = c(
"lightblue", "orange",
"lightyellow", "lightgreen"
))
)
)
deps <- findDependencies(m)
Expand Down Expand Up @@ -187,10 +201,14 @@ test_that("clustercharts", {
labels = c("Schwer", "Mäßig", "Leicht", "kein Schaden"),
colors = c("lightblue", "orange", "lightyellow", "lightgreen")
),
popupFields = c("id", "brewery", "address",
"zipcode", "category", "tosum", "tosum2"),
popupLabels = c("id", "Brauerei", "Addresse",
"PLZ", "Art", "tosum", "tosum2"),
popupFields = c(
"id", "brewery", "address",
"zipcode", "category", "tosum", "tosum2"
),
popupLabels = c(
"id", "Brauerei", "Addresse",
"PLZ", "Art", "tosum", "tosum2"
),
label = "label",
options = clusterchartOptions(size = 50)
)
Expand Down Expand Up @@ -226,10 +244,14 @@ test_that("clustercharts", {
labels = c("Schwer", "Mäßig", "Leicht", "kein Schaden"),
colors = c("lightblue", "orange", "lightyellow", "lightgreen")
),
popupFields = c("id", "brewery", "address",
"zipcode", "category", "tosum", "tosum2"),
popupLabels = c("id", "Brauerei", "Addresse",
"PLZ", "Art", "tosum", "tosum2"),
popupFields = c(
"id", "brewery", "address",
"zipcode", "category", "tosum", "tosum2"
),
popupLabels = c(
"id", "Brauerei", "Addresse",
"PLZ", "Art", "tosum", "tosum2"
),
label = "label",
options = clusterchartOptions(size = c(30, 35))
)
Expand Down Expand Up @@ -258,10 +280,14 @@ test_that("clustercharts", {
icons = iconvec
),
options = clusterchartOptions(size = 50),
popupFields = c("id", "brewery", "address",
"zipcode", "category", "tosum", "tosum2"),
popupLabels = c("id", "Brauerei", "Addresse",
"PLZ", "Art", "tosum", "tosum2"),
popupFields = c(
"id", "brewery", "address",
"zipcode", "category", "tosum", "tosum2"
),
popupLabels = c(
"id", "Brauerei", "Addresse",
"PLZ", "Art", "tosum", "tosum2"
),
label = "label"
)
deps <- findDependencies(m)
Expand Down Expand Up @@ -303,10 +329,14 @@ test_that("clustercharts", {
group = "clustermarkers",
layerId = "id",
clusterId = "id",
popupFields = c("id", "brewery", "address",
"zipcode", "category", "tosum", "tosum2"),
popupLabels = c("id", "Brauerei", "Addresse",
"PLZ", "Art", "tosum", "tosum2"),
popupFields = c(
"id", "brewery", "address",
"zipcode", "category", "tosum", "tosum2"
),
popupLabels = c(
"id", "Brauerei", "Addresse",
"PLZ", "Art", "tosum", "tosum2"
),
label = "label",
markerOptions = markerOptions(
interactive = TRUE,
Expand All @@ -318,21 +348,27 @@ test_that("clustercharts", {
riseOnHover = TRUE,
riseOffset = 400
),
legendOptions = list(position = "bottomright",
title = "Unfälle im Jahr 2003"),
legendOptions = list(
position = "bottomright",
title = "Unfälle im Jahr 2003"
),
clusterOptions = markerClusterOptions(
showCoverageOnHover = TRUE,
zoomToBoundsOnClick = TRUE,
spiderfyOnMaxZoom = TRUE,
removeOutsideVisibleBounds = TRUE,
spiderLegPolylineOptions = list(weight = 1.5,
color = "#222", opacity = 0.5),
spiderLegPolylineOptions = list(
weight = 1.5,
color = "#222", opacity = 0.5
),
freezeAtZoom = TRUE,
clusterPane = "clusterpane",
spiderfyDistanceMultiplier = 2
),
labelOptions = labelOptions(opacity = 0.8, textsize = "14px"),
popupOptions = popupOptions(maxWidth = 900,
minWidth = 200, keepInView = TRUE)
popupOptions = popupOptions(
maxWidth = 900,
minWidth = 200, keepInView = TRUE
)
)
})
9 changes: 6 additions & 3 deletions tests/testthat/test-contextmenu.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ test_that("contextmenu", {
contextmenuItems =
context_mapmenuItems(
context_menuItem("Zoom Out", "function(e) {this.zoomOut()}",
disabled = FALSE),
disabled = FALSE
),
"-",
context_menuItem("Zoom In", "function(e) {this.zoomIn()}")
)
Expand Down Expand Up @@ -44,15 +45,17 @@ test_that("contextmenu", {
"showContextmenu"
)
expect_true(all(
colnames(m$x$calls[[length(m$x$calls)]]$args[[1]]) %in% c("lng", "lat")))
colnames(m$x$calls[[length(m$x$calls)]]$args[[1]]) %in% c("lng", "lat")
))

m <- m %>% showContextmenu(lat = 49.79433, lng = 11.50941)
expect_equal(
m$x$calls[[length(m$x$calls)]]$method,
"showContextmenu"
)
expect_true(all(
colnames(m$x$calls[[length(m$x$calls)]]$args[[1]]) %in% c("lng", "lat")))
colnames(m$x$calls[[length(m$x$calls)]]$args[[1]]) %in% c("lng", "lat")
))

m <- m %>% hideContextmenu()
expect_equal(
Expand Down
42 changes: 28 additions & 14 deletions tests/testthat/test-divicon.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ library(sf)
df <- sf::st_as_sf(atlStorms2005)
df <- suppressWarnings(st_cast(df, "POINT"))
df <- df[sample(1:nrow(df), 50, replace = FALSE), ]
df$classes <- sample(x = c("myclass1", "myclass2", "myclass3"),
nrow(df), replace = TRUE)
df$classes <- sample(
x = c("myclass1", "myclass2", "myclass3"),
nrow(df), replace = TRUE
)
df$ID <- paste0("ID_", 1:nrow(df))
df$lon <- st_coordinates(df)[, 1]
df$lat <- st_coordinates(df)[, 2]
Expand All @@ -27,16 +29,20 @@ test_that("addDivicon works", {
className = ~ paste("globalclass", classes),
html = ~ paste0("<div>", Name, "</div>")
)
expect_true(any(sapply(map$dependencies,
function(dep) dep$name == "lfx-divicon")))
expect_true(any(sapply(
map$dependencies,
function(dep) dep$name == "lfx-divicon"
)))
expect_is(map, "leaflet")
expect_identical(map$x$calls[[2]]$method, "addDivicon")
expect_identical(map$x$calls[[2]]$args[[3]], df$ID)
expect_identical(map$x$calls[[2]]$args[[4]], NULL)
expect_identical(map$x$calls[[2]]$args[[5]], leaflet::markerOptions())
expect_identical(map$x$calls[[2]]$args[[6]], paste("globalclass", df$classes))
expect_identical(map$x$calls[[2]]$args[[7]],
paste0("<div>", df$Name, "</div>"))
expect_identical(
map$x$calls[[2]]$args[[7]],
paste0("<div>", df$Name, "</div>")
)
expect_identical(map$x$calls[[2]]$args[[8]], NULL)
expect_identical(map$x$calls[[2]]$args[[9]], NULL)
expect_identical(map$x$calls[[2]]$args[[10]], NULL)
Expand All @@ -45,8 +51,10 @@ test_that("addDivicon works", {
expect_identical(map$x$calls[[2]]$args[[13]], NULL)

# Test 2: Passing a group
df$groups <- sample(x = c("myclass1", "myclass2", "myclass3"),
nrow(df), replace = TRUE)
df$groups <- sample(
x = c("myclass1", "myclass2", "myclass3"),
nrow(df), replace = TRUE
)
map <- generate_test_map() %>%
addDivicon(
data = df,
Expand All @@ -61,8 +69,10 @@ test_that("addDivicon works", {
expect_identical(map$x$calls[[2]]$args[[4]], df$groups)
expect_identical(map$x$calls[[2]]$args[[5]], leaflet::markerOptions())
expect_identical(map$x$calls[[2]]$args[[6]], paste("globalclass", df$classes))
expect_identical(map$x$calls[[2]]$args[[7]],
paste0("<div>", df$Name, "</div>"))
expect_identical(
map$x$calls[[2]]$args[[7]],
paste0("<div>", df$Name, "</div>")
)
expect_identical(map$x$calls[[2]]$args[[8]], NULL)
expect_identical(map$x$calls[[2]]$args[[9]], NULL)
expect_identical(map$x$calls[[2]]$args[[10]], NULL)
Expand All @@ -89,8 +99,10 @@ test_that("addDivicon works", {
expect_identical(map$x$calls[[2]]$args[[4]], df$groups)
expect_identical(map$x$calls[[2]]$args[[5]], leaflet::markerOptions())
expect_identical(map$x$calls[[2]]$args[[6]], paste("globalclass", df$classes))
expect_identical(map$x$calls[[2]]$args[[7]],
paste0("<div>", df$Name, "</div>"))
expect_identical(
map$x$calls[[2]]$args[[7]],
paste0("<div>", df$Name, "</div>")
)
expect_identical(map$x$calls[[2]]$args[[8]], paste0(df$ID, ": ", df$Name))
expect_identical(map$x$calls[[2]]$args[[9]], popupOptions(minWidth = 400))
expect_identical(map$x$calls[[2]]$args[[10]], df$groups)
Expand Down Expand Up @@ -119,8 +131,10 @@ test_that("addDivicon works", {
expect_identical(map$x$calls[[2]]$args[[4]], df$groups)
expect_identical(map$x$calls[[2]]$args[[5]], leaflet::markerOptions())
expect_identical(map$x$calls[[2]]$args[[6]], paste("globalclass", df$classes))
expect_identical(map$x$calls[[2]]$args[[7]],
paste0("<div>", df$Name, "</div>"))
expect_identical(
map$x$calls[[2]]$args[[7]],
paste0("<div>", df$Name, "</div>")
)
expect_identical(map$x$calls[[2]]$args[[8]], paste0(df$ID, ": ", df$Name))
expect_identical(map$x$calls[[2]]$args[[9]], popupOptions(minWidth = 400))
expect_identical(map$x$calls[[2]]$args[[10]], df$groups)
Expand Down
7 changes: 5 additions & 2 deletions tests/testthat/test-heightgraph.R
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,11 @@ data <- structure(
)
),
row.names = 4L, class = c("sf", "data.frame"), sf_column = "geometry",
agr = structure(c(Name = NA_integer_,
MaxWind = NA_integer_, MinPress = NA_integer_),
agr = structure(
c(
Name = NA_integer_,
MaxWind = NA_integer_, MinPress = NA_integer_
),
levels = c("constant", "aggregate", "identity"), class = "factor"
)
)
Expand Down
3 changes: 2 additions & 1 deletion tests/testthat/test-leafletsync.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ test_that("Leaflet Sync works", {
deps <- findDependencies(m)
expect_equal(deps[[length(deps)]]$name, "lfx-leafletsync")
expect_true(all(deps[[length(deps)]]$script %in% c(
"L.Map.Sync.js", "leafletsync-bindings.js")))
"L.Map.Sync.js", "leafletsync-bindings.js"
)))


m <- leaflet() %>%
Expand Down
Loading

0 comments on commit e580d92

Please sign in to comment.