Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 0 additions & 11 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,19 +1,8 @@
# Generated by roxygen2: do not edit by hand

export(ro_ply_add_theme)
export(ro_ply_cursor)
export(ro_ply_dim)
export(ro_ply_disable_toolbar)
export(ro_ply_focus_linechart)
export(ro_ply_keyboard_nav_barchart)
export(ro_ply_keyboard_nav_bargraph)
export(ro_ply_keyboard_nav_legend)
export(ro_ply_keyboard_nav_linechart)
export(ro_ply_keyboard_nav_trendline)
export(ro_ply_legend_theme)
export(ro_ply_standard)
export(ro_ply_theme)
export(ro_ply_title)
import(rlang)
importFrom(ROvis.utils,
ro_check_if_font_available,
Expand Down
20 changes: 20 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
# ROvis.plotly (development version)

### :hammer_and_wrench: Changed

- **Breaking:** `ro_ply_theme()` now takes the figure as its first argument and returns it
styled, like `ro_gg_theme()`, `ro_gt_theme()` and `ro_e_theme()`, instead of returning a
theme list. Replace `ro_ply_add_theme(fig, ro_ply_theme(...))` with `ro_ply_theme(fig, ...)`.
- Replaced the vignettes "plotly figures in Rijksoverheid style" and "ggplotly and plotly
keyboard accessibility" with one vignette, "plotly in RO style", built around
`ro_ply_standard()`.

### :coffin: Deprecated

- **Breaking:** `ro_ply_add_theme()` is removed; `ro_ply_theme(fig, ...)` applies the theme
directly.
- **Breaking:** `ro_ply_cursor()`, `ro_ply_dim()`, `ro_ply_disable_toolbar()`,
`ro_ply_legend_theme()`, `ro_ply_title()` and the keyboard navigation functions
(`ro_ply_keyboard_nav_barchart()`, `ro_ply_keyboard_nav_bargraph()`,
`ro_ply_keyboard_nav_linechart()`, `ro_ply_keyboard_nav_trendline()`,
`ro_ply_keyboard_nav_legend()`) are now internal. `ro_ply_standard()` applies all of them;
use `ro_ply_theme()` for styling only.

# ROvis.plotly 0.1.0

First release since `ROvis.plotly` was split out of the `ROvis` monolith into its own
Expand Down
20 changes: 0 additions & 20 deletions R/ro_ply_add_theme.R

This file was deleted.

2 changes: 1 addition & 1 deletion R/ro_ply_cursor.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#' @param fig A Plotly figure object created by \code{plotly::plot_ly()} or similar.
#'
#' @return A Plotly figure object with the cursor style set to "default" (arrow).
#' @export
#' @family plotly
#' @family ggplotly
#' @examples
Expand All @@ -14,6 +13,7 @@
#' fig_cursor <- ro_ply_cursor(fig)
#' fig_cursor
#' }
#' @keywords internal
ro_ply_cursor <- function(fig) {
#The default of plotly is a cross, but a cursor is better
fig <- onRender(
Expand Down
2 changes: 1 addition & 1 deletion R/ro_ply_dim.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
#' @param height Desired plot height in pixels. Default is 400.
#'
#' @return A Plotly figure object with updated sizing policy and layout.
#' @export
#' @family plotly
#' @examples
#' \dontrun{
#' fig <- plotly::plot_ly(data = mtcars, x = ~mpg, y = ~hp, type = 'scatter', mode = 'markers')
#' fig_dimmed <- ro_ply_dim(fig, width = 800, height = 500)
#' fig_dimmed
#' }
#' @keywords internal
ro_ply_dim <- function(fig, width = 776, height = 400) {
# Make sure the plot is the correct dimensions and ratio
fig5 <- fig |>
Expand Down
3 changes: 1 addition & 2 deletions R/ro_ply_disable_toolbar.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#'
#' @return A \code{plotly} object without the modebar and with improved legend accessibility.
#'
#' @export
#' @family ggplotly
#' @family plotly
#' @examples
Expand Down Expand Up @@ -42,7 +41,7 @@
#' fig <- ro_ply_disable_toolbar(fig)
#' fig
#' }

#' @keywords internal
ro_ply_disable_toolbar <- function(fig) {
# Remove the modebar for a clean look, as it is not so accessible
fig <- plotly::config(fig, displayModeBar = FALSE)
Expand Down
2 changes: 1 addition & 1 deletion R/ro_ply_focus_linechart.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#'
#' @return HTML code (using `tags$head` and `tags$style`) to be included in a Shiny UI.
#' @family plotly
#' @export
#' @examples
#' if (interactive()) {
#' ui <- fluidPage(
Expand All @@ -23,6 +22,7 @@
#' })
#' }
#' }
#' @export
ro_ply_focus_linechart <- function() {
tags$head(
tags$style(
Expand Down
10 changes: 4 additions & 6 deletions R/ro_ply_keyboard_accessibility.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#' @family ggplotly
#' @return A \code{plotly} object with improved accessibility features for keyboard and screen reader users.
#' @seealso \code{\link{ro_ply_keyboard_nav_bargraph}}
#' @export
#'
#' @examples
#' \dontrun{
Expand Down Expand Up @@ -81,6 +80,7 @@
#' fig <- ro_ply_keyboard_nav_barchart(fig)
#' fig
#' }
#' @keywords internal
ro_ply_keyboard_nav_barchart <- function(fig) {
# Add a java-script so that the tooltip is accessible with the keyboard
fig2 <- onRender(
Expand Down Expand Up @@ -598,7 +598,6 @@ ro_ply_keyboard_nav_barchart <- function(fig) {
#' @return A \code{plotly} object with improved keyboard accessibility.
#' @family ggplotly
#' @family plotly
#' @export
#'
#' @examples
#' \dontrun{
Expand All @@ -623,7 +622,7 @@ ro_ply_keyboard_nav_barchart <- function(fig) {
#' fig <- ro_ply_keyboard_nav_bargraph(fig)
#' fig
#' }

#' @keywords internal
ro_ply_keyboard_nav_bargraph <- function(fig) {
# Add a java-script so that the tooltip is accessible with the keyboard
fig2 <- onRender(
Expand Down Expand Up @@ -1102,7 +1101,6 @@ ro_ply_keyboard_nav_bargraph <- function(fig) {
#'
#' @return A \code{plotly} object with improved keyboard accessibility.
#'
#' @export
#' @family ggplotly
#' @family plotly
#' @examples
Expand Down Expand Up @@ -1136,7 +1134,7 @@ ro_ply_keyboard_nav_bargraph <- function(fig) {
#' fig <- ro_ply_keyboard_nav_trendline(fig)
#' fig
#' }

#' @keywords internal
ro_ply_keyboard_nav_trendline <- function(fig) {
# Add custom Javascript to make the points and lines accessible with the keyboard
fig2 <-
Expand Down Expand Up @@ -1515,7 +1513,6 @@ ro_ply_keyboard_nav_trendline <- function(fig) {
#' @return A \code{plotly} object with improved keyboard accessibility for line charts.
#' @family ggplotly
#' @family plotly
#' @export
#'
#' @examples
#' \dontrun{
Expand All @@ -1537,6 +1534,7 @@ ro_ply_keyboard_nav_trendline <- function(fig) {
#' fig <- ro_ply_keyboard_nav_linechart(fig)
#' fig
#' }
#' @keywords internal
ro_ply_keyboard_nav_linechart <- function(fig) {
fig2 <- onRender(
fig,
Expand Down
2 changes: 1 addition & 1 deletion R/ro_ply_keyboard_nav_legend.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#'
#' @return A \code{plotly} object with improved legend accessibility.
#'
#' @export
#' @family ggplotly
#' @family plotly
#' @examples
Expand Down Expand Up @@ -42,6 +41,7 @@
#' fig <- ro_ply_keyboard_nav_legend(fig)
#' fig
#' }
#' @keywords internal
ro_ply_keyboard_nav_legend <- function(fig) {
fig2 <- onRender(
fig,
Expand Down
2 changes: 1 addition & 1 deletion R/ro_ply_legend_theme.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#' @param fig A Plotly figure object created by \code{plotly::plot_ly()} or similar.
#'
#' @return The Plotly figure object with the custom legend styling applied.
#' @export
#' @family plotly
#' @examples
#' \dontrun{
Expand All @@ -16,6 +15,7 @@
#' fig_styled <- ro_ply_legend_theme(fig)
#' fig_styled
#' }
#' @keywords internal
ro_ply_legend_theme <- function(fig) {
# Add boxes around the legend items instead of the legend itself
fig3 <- onRender(
Expand Down
5 changes: 3 additions & 2 deletions R/ro_ply_standard.R
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
#' @param height Desired plot height in pixels. Default is 400.
#'
#' @returns The Plotly figure object with the custom styling applied and accesibility features applied.
#' @seealso [ro_ply_theme()] for the styling only, without accessibility features.
#' @export
#'
#' @examples
Expand Down Expand Up @@ -187,7 +188,8 @@ ro_ply_standard <- function(
height = 400
) {
# Theming functions
theme <- ro_ply_theme(
fig <- ro_ply_theme(
fig,
barmode,
base_family,
title_color,
Expand Down Expand Up @@ -224,7 +226,6 @@ ro_ply_standard <- function(
tooltip_background_color,
tooltip_font_size
)
fig <- ro_ply_add_theme(fig = fig, theme = theme)
fig <- ro_ply_title(
fig,
y_data = y_data,
Expand Down
26 changes: 15 additions & 11 deletions R/ro_ply_theme.R
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
#' RIVM Plotly Theme List
#' Apply the RO style to a plotly figure
#'
#' Returns a standardized RIVM theme as a list for use with plotly charts,
#' allowing customization of fonts, colors, grid, axis, legend, and tooltip styling.
#' @description
#' `ro_ply_theme()` applies the RO visual style (fonts, colors, grid, axes, legend
#' and tooltip) to a plotly figure. It does not add accessibility features: use
#' [ro_ply_standard()] for that, which is the recommended way to finish a plotly
#' figure. Use `ro_ply_theme()` only when you need the styling alone, for example
#' for a chart that `ro_ply_standard()` does not cover.
#'
#' @param fig A plotly figure object created by \code{plotly::plot_ly()} or
#' \code{plotly::ggplotly()}.
#' @param base_family Font family for all text (default = "RijksoverheidSansWebText").
#' @param title_color Color for the main title text.
#' @param title_size Font size for the main title.
Expand Down Expand Up @@ -48,11 +54,11 @@
#' @param tooltip_font_size Font size for tooltips.
#' @family plotly
#'
#' @return A named list with plotly theming options, suitable for passing
#' to \code{plotly::layout()} or as a theme in a plotly chart.
#' @return The plotly figure with the RO styling applied.
#'
#' @export
#' @seealso [ro_ply_standard()] for the styling plus all accessibility features.
#'
#' @export
#' @examples
#' \dontrun{
#' # Example data: number of cases per age group and sex
Expand All @@ -69,9 +75,6 @@
#' "Onbekend" = ro_color("donkergeel")
#' )
#'
#' # Use ro_ply_theme with barmode = "stack"
#' theme_rivm <- ro_ply_theme(barmode = "stack")
#'
#' # Create the plotly stacked bar chart
#' fig <- plotly::plot_ly(
#' data = stacked_data,
Expand All @@ -89,10 +92,11 @@
#' hoverinfo = "text"
#' )
#'
#' fig <- ro_ply_add_theme(fig, theme_rivm)
#' fig <- ro_ply_theme(fig, barmode = "stack")
#' fig
#' }
ro_ply_theme <- function(
fig,
barmode = "vgroup",

#Font
Expand Down Expand Up @@ -277,5 +281,5 @@ ro_ply_theme <- function(
bargap = 0.1,
hovermode = "closest"
)
return(rivm_theme)
do.call(layout, c(list(fig), rivm_theme))
}
2 changes: 1 addition & 1 deletion R/ro_ply_title.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
#' @family plotly
#' @return The plotly figure object with added (and styled) title and/or axis labels as annotations.
#'
#' @export
#'
#' @examples
#' \dontrun{
Expand All @@ -35,6 +34,7 @@
#' ro_ply_title(fig, y_data = data$'Number of Cases',
#' y_label = "Number of cases", title = "Fancy title", x_label = "groups")
#' }
#' @keywords internal
ro_ply_title <- function(
fig,
y_data = NULL,
Expand Down
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ A version number ending in `.9000` is a development version.

## Usage

A short example of on how to use the ro_ply_add_theme() function in combination with your plotly-object.
For the full functionality, please see the vignettes.
A short example of how to finish a plotly figure with `ro_ply_standard()`, which applies the
RO style and all accessibility features. Use `ro_ply_theme()` instead if you only need the
styling. For the full functionality, see the vignette.

```r
bar_data <- tibble::tibble(
Expand Down Expand Up @@ -65,8 +66,8 @@ fig <- plot_ly(
hoverinfo = "text"
)

# Apply Rijksoverheid / RIVM theme
fig <- ro_ply_add_theme(fig, ro_ply_theme())
# Apply the RO style and accessibility features
fig <- ro_ply_standard(fig, type = "bargraph", title = "Aantal cases per geslacht")
```

## Support
Expand Down
9 changes: 9 additions & 0 deletions man/ROvis.plotly-package.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading