Skip to content

Commit

Permalink
fix tooltip label interactivity and conditions
Browse files Browse the repository at this point in the history
  • Loading branch information
LouisManiere committed Jan 30, 2024
1 parent c3049e9 commit 40ab20e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 14 deletions.
21 changes: 12 additions & 9 deletions R/fct_map.R
Original file line number Diff line number Diff line change
Expand Up @@ -219,20 +219,20 @@ map_region_clicked <- function(map,
radius = 3,
weight = 0.5,
opacity = 0.9,
color = "orange",
fillColor = "orange",
color = "#D0D0D0",
fillColor = "#323232",
fillOpacity = 0.9,
popup = ~nomprincip,
group = params_map_group()[["roe"]]
) %>%
# ROE layer hidden by default
# hydrometric stations layer hidden by default
hideGroup(params_map_group()[["roe"]]) %>%
addCircleMarkers(data = data_get_station_hubeau(region_click$id),
radius = 3,
weight = 0.5,
opacity = 0.9,
color = "blue",
fillColor = "blue",
color = "#E5F6FF",
fillColor = "#33B1FF",
fillOpacity = 0.9,
popup = ~libelle_station,
group = params_map_group()[["hydro_station"]]
Expand Down Expand Up @@ -456,12 +456,15 @@ map_metric <- function(map, wms_params = params_wms()$metric,
#' @export
map_dgo_axis <- function(map, selected_axis, region_axis, main_metric, second_metric) {

# create HTML conditional tooltip labels
tooltip_label <- NULL
if (!is.null(main_metric) && is.null(second_metric)){
tooltip_label <- paste0('<span style="color:blue;"> <b>', selected_axis[[main_metric]], '</b> </span>')
tooltip_label <- lapply(paste0('<span style="color:blue;"> <b>', selected_axis[[main_metric]], '</b> </span>'),
htmltools::HTML)
} else if (!is.null(main_metric) && !is.null(second_metric)){
tooltip_label <- paste0('<span style="color:blue;"> <b>', selected_axis[[main_metric]], '</b> </span> <br/>',
'<span style="color:#FC9D5A;"> <b>', selected_axis[[second_metric]], '</b> </span>')
tooltip_label <- lapply(paste0('<span style="color:blue;"> <b>', selected_axis[[main_metric]], '</b> </span> <br/>',
'<span style="color:#FC9D5A;"> <b>', selected_axis[[second_metric]], '</b> </span>'),
htmltools::HTML)
}

map %>%
Expand All @@ -473,7 +476,7 @@ map_dgo_axis <- function(map, selected_axis, region_axis, main_metric, second_me
layerId = ~fid,
weight = 5,
color = "#ffffff00",
label = lapply(tooltip_label, htmltools::HTML),
label = tooltip_label,
opacity = 1,
highlightOptions = highlightOptions(
opacity = 1,
Expand Down
16 changes: 11 additions & 5 deletions R/mod_explore.R
Original file line number Diff line number Diff line change
Expand Up @@ -510,11 +510,6 @@ mod_explore_server <- function(id){
# update profile with new metric selected
if (r_val$profile_display == TRUE){

# update dgo on axis to reset tooltip
leafletProxy("exploremap") %>%
map_dgo_axis(selected_axis = r_val$dgo_axis, region_axis = r_val$network_region_axis,
main_metric = r_val$selected_metric, second_metric = r_val$selected_profile_metric)

proxy_main_axe <-
lg_profile_update_main(
data = r_val$selected_axis_df,
Expand Down Expand Up @@ -544,6 +539,11 @@ mod_explore_server <- function(id){
choices = utile_get_metric_type(params_metrics_choice()),
selected = utile_get_metric_type(params_metrics_choice())[1])

# update dgo on axis to reset tooltip
leafletProxy("exploremap") %>%
map_dgo_axis(selected_axis = r_val$dgo_axis, region_axis = r_val$network_region_axis,
main_metric = r_val$selected_metric, second_metric = r_val$selected_profile_metric)

# plot single axe with metric selected
r_val$plot = lg_profile_main(data = r_val$selected_axis_df,
y = r_val$selected_axis_df[[r_val$selected_metric]],
Expand Down Expand Up @@ -629,6 +629,12 @@ mod_explore_server <- function(id){

updateRadioButtons(session, "profile_metric", selected = character(0))

r_val$selected_profile_metric = NULL
# update dgo on axis to reset tooltip
leafletProxy("exploremap") %>%
map_dgo_axis(selected_axis = r_val$dgo_axis, region_axis = r_val$network_region_axis,
main_metric = r_val$selected_metric, second_metric = r_val$selected_profile_metric)

})

### EVENT FILTER ####
Expand Down

0 comments on commit 40ab20e

Please sign in to comment.