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

Custom tooltip label for zoom_off does not appear in plot toolbar #271

Open
4 tasks done
MaximilianKrauss opened this issue Jul 28, 2023 · 1 comment
Open
4 tasks done
Assignees
Labels

Comments

@MaximilianKrauss
Copy link

What I do

I work on interactive plots for a German website. Luckily, opts_toolbar(tooltips = list()) takes my translations for a seamless user experience entirely in German. Well, not quite.

What goes wrong

Unfortunately, the custom tooltip label for zoom_off does not appear in the plot toolbar! Instead, I see the English default label. All other custom tooltip labels are visible. Not sure what I mean? Please look at your book example or my screenshots below.

Screenshots

English default tooltip appears for zoom_off (crossed out magnifier):

Custom tooltip is ignored

Custom tooltip appears for zoom_on (empty magnifier):

Custom tooltip is used

All my custom labels are embedded in the HTML output, but the one for zoom_off apparently is ignored/not used somewhere else in your code:

<script type="application/json" data-for="htmlwidget-a04256daf6ffa03bd69b">
  ...
"tooltips":{"lasso_select":"Mit Lasso auswählen","lasso_deselect":"Mit Lasso abwählen","zoom_on":"Ansicht bewegen/zoomen","zoom_off":"Ansicht beibehalten","zoom_rect":"Mit Rechteckauswahl zoomen","zoom_reset":"Ansicht wiederherstellen","saveaspng":"Als PNG-Grafik speichern"}
</script>

How to escape

For now, I force my German label with a literally radical approach: In the <head>of the htmlwidgets::saveWidget()ed HTML code, I search and replace the English default string with my custom tooltip string.

key: "getButtons",
  ...
  zoom_off: { class: "drop", unclass: "neutral", tooltip: "deactivate pan/zoom",
  ...

How to reproduce

  1. Run the code below and wait for the plot widget. Alternatively, use your book example.
  2. Click the zoom_on button (empty magnifier) in the toolbar to enter panning/zoom mode.
  3. Hover over the zoom_off button (crossed out magnifier) to trigger the English default tooltip.
library(ggplot2)
library(ggiraph)

plot <- girafe(code = plot(ggplot(mtcars, aes(x = disp,
                                              y = qsec,
                                              data_id = 1:nrow(mtcars))) +
                              geom_point_interactive()))
plot <- girafe_options(
  plot,
  opts_selection(type = "multiple", only_shiny = FALSE),
  opts_toolbar(
    tooltips = list(
      lasso_select = "Mit Lasso auswählen",
      lasso_deselect = "Mit Lasso abwählen",
      zoom_on = "Ansicht bewegen/zoomen",
      zoom_off = "Ansicht beibehalten", # Ignored
      zoom_rect = "Mit Rechteckauswahl zoomen",
      zoom_reset = "Ansicht wiederherstellen",
      saveaspng = "Als PNG-Grafik speichern"
      )
    )
  )
print(plot)

Created on 2023-07-28 with reprex v2.0.2

Session info
sessioninfo::session_info()
#> ─ Session info ───────────────────────────────────────────────────────────────
#>  setting  value
#>  version  R version 4.3.1 (2023-06-16 ucrt)
#>  os       Windows 10 x64 (build 19045)
#>  system   x86_64, mingw32
#>  ui       RTerm
#>  language (EN)
#>  collate  German_Germany.utf8
#>  ctype    German_Germany.utf8
#>  tz       Europe/Berlin
#>  date     2023-07-28
#>  pandoc   3.1.1 @ C:/Program Files/RStudio/resources/app/bin/quarto/bin/tools/ (via rmarkdown)
#> 
#> ─ Packages ───────────────────────────────────────────────────────────────────
#>  package     * version date (UTC) lib source
#>  cli           3.6.1   2023-03-23 [1] CRAN (R 4.3.0)
#>  colorspace    2.1-0   2023-01-23 [1] CRAN (R 4.3.0)
#>  digest        0.6.33  2023-07-07 [1] CRAN (R 4.3.1)
#>  dplyr         1.1.2   2023-04-20 [1] CRAN (R 4.3.0)
#>  evaluate      0.21    2023-05-05 [1] CRAN (R 4.3.0)
#>  fansi         1.0.4   2023-01-22 [1] CRAN (R 4.3.0)
#>  farver        2.1.1   2022-07-06 [1] CRAN (R 4.3.0)
#>  fastmap       1.1.1   2023-02-24 [1] CRAN (R 4.3.0)
#>  fs            1.6.3   2023-07-20 [1] CRAN (R 4.3.1)
#>  generics      0.1.3   2022-07-05 [1] CRAN (R 4.3.0)
#>  ggiraph     * 0.8.7   2023-03-17 [1] CRAN (R 4.3.1)
#>  ggplot2     * 3.4.2   2023-04-03 [1] CRAN (R 4.3.0)
#>  glue          1.6.2   2022-02-24 [1] CRAN (R 4.3.0)
#>  gtable        0.3.3   2023-03-21 [1] CRAN (R 4.3.0)
#>  htmltools     0.5.5   2023-03-23 [1] CRAN (R 4.3.0)
#>  htmlwidgets   1.6.2   2023-03-17 [1] CRAN (R 4.3.0)
#>  knitr         1.43    2023-05-25 [1] CRAN (R 4.3.0)
#>  labeling      0.4.2   2020-10-20 [1] CRAN (R 4.3.0)
#>  lifecycle     1.0.3   2022-10-07 [1] CRAN (R 4.3.0)
#>  magrittr      2.0.3   2022-03-30 [1] CRAN (R 4.3.0)
#>  munsell       0.5.0   2018-06-12 [1] CRAN (R 4.3.0)
#>  pillar        1.9.0   2023-03-22 [1] CRAN (R 4.3.0)
#>  pkgconfig     2.0.3   2019-09-22 [1] CRAN (R 4.3.0)
#>  purrr         1.0.1   2023-01-10 [1] CRAN (R 4.3.0)
#>  R.cache       0.16.0  2022-07-21 [1] CRAN (R 4.3.0)
#>  R.methodsS3   1.8.2   2022-06-13 [1] CRAN (R 4.3.0)
#>  R.oo          1.25.0  2022-06-12 [1] CRAN (R 4.3.0)
#>  R.utils       2.12.2  2022-11-11 [1] CRAN (R 4.3.0)
#>  R6            2.5.1   2021-08-19 [1] CRAN (R 4.3.0)
#>  Rcpp          1.0.11  2023-07-06 [1] CRAN (R 4.3.1)
#>  reprex        2.0.2   2022-08-17 [1] CRAN (R 4.3.0)
#>  rlang         1.1.1   2023-04-28 [1] CRAN (R 4.3.0)
#>  rmarkdown     2.23    2023-07-01 [1] CRAN (R 4.3.1)
#>  rstudioapi    0.15.0  2023-07-07 [1] CRAN (R 4.3.1)
#>  scales        1.2.1   2022-08-20 [1] CRAN (R 4.3.0)
#>  sessioninfo   1.2.2   2021-12-06 [1] CRAN (R 4.3.0)
#>  styler        1.10.1  2023-06-05 [1] CRAN (R 4.3.0)
#>  systemfonts   1.0.4   2022-02-11 [1] CRAN (R 4.3.0)
#>  tibble        3.2.1   2023-03-20 [1] CRAN (R 4.3.0)
#>  tidyselect    1.2.0   2022-10-10 [1] CRAN (R 4.3.0)
#>  utf8          1.2.3   2023-01-31 [1] CRAN (R 4.3.0)
#>  uuid          1.1-0   2022-04-19 [1] CRAN (R 4.3.0)
#>  vctrs         0.6.3   2023-06-14 [1] CRAN (R 4.3.1)
#>  withr         2.5.0   2022-03-03 [1] CRAN (R 4.3.0)
#>  xfun          0.39    2023-04-20 [1] CRAN (R 4.3.0)
#>  yaml          2.3.7   2023-01-23 [1] CRAN (R 4.3.0)
#> 
#>  [1] C:/Users/maxim/AppData/Local/R/win-library/4.3
#>  [2] C:/Program Files/R/R-4.3.1/library
#> 
#> ──────────────────────────────────────────────────────────────────────────────

Could you please have a look into this? Many thanks for your work! Great package!

Kind regards
Maximilian

When submitting a new issue:

  • Provide the code that is producing the error, it has to be a minimal reproducible example.

  • Provide the results of R command sessionInfo().

  • Make sure you did checked you had the latest version of the package on CRAN (and on github if issue exists with CRAN version).

  • Make sure you searched in the open and closed issues on the github repository.

@davidgohel davidgohel added the bug label Sep 3, 2023
@davidgohel
Copy link
Owner

@sigmapi I can't find how to fix that tooltip issue, it happens (to be confirmed) in toolbars.js in function init.

state is always initialised with "zoom_on".

if (btn.states) {
  key = btn.current_state;
  state = states[key];
}

I am not sure my analysis is ok - I didn't catch where the tooltip values were defined as values for the 'title' attribute. Can you give an hint here?

@sigmapi sigmapi self-assigned this Sep 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants