From 40ab20e0274828b5137846e4fbcb02bf08acebfd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mani=C3=A8re=20Louis?= Date: Tue, 30 Jan 2024 11:08:15 +0100 Subject: [PATCH] fix tooltip label interactivity and conditions --- R/fct_map.R | 21 ++++++++++++--------- R/mod_explore.R | 16 +++++++++++----- 2 files changed, 23 insertions(+), 14 deletions(-) diff --git a/R/fct_map.R b/R/fct_map.R index 5898e51..4795ef3 100644 --- a/R/fct_map.R +++ b/R/fct_map.R @@ -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"]] @@ -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(' ', selected_axis[[main_metric]], ' ') + tooltip_label <- lapply(paste0(' ', selected_axis[[main_metric]], ' '), + htmltools::HTML) } else if (!is.null(main_metric) && !is.null(second_metric)){ - tooltip_label <- paste0(' ', selected_axis[[main_metric]], '
', - ' ', selected_axis[[second_metric]], ' ') + tooltip_label <- lapply(paste0(' ', selected_axis[[main_metric]], '
', + ' ', selected_axis[[second_metric]], ' '), + htmltools::HTML) } map %>% @@ -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, diff --git a/R/mod_explore.R b/R/mod_explore.R index 7ab3993..8890c2c 100644 --- a/R/mod_explore.R +++ b/R/mod_explore.R @@ -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, @@ -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]], @@ -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 ####