From 21d1254ed18cfde24799f88faeb4155fa355cfc2 Mon Sep 17 00:00:00 2001 From: trafficonese Date: Sat, 16 Mar 2024 17:49:23 +0000 Subject: [PATCH] Style code (GHA) --- tests/testthat/test-heatmaps.R | 82 ++++++---- tests/testthat/test-map-controls.R | 84 +++++++---- tests/testthat/test-marker.R | 234 ++++++++++++++++++----------- 3 files changed, 248 insertions(+), 152 deletions(-) diff --git a/tests/testthat/test-heatmaps.R b/tests/testthat/test-heatmaps.R index 224103b8..73de5785 100644 --- a/tests/testthat/test-heatmaps.R +++ b/tests/testthat/test-heatmaps.R @@ -2,7 +2,6 @@ library(leaflet) library(leaflet.extras) test_that("heatmaps", { - ## WebGL Heatmap ######################### ts <- leaflet(quakes) %>% addProviderTiles(providers$CartoDB.DarkMatter) %>% @@ -17,16 +16,20 @@ 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) @@ -34,14 +37,16 @@ test_that("heatmaps", { 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) @@ -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))) }) diff --git a/tests/testthat/test-map-controls.R b/tests/testthat/test-map-controls.R index ec5c8977..a7372ad4 100644 --- a/tests/testthat/test-map-controls.R +++ b/tests/testthat/test-map-controls.R @@ -2,7 +2,6 @@ library(leaflet) library(leaflet.extras) test_that("map-control-plugins", { - ## Measure ################### ts <- leaflet() %>% addMeasurePathToolbar() @@ -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") @@ -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") @@ -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") @@ -253,22 +258,26 @@ 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"), @@ -276,7 +285,8 @@ test_that("map-control-plugins", { polyline = "Draw a sexy polyline", rectangle = "Draw a gigantic rectangle", circlemarker = "Make a nice circle" - )) + ) + ) ts <- leaflet() %>% setView(0, 0, 2) %>% @@ -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) %>% @@ -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() %>% @@ -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() %>% @@ -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") @@ -463,5 +482,4 @@ test_that("map-control-plugins", { ts <- ts %>% removeControlGPS() expect_identical(ts$x$calls[[length(ts$x$calls)]]$method, "removeControlGPS") - }) diff --git a/tests/testthat/test-marker.R b/tests/testthat/test-marker.R index 0c65fd17..64af4452 100644 --- a/tests/testthat/test-marker.R +++ b/tests/testthat/test-marker.R @@ -3,9 +3,9 @@ library(leaflet) library(leaflet.extras) test_that("markers", { - ## Data ############## - lng = 49; lat = 11 + lng <- 49 + lat <- 11 cities <- read.csv(textConnection("City,Lat,Long,Pop Boston,42.3601,-71.0589,645966 Hartford,41.7627,-72.6743,125017 @@ -23,7 +23,8 @@ Providence,41.8236,-71.4222,177994")) iconAnchorX = 22, iconAnchorY = 94, shadowUrl = SHADOWURL, shadowWidth = 50, shadowHeight = 64, - shadowAnchorX = 4, shadowAnchorY = 62) + shadowAnchorX = 4, shadowAnchorY = 62 + ) myIconSet <- iconList( greencol = makeIcon(iconUrl = "http://leafletjs.com/examples/custom-icons/leaf-green.png"), @@ -31,12 +32,18 @@ Providence,41.8236,-71.4222,177994")) orangecol = makeIcon(iconUrl = "http://leafletjs.com/examples/custom-icons/leaf-orange.png") ) myIconSetDiffSize <- iconList( - greencol = makeIcon(iconUrl = "http://leafletjs.com/examples/custom-icons/leaf-green.png", - iconWidth = 20, iconHeight = 35), - redcol = makeIcon(iconUrl = "http://leafletjs.com/examples/custom-icons/leaf-red.png", - iconWidth = 40), - orangecol = makeIcon(iconUrl = "http://leafletjs.com/examples/custom-icons/leaf-orange.png", - iconWidth = 30, iconHeight = 50) + greencol = makeIcon( + iconUrl = "http://leafletjs.com/examples/custom-icons/leaf-green.png", + iconWidth = 20, iconHeight = 35 + ), + redcol = makeIcon( + iconUrl = "http://leafletjs.com/examples/custom-icons/leaf-red.png", + iconWidth = 40 + ), + orangecol = makeIcon( + iconUrl = "http://leafletjs.com/examples/custom-icons/leaf-orange.png", + iconWidth = 30, iconHeight = 50 + ) ) ## Bouncing Markers ######################### @@ -60,35 +67,45 @@ Providence,41.8236,-71.4222,177994")) ts <- leaflet() %>% addTiles() %>% addBounceMarkers(lng = lng, lat = lat, icon = list( - iconUrl = ICONURL, iconSize = c(10, 40))) + iconUrl = ICONURL, iconSize = c(10, 40) + )) expect_identical(ts$x$calls[[length(ts$x$calls)]]$method, "addBounceMarkers") expect_identical(ts$x$calls[[length(ts$x$calls)]]$args[[1]], lat) expect_identical(ts$x$calls[[length(ts$x$calls)]]$args[[2]], lng) expect_identical(ts$x$calls[[length(ts$x$calls)]]$args[[3]]$iconUrl$data, ICONURL) - ts <- leaflet(cities) %>% addTiles() %>% - addBounceMarkers(lng = ~Long, lat = ~Lat, - label = ~City) + ts <- leaflet(cities) %>% + addTiles() %>% + addBounceMarkers( + lng = ~Long, lat = ~Lat, + label = ~City + ) expect_identical(ts$x$calls[[length(ts$x$calls)]]$method, "addBounceMarkers") expect_identical(ts$x$calls[[length(ts$x$calls)]]$args[[1]], cities$Lat) expect_identical(ts$x$calls[[length(ts$x$calls)]]$args[[2]], cities$Long) expect_identical(ts$x$calls[[length(ts$x$calls)]]$args[[13]], cities$City) - cities$color <- sample(c("greencol","redcol","orangecol"), nrow(cities), replace = TRUE) - ts <- leaflet(cities) %>% addTiles() %>% - addBounceMarkers(lng = ~Long, lat = ~Lat, - label = ~paste0(City, " - ", color), - icon = ~myIconSet[color]) + cities$color <- sample(c("greencol", "redcol", "orangecol"), nrow(cities), replace = TRUE) + ts <- leaflet(cities) %>% + addTiles() %>% + addBounceMarkers( + lng = ~Long, lat = ~Lat, + label = ~ paste0(City, " - ", color), + icon = ~ myIconSet[color] + ) expect_identical(ts$x$calls[[length(ts$x$calls)]]$method, "addBounceMarkers") expect_identical(ts$x$calls[[length(ts$x$calls)]]$args[[1]], cities$Lat) expect_identical(ts$x$calls[[length(ts$x$calls)]]$args[[2]], cities$Long) expect_identical(ts$x$calls[[length(ts$x$calls)]]$args[[13]], paste0(cities$City, " - ", cities$color)) - ts <- leaflet(cities) %>% addTiles() %>% - addBounceMarkers(lng = ~Long, lat = ~Lat, - label = ~paste0(City, " - ", color), - icon = ~myIconSetDiffSize[color]) + ts <- leaflet(cities) %>% + addTiles() %>% + addBounceMarkers( + lng = ~Long, lat = ~Lat, + label = ~ paste0(City, " - ", color), + icon = ~ myIconSetDiffSize[color] + ) expect_identical(ts$x$calls[[length(ts$x$calls)]]$method, "addBounceMarkers") expect_identical(ts$x$calls[[length(ts$x$calls)]]$args[[1]], cities$Lat) expect_identical(ts$x$calls[[length(ts$x$calls)]]$args[[2]], cities$Long) @@ -120,7 +137,9 @@ Providence,41.8236,-71.4222,177994")) expect_error(weatherIcons(icon = "sunny", markerColor = "transparent")) expect_error(weatherIcons(icon = "sunny", markerColor = "purple12")) - lng = -118.456554; lat = 34.078039; ALABEL = "This is a label" + lng <- -118.456554 + lat <- 34.078039 + ALABEL <- "This is a label" ts <- leaflet() %>% addTiles() %>% addWeatherMarkers( @@ -139,58 +158,82 @@ Providence,41.8236,-71.4222,177994")) expect_identical(ts$x$calls[[length(ts$x$calls)]]$args[[11]], ALABEL) - ts <- leaflet(cities) %>% addTiles() %>% - addWeatherMarkers(lng = ~Long, lat = ~Lat, - label = ~City, - icon = makeWeatherIcon( - icon = "hot", - iconColor = "#ffffff77", - markerColor = "blue" - )) + ts <- leaflet(cities) %>% + addTiles() %>% + addWeatherMarkers( + lng = ~Long, lat = ~Lat, + label = ~City, + icon = makeWeatherIcon( + icon = "hot", + iconColor = "#ffffff77", + markerColor = "blue" + ) + ) expect_identical(ts$x$calls[[length(ts$x$calls)]]$method, "addWeatherMarkers") expect_identical(ts$x$calls[[length(ts$x$calls)]]$args[[1]], cities$Lat) expect_identical(ts$x$calls[[length(ts$x$calls)]]$args[[2]], cities$Long) expect_identical(ts$x$calls[[length(ts$x$calls)]]$args[[11]], cities$City) - expect_error(makeWeatherIcon(icon = "day-sunny", - markerColor = "yellow")) + expect_error(makeWeatherIcon( + icon = "day-sunny", + markerColor = "yellow" + )) iconSet <- weatherIconList( - sunny = makeWeatherIcon(icon = "day-sunny", - markerColor = "orange"), - rain = makeWeatherIcon(icon = "rain", - markerColor = "blue"), - wind = makeWeatherIcon(icon = "wind", - markerColor = "lightblue"), - cloudy = makeWeatherIcon(icon = "cloudy", - markerColor = "gray") + sunny = makeWeatherIcon( + icon = "day-sunny", + markerColor = "orange" + ), + rain = makeWeatherIcon( + icon = "rain", + markerColor = "blue" + ), + wind = makeWeatherIcon( + icon = "wind", + markerColor = "lightblue" + ), + cloudy = makeWeatherIcon( + icon = "cloudy", + markerColor = "gray" + ) ) - cities$weather <- sample(c("sunny","rain","wind","cloudy"), nrow(cities), replace = TRUE) - ts <- leaflet(cities) %>% addTiles() %>% - addWeatherMarkers(lng = ~Long, lat = ~Lat, - label = ~paste0(City, " - ", weather), - icon = ~iconSet[weather]) + cities$weather <- sample(c("sunny", "rain", "wind", "cloudy"), nrow(cities), replace = TRUE) + ts <- leaflet(cities) %>% + addTiles() %>% + addWeatherMarkers( + lng = ~Long, lat = ~Lat, + label = ~ paste0(City, " - ", weather), + icon = ~ iconSet[weather] + ) expect_identical(ts$x$calls[[length(ts$x$calls)]]$method, "addWeatherMarkers") expect_identical(ts$x$calls[[length(ts$x$calls)]]$args[[1]], cities$Lat) expect_identical(ts$x$calls[[length(ts$x$calls)]]$args[[2]], cities$Long) expect_identical(ts$x$calls[[length(ts$x$calls)]]$args[[11]], paste0(cities$City, " - ", cities$weather)) - expect_identical(ts$x$calls[[length(ts$x$calls)]]$args[[3]]$icon, - as.character(unlist(lapply(iconSet[cities$weather], function(x) x$icon)))) - - ts <- leaflet(cities) %>% addTiles() %>% - addWeatherMarkers(lng = ~Long, lat = ~Lat, - label = ~paste0(City, " - ", weather), - clusterOptions = markerClusterOptions(), - icon = ~iconSet[weather]) + expect_identical( + ts$x$calls[[length(ts$x$calls)]]$args[[3]]$icon, + as.character(unlist(lapply(iconSet[cities$weather], function(x) x$icon))) + ) + + ts <- leaflet(cities) %>% + addTiles() %>% + addWeatherMarkers( + lng = ~Long, lat = ~Lat, + label = ~ paste0(City, " - ", weather), + clusterOptions = markerClusterOptions(), + icon = ~ iconSet[weather] + ) expect_identical(ts$x$calls[[length(ts$x$calls)]]$method, "addWeatherMarkers") expect_identical(ts$x$calls[[length(ts$x$calls)]]$args[[1]], cities$Lat) expect_identical(ts$x$calls[[length(ts$x$calls)]]$args[[2]], cities$Long) expect_identical(ts$x$calls[[length(ts$x$calls)]]$args[[11]], paste0(cities$City, " - ", cities$weather)) - expect_identical(ts$x$calls[[length(ts$x$calls)]]$args[[3]]$icon, - as.character(unlist(lapply(iconSet[cities$weather], function(x) x$icon)))) + expect_identical( + ts$x$calls[[length(ts$x$calls)]]$args[[3]]$icon, + as.character(unlist(lapply(iconSet[cities$weather], function(x) x$icon))) + ) ## Pulse Markers ######################### - COL1 <- "#ff0000"; COL2 <- "#0000ff" + COL1 <- "#ff0000" + COL2 <- "#0000ff" iconSet <- pulseIconList( redcol = makePulseIcon(color = COL1), bluecol = makePulseIcon(color = COL2) @@ -211,13 +254,18 @@ Providence,41.8236,-71.4222,177994")) expect_identical(iconSet[1]$red$color, COL1) expect_identical(iconSet[2]$blue$color, COL2) - cities$color <- sample(c("redcol","bluecol"), nrow(cities), replace = TRUE) - ts <- leaflet(cities) %>% addTiles() %>% - addPulseMarkers(lng = ~Long, lat = ~Lat, - label = ~paste0(City, " - ", color), - icon = ~iconSet[color]) + cities$color <- sample(c("redcol", "bluecol"), nrow(cities), replace = TRUE) + ts <- leaflet(cities) %>% + addTiles() %>% + addPulseMarkers( + lng = ~Long, lat = ~Lat, + label = ~ paste0(City, " - ", color), + icon = ~ iconSet[color] + ) - lng = -118.456554; lat = 34.078039; ALABEL = "This is a label" + lng <- -118.456554 + lat <- 34.078039 + ALABEL <- "This is a label" ts <- leaflet() %>% addPulseMarkers( lng = lng, lat = lat, label = ALABEL, @@ -232,10 +280,13 @@ Providence,41.8236,-71.4222,177994")) expect_identical(ts$x$calls[[length(ts$x$calls)]]$args[[3]]$heartbeat, 0.5) - ts <- leaflet(cities) %>% addTiles() %>% - addPulseMarkers(lng = ~Long, lat = ~Lat, - label = ~City, - icon = makePulseIcon()) + ts <- leaflet(cities) %>% + addTiles() %>% + addPulseMarkers( + lng = ~Long, lat = ~Lat, + label = ~City, + icon = makePulseIcon() + ) expect_identical(ts$x$calls[[length(ts$x$calls)]]$method, "addPulseMarkers") expect_identical(ts$x$calls[[length(ts$x$calls)]]$args[[1]], cities$Lat) expect_identical(ts$x$calls[[length(ts$x$calls)]]$args[[2]], cities$Long) @@ -243,15 +294,20 @@ Providence,41.8236,-71.4222,177994")) COLORDER <- c("red", "blue", "red", "red", "blue", "blue") HEARTORDER <- c("0.4", "0.8", "0.4", "0.4", "0.8", "0.8") - icon.pop <- pulseIcons(color = ifelse(cities$Pop < 500000, "blue", "red"), - heartbeat = ifelse(cities$Pop < 500000, "0.8", "0.4")) + icon.pop <- pulseIcons( + color = ifelse(cities$Pop < 500000, "blue", "red"), + heartbeat = ifelse(cities$Pop < 500000, "0.8", "0.4") + ) expect_identical(icon.pop$color, COLORDER) expect_identical(icon.pop$heartbeat, HEARTORDER) - ts <- leaflet(cities) %>% addTiles() %>% - addPulseMarkers(lng = ~Long, lat = ~Lat, - label = ~City, - icon = icon.pop) + ts <- leaflet(cities) %>% + addTiles() %>% + addPulseMarkers( + lng = ~Long, lat = ~Lat, + label = ~City, + icon = icon.pop + ) expect_identical(ts$x$calls[[length(ts$x$calls)]]$method, "addPulseMarkers") expect_identical(ts$x$calls[[length(ts$x$calls)]]$args[[1]], cities$Lat) expect_identical(ts$x$calls[[length(ts$x$calls)]]$args[[2]], cities$Long) @@ -262,14 +318,19 @@ Providence,41.8236,-71.4222,177994")) COLORDER <- c("red", "blue", "red", "red", "blue", "blue") HEARTORDER <- c("0.4", "0.8", "0.4", "0.4", "0.8", "0.8") - icon.pop <- pulseIcons(color = ifelse(cities$PopCat == "blue", "blue", "red"), - heartbeat = ifelse(cities$PopCat == "blue", "0.8", "0.4")) + icon.pop <- pulseIcons( + color = ifelse(cities$PopCat == "blue", "blue", "red"), + heartbeat = ifelse(cities$PopCat == "blue", "0.8", "0.4") + ) expect_identical(icon.pop$color, COLORDER) expect_identical(icon.pop$heartbeat, HEARTORDER) - ts <- leaflet(cities) %>% addTiles() %>% - addPulseMarkers(lng = ~Long, lat = ~Lat, - label = ~City, - icon = icon.pop) + ts <- leaflet(cities) %>% + addTiles() %>% + addPulseMarkers( + lng = ~Long, lat = ~Lat, + label = ~City, + icon = icon.pop + ) expect_identical(ts$x$calls[[length(ts$x$calls)]]$method, "addPulseMarkers") expect_identical(ts$x$calls[[length(ts$x$calls)]]$args[[1]], cities$Lat) expect_identical(ts$x$calls[[length(ts$x$calls)]]$args[[2]], cities$Long) @@ -278,11 +339,14 @@ Providence,41.8236,-71.4222,177994")) expect_identical(ts$x$calls[[length(ts$x$calls)]]$args[[3]]$heartbeat, HEARTORDER) - ts <- leaflet(cities) %>% addTiles() %>% - addPulseMarkers(lng = ~Long, lat = ~Lat, - label = ~City, - clusterOptions = markerClusterOptions(), - icon = icon.pop) + ts <- leaflet(cities) %>% + addTiles() %>% + addPulseMarkers( + lng = ~Long, lat = ~Lat, + label = ~City, + clusterOptions = markerClusterOptions(), + icon = icon.pop + ) expect_identical(ts$x$calls[[length(ts$x$calls)]]$method, "addPulseMarkers") expect_identical(ts$x$calls[[length(ts$x$calls)]]$args[[1]], cities$Lat) expect_identical(ts$x$calls[[length(ts$x$calls)]]$args[[2]], cities$Long) @@ -303,6 +367,4 @@ Providence,41.8236,-71.4222,177994")) # label = ~City, # labelOptions = rep(labelOptions(noHide = T), nrow(cities)), # icon = ~popIcons[PopCat] ) - - })