Skip to content

Commit

Permalink
Style code (GHA)
Browse files Browse the repository at this point in the history
  • Loading branch information
trafficonese committed Mar 16, 2024
1 parent 8fe0297 commit 21d1254
Show file tree
Hide file tree
Showing 3 changed files with 248 additions and 152 deletions.
82 changes: 49 additions & 33 deletions tests/testthat/test-heatmaps.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ library(leaflet)
library(leaflet.extras)

test_that("heatmaps", {

## WebGL Heatmap #########################
ts <- leaflet(quakes) %>%
addProviderTiles(providers$CartoDB.DarkMatter) %>%
Expand All @@ -17,31 +16,37 @@ test_that("heatmaps", {

expect_error({
leaflet(quakes) %>%
addWebGLHeatmap(lng = ~long, lat = ~lat,
gradientTexture = "skyline1")
addWebGLHeatmap(
lng = ~long, lat = ~lat,
gradientTexture = "skyline1"
)
})
ts <- leaflet(quakes) %>%
addWebGLHeatmap(lng = ~long, lat = ~lat, intensity = ~mag,
gradientTexture = "skyline")
addWebGLHeatmap(
lng = ~long, lat = ~lat, intensity = ~mag,
gradientTexture = "skyline"
)
expect_s3_class(ts, "leaflet")
expect_identical(ts$dependencies[[length(ts$dependencies)]]$name, "lfx-webgl-heatmap")
expect_identical(ts$x$calls[[length(ts$x$calls)]]$method, "addWebGLHeatmap")
expect_identical(ts$x$calls[[length(ts$x$calls)]]$args[[1]][,"intensity"], quakes$mag)
expect_identical(ts$x$calls[[length(ts$x$calls)]]$args[[1]][, "intensity"], quakes$mag)
expect_identical(ts$x$calls[[length(ts$x$calls)]]$args[[4]]$size, "30000")
expect_identical(ts$x$calls[[length(ts$x$calls)]]$args[[4]]$units, "m")
expect_identical(ts$x$calls[[length(ts$x$calls)]]$args[[4]]$opacity, 1)
expect_identical(ts$x$calls[[length(ts$x$calls)]]$args[[4]]$gradientTexture, "skyline")
expect_identical(ts$x$calls[[length(ts$x$calls)]]$args[[4]]$alphaRange, 1)

ts <- leaflet(quakes) %>%
addWebGLHeatmap(lng = ~long, lat = ~lat, intensity = ~mag,
size = 20000, group = "somegroup", opacity = 0.1, alphaRange = 0.8,
units = "px",
gradientTexture = "deep-sea")
addWebGLHeatmap(
lng = ~long, lat = ~lat, intensity = ~mag,
size = 20000, group = "somegroup", opacity = 0.1, alphaRange = 0.8,
units = "px",
gradientTexture = "deep-sea"
)
expect_s3_class(ts, "leaflet")
expect_identical(ts$dependencies[[length(ts$dependencies)]]$name, "lfx-webgl-heatmap")
expect_identical(ts$x$calls[[length(ts$x$calls)]]$method, "addWebGLHeatmap")
expect_identical(ts$x$calls[[length(ts$x$calls)]]$args[[1]][,"intensity"], quakes$mag)
expect_identical(ts$x$calls[[length(ts$x$calls)]]$args[[1]][, "intensity"], quakes$mag)
expect_identical(ts$x$calls[[length(ts$x$calls)]]$args[[4]]$size, 20000)
expect_identical(ts$x$calls[[length(ts$x$calls)]]$args[[4]]$units, "px")
expect_identical(ts$x$calls[[length(ts$x$calls)]]$args[[4]]$opacity, 0.1)
Expand Down Expand Up @@ -117,49 +122,60 @@ test_that("heatmaps", {


## addHeatmap #########################
ts <- leaflet(quakes) %>% addProviderTiles(providers$CartoDB.DarkMatter) %>%
setView( 178, -20, 5 ) %>%
addHeatmap(lng = ~long, lat = ~lat, intensity = ~mag,
blur = 20, max = 0.05, radius = 15)
ts <- leaflet(quakes) %>%
addProviderTiles(providers$CartoDB.DarkMatter) %>%
setView(178, -20, 5) %>%
addHeatmap(
lng = ~long, lat = ~lat, intensity = ~mag,
blur = 20, max = 0.05, radius = 15
)
expect_s3_class(ts, "leaflet")
expect_identical(ts$dependencies[[length(ts$dependencies)]]$name, "lfx-heat")
expect_identical(ts$x$calls[[length(ts$x$calls)]]$method, "addHeatmap")
expect_identical(ts$x$calls[[length(ts$x$calls)]]$args[[1]][,"intensity"], quakes[,"mag"])
expect_identical(ts$x$calls[[length(ts$x$calls)]]$args[[1]][, "intensity"], quakes[, "mag"])


ts <- leaflet(quakes) %>% addProviderTiles(providers$CartoDB.DarkMatter) %>%
setView( 178, -20, 5 ) %>%
addHeatmap(lng = ~long, lat = ~lat, intensity = ~mag,
gradient = RColorBrewer::brewer.pal(5, "Reds"),
blur = 20, max = 0.05, radius = 15)
ts <- leaflet(quakes) %>%
addProviderTiles(providers$CartoDB.DarkMatter) %>%
setView(178, -20, 5) %>%
addHeatmap(
lng = ~long, lat = ~lat, intensity = ~mag,
gradient = RColorBrewer::brewer.pal(5, "Reds"),
blur = 20, max = 0.05, radius = 15
)
expect_s3_class(ts, "leaflet")
expect_identical(ts$dependencies[[length(ts$dependencies)]]$name, "lfx-heat")
expect_identical(ts$x$calls[[length(ts$x$calls)]]$method, "addHeatmap")
expect_identical(ts$x$calls[[length(ts$x$calls)]]$args[[1]][,"intensity"], quakes[,"mag"])
expect_identical(ts$x$calls[[length(ts$x$calls)]]$args[[1]][, "intensity"], quakes[, "mag"])
expect_identical(ts$x$calls[[length(ts$x$calls)]]$args[[4]]$max, 0.05)
expect_identical(ts$x$calls[[length(ts$x$calls)]]$args[[4]]$radius, 15)
expect_identical(ts$x$calls[[length(ts$x$calls)]]$args[[4]]$blur, 20)
expect_identical(ts$x$calls[[length(ts$x$calls)]]$args[[4]]$minOpacity, 0.05)


ts <- leaflet(quakes) %>% addProviderTiles(providers$CartoDB.DarkMatter) %>%
setView( 178, -20, 5 ) %>%
addHeatmap(lng = ~long, lat = ~lat, intensity = NULL,
gradient = RColorBrewer::brewer.pal(5, "BrBG"),
blur = 20, max = 0.05, radius = 15)
ts <- leaflet(quakes) %>%
addProviderTiles(providers$CartoDB.DarkMatter) %>%
setView(178, -20, 5) %>%
addHeatmap(
lng = ~long, lat = ~lat, intensity = NULL,
gradient = RColorBrewer::brewer.pal(5, "BrBG"),
blur = 20, max = 0.05, radius = 15
)
expect_s3_class(ts, "leaflet")
expect_identical(ts$dependencies[[length(ts$dependencies)]]$name, "lfx-heat")
expect_identical(ts$x$calls[[length(ts$x$calls)]]$method, "addHeatmap")
expect_identical(ncol(ts$x$calls[[length(ts$x$calls)]]$args[[1]]), 2L)


ts <- leaflet(quakes) %>% addProviderTiles(providers$CartoDB.DarkMatter) %>%
setView( 178, -20, 5 ) %>%
addHeatmap(lng = ~long, lat = ~lat, intensity = 3,
blur = 20, max = 0.05, radius = 15)
ts <- leaflet(quakes) %>%
addProviderTiles(providers$CartoDB.DarkMatter) %>%
setView(178, -20, 5) %>%
addHeatmap(
lng = ~long, lat = ~lat, intensity = 3,
blur = 20, max = 0.05, radius = 15
)
expect_s3_class(ts, "leaflet")
expect_identical(ts$dependencies[[length(ts$dependencies)]]$name, "lfx-heat")
expect_identical(ts$x$calls[[length(ts$x$calls)]]$method, "addHeatmap")
expect_identical(ts$x$calls[[length(ts$x$calls)]]$args[[1]][,"intensity"], rep(3, nrow(quakes)))

expect_identical(ts$x$calls[[length(ts$x$calls)]]$args[[1]][, "intensity"], rep(3, nrow(quakes)))
})
84 changes: 51 additions & 33 deletions tests/testthat/test-map-controls.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ library(leaflet)
library(leaflet.extras)

test_that("map-control-plugins", {

## Measure ###################
ts <- leaflet() %>%
addMeasurePathToolbar()
Expand All @@ -16,11 +15,13 @@ test_that("map-control-plugins", {
expect_identical(ts$x$calls[[length(ts$x$calls)]]$args[[1]]$imperial, FALSE)

ts <- leaflet() %>%
addMeasurePathToolbar(options = measurePathOptions(showOnHover=TRUE,
minPixelDistance = 10,
showDistances = FALSE,
showArea = FALSE,
imperial = TRUE))
addMeasurePathToolbar(options = measurePathOptions(
showOnHover = TRUE,
minPixelDistance = 10,
showDistances = FALSE,
showArea = FALSE,
imperial = TRUE
))
expect_s3_class(ts, "leaflet")
# expect_identical(ts$dependencies[[length(ts$dependencies)]]$name, "lfx-styleeditor")
expect_identical(ts$x$calls[[length(ts$x$calls)]]$method, "setMeasurementOptions")
Expand Down Expand Up @@ -122,8 +123,10 @@ test_that("map-control-plugins", {
expect_identical(ts$x$calls[[length(ts$x$calls)]]$args[[1]]$showFeature, TRUE)

ts <- leaflet() %>%
addReverseSearchOSM(displayText = FALSE, showSearchLocation = FALSE,group = "mygroup",
showBounds = TRUE, fitBounds = FALSE, showFeature = FALSE)
addReverseSearchOSM(
displayText = FALSE, showSearchLocation = FALSE, group = "mygroup",
showBounds = TRUE, fitBounds = FALSE, showFeature = FALSE
)
expect_s3_class(ts, "leaflet")
expect_identical(ts$dependencies[[length(ts$dependencies)]]$name, "lfx-search")
expect_identical(ts$x$calls[[length(ts$x$calls)]]$method, "addReverseSearchOSM")
Expand Down Expand Up @@ -177,9 +180,11 @@ test_that("map-control-plugins", {
expect_identical(ts$x$calls[[length(ts$x$calls)]]$args[[1]]$showFeature, TRUE)

ts <- leaflet() %>%
addReverseSearchGoogle(displayText = FALSE, apikey = "something",
showSearchLocation = FALSE,group = "mygroup",
showBounds = TRUE, fitBounds = FALSE, showFeature = FALSE)
addReverseSearchGoogle(
displayText = FALSE, apikey = "something",
showSearchLocation = FALSE, group = "mygroup",
showBounds = TRUE, fitBounds = FALSE, showFeature = FALSE
)
expect_s3_class(ts, "leaflet")
expect_identical(ts$dependencies[[length(ts$dependencies)]]$name, "lfx-search")
expect_identical(ts$x$calls[[length(ts$x$calls)]]$method, "addReverseSearchGoogle")
Expand Down Expand Up @@ -253,30 +258,35 @@ test_that("map-control-plugins", {
iconAnchorX = 22, iconAnchorY = 94,
shadowUrl = SHADOWURL,
shadowWidth = 50, shadowHeight = 64,
shadowAnchorX = 4, shadowAnchorY = 62)
drawopts <- drawPolylineOptions(allowIntersection = FALSE,
nautic = TRUE, repeatMode = TRUE)
shadowAnchorX = 4, shadowAnchorY = 62
)
drawopts <- drawPolylineOptions(
allowIntersection = FALSE,
nautic = TRUE, repeatMode = TRUE
)
drawpoly <- drawPolygonOptions(showArea = TRUE, metric = FALSE)
drawcirc <- drawCircleOptions(showRadius = FALSE, metric = FALSE, repeatMode = TRUE)
drawrect <- drawRectangleOptions(showArea = FALSE, metric = FALSE)
drawmark <- drawMarkerOptions(zIndexOffset = 10, repeatMode = TRUE, markerIcon = greenLeafIcon)
drawcirm <- drawCircleMarkerOptions(color = "red", fill=FALSE)
drawrect <- drawCircleMarkerOptions(stroke = FALSE, color="orange")
selfeats <- selectedPathOptions(dashArray = c("20, 40"),maintainColor =TRUE)
drawcirm <- drawCircleMarkerOptions(color = "red", fill = FALSE)
drawrect <- drawCircleMarkerOptions(stroke = FALSE, color = "orange")
selfeats <- selectedPathOptions(dashArray = c("20, 40"), maintainColor = TRUE)
hndl <- handlersOptions(
polyline = list(
tooltipStart = "Click It",
tooltipCont = "Keep going",
tooltipEnd = "Make it stop"
))
)
)
toolbr <- toolbarOptions(
actions = list(text = "STOP"),
finish = list(text = "DONE"),
buttons = list(
polyline = "Draw a sexy polyline",
rectangle = "Draw a gigantic rectangle",
circlemarker = "Make a nice circle"
))
)
)

ts <- leaflet() %>%
setView(0, 0, 2) %>%
Expand Down Expand Up @@ -323,8 +333,10 @@ test_that("map-control-plugins", {



drawmark <- drawMarkerOptions(zIndexOffset = 10, repeatMode = TRUE,
markerIcon = greenLeafIcon)
drawmark <- drawMarkerOptions(
zIndexOffset = 10, repeatMode = TRUE,
markerIcon = greenLeafIcon
)
ts <- leaflet() %>%
setView(0, 0, 2) %>%
addProviderTiles(providers$CartoDB.Positron) %>%
Expand All @@ -341,10 +353,13 @@ test_that("map-control-plugins", {
expect_identical(ts$x$calls[[length(ts$x$calls)]]$args[[2]], "draw")

awesomeicon <- leaflet::makeAwesomeIcon(awesomeIcons(
icon = 'ios-close',iconColor = 'black',
library = 'ion',markerColor = "green"))
drawmark <- drawMarkerOptions(zIndexOffset = 10, repeatMode = TRUE,
markerIcon = awesomeicon)
icon = "ios-close", iconColor = "black",
library = "ion", markerColor = "green"
))
drawmark <- drawMarkerOptions(
zIndexOffset = 10, repeatMode = TRUE,
markerIcon = awesomeicon
)

## TODO - this doesnt throw an error but it doesnt work. Console-errors..
ts <- leaflet() %>%
Expand All @@ -363,10 +378,12 @@ test_that("map-control-plugins", {


expect_error(leaflet() %>%
addDrawToolbar(
markerOptions = drawMarkerOptions(zIndexOffset = 10, repeatMode = TRUE,
markerIcon = list("something else")),
))
addDrawToolbar(
markerOptions = drawMarkerOptions(
zIndexOffset = 10, repeatMode = TRUE,
markerIcon = list("something else")
),
))

## Full Screen ##########################
ts <- leaflet() %>%
Expand Down Expand Up @@ -399,9 +416,11 @@ test_that("map-control-plugins", {
expect_s3_class(ts, "leaflet")

ts <- leaflet(options = NULL) %>%
suspendScroll(sleep, sleepTime = 1000, wakeTime = 1200,
sleepNote = "Go to sleep", wakeMessage = "Wake Up",
hoverToWake = FALSE, sleepOpacity = 0.1)
suspendScroll(sleep,
sleepTime = 1000, wakeTime = 1200,
sleepNote = "Go to sleep", wakeMessage = "Wake Up",
hoverToWake = FALSE, sleepOpacity = 0.1
)
expect_identical(ts$x$options$sleepTime, 1000)
expect_identical(ts$x$options$wakeTime, 1200)
expect_identical(ts$x$options$sleepNote, "Go to sleep")
Expand Down Expand Up @@ -463,5 +482,4 @@ test_that("map-control-plugins", {
ts <- ts %>%
removeControlGPS()
expect_identical(ts$x$calls[[length(ts$x$calls)]]$method, "removeControlGPS")

})
Loading

0 comments on commit 21d1254

Please sign in to comment.