From c8f0e5a44608a47a2a27d6843cf2a5ad8727099f Mon Sep 17 00:00:00 2001 From: Russ Hyde Date: Mon, 11 Mar 2024 15:29:15 +0000 Subject: [PATCH] refac: reduce some duplicated code for setting girafe options --- R/ggiraph.R | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/R/ggiraph.R b/R/ggiraph.R index 0a0f5a2..0b49ced 100644 --- a/R/ggiraph.R +++ b/R/ggiraph.R @@ -23,29 +23,26 @@ create_girafe = function( ) # set options - if (widget_choice == "tree-mutations.rds") { - girafe_options = list( + common_options = list( + ggiraph::opts_sizing(rescale = FALSE), + ggiraph::opts_zoom(max = 5), + ggiraph::opts_tooltip( + css = tooltip_css, + use_fill = FALSE + ) + ) + + plot_specific_options = if (widget_choice == "tree-mutations.rds") { + list( ggiraph::opts_selection(css = "fill:red;"), - ggiraph::opts_selection_inv(css = "fill:grey;"), - ggiraph::opts_sizing(rescale = FALSE), - ggiraph::opts_zoom(max = 5), - ggiraph::opts_tooltip( - css = tooltip_css, - use_fill = FALSE - ) + ggiraph::opts_selection_inv(css = "fill:grey;") ) } else { - girafe_options = list( - ggiraph::opts_selection(type = "single"), - ggiraph::opts_sizing(rescale = FALSE), - ggiraph::opts_zoom(max = 5), - ggiraph::opts_tooltip( - css = tooltip_css, - use_fill = FALSE - ) - ) + list(ggiraph::opts_selection(type = "single")) } + girafe_options = c(plot_specific_options, common_options) + create_widget = function() { ggiraph::girafe( ggobj = ggobj,