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

Add hoverable data values for single-bar nanoplots #1519

Merged
merged 5 commits into from
Jan 3, 2024

Conversation

rich-iannone
Copy link
Member

@rich-iannone rich-iannone commented Jan 2, 2024

This PR makes single-bar nanoplots display their values on hover. As these types of nanoplots can have a mix of positive, negative, and zero-value bars, it was important to ensure that the compactly-formatted data values are affixed to the zero-line, with the text anchored on the appropriate side. Zero value labels were adjusted to lie in a more central position (since there is no bar). The user could hover virtually anywhere in the cell and the value will then appear (i.e., the hover area is large for convenience).

Here we also add the interactive_data_values argument to the nanoplot_options() function. This allows for having persistent data values shown on the single-bar nanoplots. This may be desirable in some cases since there is only a single value per nanoplot (i.e., clutter won't be an issue) and having a compactly formatted value present is commonly seen in bar plots.

Here is an example of this:

dplyr::tibble(
  a = c(-20, -10, 0, 10, 5)
) |>
  gt() |>
  cols_nanoplot(
    columns = a,
    plot_type = "bar",
    options = nanoplot_options(
      data_bar_negative_fill_color = "lightblue",
      data_bar_fill_color = "lightgreen",
      data_bar_stroke_color = "forestgreen",
      data_bar_negative_stroke_color = "steelblue",
      interactive_data_values = FALSE
    )
  ) |>
  tab_style(
    style = cell_borders(sides = c("left", "right"), weight = "2px"),
    locations = cells_body(columns = nanoplots)
  )
nanoplot-single-bars-static-values

If that option is unset or TRUE (i.e., the default display) we get this:

nanoplot-single-bars-values

where the screenshot was taken while hovering over the second nanoplot.

Fixes: #1517

@rich-iannone rich-iannone merged commit 49d8a21 into master Jan 3, 2024
12 checks passed
@rich-iannone rich-iannone deleted the nanoplots-single-bar-values branch January 3, 2024 01:07
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

Successfully merging this pull request may close these issues.

Incorporate static/hoverable value labels on single-bar nanoplots
1 participant