Skip to content

Commit

Permalink
refac: reduce some duplicated code for setting girafe options
Browse files Browse the repository at this point in the history
  • Loading branch information
russHyde committed Apr 16, 2024
1 parent b298a16 commit 43c9507
Showing 1 changed file with 15 additions and 18 deletions.
33 changes: 15 additions & 18 deletions R/ggiraph.R
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 43c9507

Please sign in to comment.