Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

geom_path_interactive, hover improperly triggered in interior region of open path #259

Open
ssp3nc3r opened this issue Mar 20, 2023 · 1 comment

Comments

@ssp3nc3r
Copy link

ssp3nc3r commented Mar 20, 2023

In a recent update, presumably of ggiraph, the behavior of geom_path_interactive and geom_line_interactive has changed so that paths seem closed, creating an invisible fill or otherwise blocking hover on the lower, layered line.

In the minimal example below, triangle1 cannot be selected inside triangle 2 (hovering over interior of triangle 2):

library(tidyverse)
library(ggiraph)

triangle1 <- data.frame(
  id = 1, 
  x = c(0, 1, 2, 0.2), 
  y = c(0, 1, 0, 0)
  )

triangle2 <- mutate(
  triangle1, 
  id = 2, 
  x = x + 0.5, 
  y = y + 0.25)

d <- bind_rows(triangle1, triangle2)

p <- ggplot(d) + 
  geom_path_interactive(
    mapping = aes(
      x, y, group = id, 
      data_id = id, tooltip = id),
    color = 'black')

girafe(code = print(p),
       width_svg = 7,
       height_svg = 7,
       options = list(
         opts_sizing(rescale = FALSE),
         opts_toolbar(saveaspng = FALSE),
         opts_hover_inv(css = "stroke-opacity:0.1;fill:none;"),
         opts_hover(css = "stroke-width:3;fill:none;")
       ))

I should add that although I don't think this warning in the help,

IMPORTANT: When applying a fill style with the css argument, be aware that the browser's CSS engine will apply it also to line elements, if there are any that use the hovering feature. This will cause an undesired effect.

To overcome this, supply the argument css using girafe_css(), in order to set the fill style only for the desired elements.

should apply, I've also tried this:

x <- girafe(ggobj = p)
x <- girafe_options(x = x,
     opts_hover_inv(css = girafe_css(
           css = "fill:none;", 
           line = 'stroke-opacity:0.1;fill:none;', 
           area = 'fill:none;')
           ),
         opts_hover(css = girafe_css(
           css = "fill:none;", 
           line = 'stroke-width:3;fill:none;', 
           area = 'fill:none;'), 
           nearest_distance = 0)
      )

but still doesn't behave as expected.

The session information is:

sessionInfo()
R version 4.2.3 (2023-03-15)
Platform: aarch64-apple-darwin20 (64-bit)
Running under: macOS Ventura 13.2.1

Matrix products: default
LAPACK: /Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods  
[7] base     

other attached packages:
 [1] ggiraph_0.8.7   lubridate_1.9.2 forcats_1.0.0  
 [4] stringr_1.5.0   dplyr_1.1.0     purrr_1.0.1    
 [7] readr_2.1.4     tidyr_1.3.0     tibble_3.2.1   
[10] ggplot2_3.4.1   tidyverse_2.0.0

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.10       pillar_1.8.1      compiler_4.2.3   
 [4] tools_4.2.3       digest_0.6.31     uuid_1.1-0       
 [7] downlit_0.4.2     timechange_0.2.0  evaluate_0.20    
[10] memoise_2.0.1     lifecycle_1.0.3   gtable_0.3.2     
[13] pkgconfig_2.0.3   rlang_1.1.0       cli_3.6.0        
[16] rstudioapi_0.14   distill_1.5.1     yaml_2.3.7       
[19] xfun_0.37         fastmap_1.1.1     withr_2.5.0      
[22] knitr_1.42        hms_1.1.2         generics_0.1.3   
[25] vctrs_0.6.0       htmlwidgets_1.6.2 systemfonts_1.0.4
[28] grid_4.2.3        tidyselect_1.2.0  glue_1.6.2       
[31] R6_2.5.1          fansi_1.0.4       rmarkdown_2.20   
[34] tzdb_0.3.0        magrittr_2.0.3    ellipsis_0.3.2   
[37] scales_1.2.1      htmltools_0.5.4   colorspace_2.1-0 
[40] utf8_1.2.3        stringi_1.7.12    munsell_0.5.0    
[43] cachem_1.0.7     
> 
@ssp3nc3r
Copy link
Author

For anyone that needs a workaround for now, line segments work as expected:

d <- d %>% 
  group_by(id) %>%
  mutate(
    xend = lead(x, default = last(x)),
    yend = lead(y, default = last(y))
  ) %>%
  ungroup()

p <- ggplot(d) + 
  geom_segment_interactive(
    mapping = aes(
      x, y, xend = xend, yend = yend, group = id, 
      data_id = id, tooltip = id),
    color = 'black')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant