Skip to content

Commit fa93fd1

Browse files
committed
simplify config()
1 parent 86a839b commit fa93fd1

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

R/layout.R

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -65,20 +65,29 @@ rangeslider <- function(p, ...) {
6565

6666
config <- function(p, ...) {
6767
attrs <- list(...)
68-
# accumulate these attributes
68+
# make sure we have the right defaults
69+
p$x$config <- p$x$config %||% list()
70+
p$x$config[["modeBarButtonsToRemove"]] <-
71+
p$x$config[["modeBarButtonsToRemove"]] %||% 'sendDataToCloud'
72+
p$x$config[["modeBarButtonsToAdd"]] <-
73+
p$x$config[["modeBarButtonsToAdd"]] %||% list(sharingButton())
74+
75+
# now accumulate
76+
p$x$config[["modeBarButtonsToAdd"]] <- c(
77+
p$x$config[["modeBarButtonsToAdd"]],
78+
attrs[["modeBarButtonsToAdd"]]
79+
)
6980
p$x$config[["modeBarButtonsToRemove"]] <- c(
70-
p$x$config[["modeBarButtonsToRemove"]] %||% 'sendDataToCloud',
81+
p$x$config[["modeBarButtonsToRemove"]],
7182
attrs[["modeBarButtonsToRemove"]]
7283
)
73-
# include the plotly book collaboration link?
74-
removeCollab <- "Collaborate" %in% p$x$config[["modeBarButtonsToRemove"]]
75-
if (length(p$x$config[["modeBarButtonsToRemove"]])) {
84+
85+
# ensure array
86+
if (length(p$x$config[["modeBarButtonsToRemove"]]) == 1) {
7687
p$x$config[["modeBarButtonsToRemove"]] <- list(p$x$config[["modeBarButtonsToRemove"]])
7788
}
78-
p$x$config[["modeBarButtonsToAdd"]] <- c(
79-
if (!removeCollab) list(sharingButton()),
80-
attrs[["modeBarButtonsToAdd"]]
81-
)
89+
90+
# overwrite the other arguments
8291
attrs <- attrs[!grepl("modeBarButtonsTo", names(attrs))]
8392
p$x$config <- modify_list(p$x$config, attrs)
8493
p

0 commit comments

Comments
 (0)