Skip to content

Commit a833229

Browse files
committed
refac: reduce some duplicated code for setting girafe options
1 parent c810977 commit a833229

File tree

1 file changed

+15
-18
lines changed

1 file changed

+15
-18
lines changed

R/ggiraph.R

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -23,29 +23,26 @@ create_girafe = function(
2323
)
2424

2525
# set options
26-
if (widget_choice == "tree-mutations.rds") {
27-
girafe_options = list(
26+
common_options = list(
27+
ggiraph::opts_sizing(rescale = FALSE),
28+
ggiraph::opts_zoom(max = 5),
29+
ggiraph::opts_tooltip(
30+
css = tooltip_css,
31+
use_fill = FALSE
32+
)
33+
)
34+
35+
plot_specific_options = if (widget_choice == "tree-mutations.rds") {
36+
list(
2837
ggiraph::opts_selection(css = "fill:red;"),
29-
ggiraph::opts_selection_inv(css = "fill:grey;"),
30-
ggiraph::opts_sizing(rescale = FALSE),
31-
ggiraph::opts_zoom(max = 5),
32-
ggiraph::opts_tooltip(
33-
css = tooltip_css,
34-
use_fill = FALSE
35-
)
38+
ggiraph::opts_selection_inv(css = "fill:grey;")
3639
)
3740
} else {
38-
girafe_options = list(
39-
ggiraph::opts_selection(type = "single"),
40-
ggiraph::opts_sizing(rescale = FALSE),
41-
ggiraph::opts_zoom(max = 5),
42-
ggiraph::opts_tooltip(
43-
css = tooltip_css,
44-
use_fill = FALSE
45-
)
46-
)
41+
list(ggiraph::opts_selection(type = "single"))
4742
}
4843

44+
girafe_options = c(plot_specific_options, common_options)
45+
4946
create_widget = function() {
5047
ggiraph::girafe(
5148
ggobj = ggobj,

0 commit comments

Comments
 (0)