Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge options if plugin was already added #158

Merged
merged 1 commit into from
Mar 6, 2017

Conversation

przmv
Copy link
Collaborator

@przmv przmv commented Mar 1, 2017

Initially discussed in #157 (review)

@@ -56,6 +56,15 @@ dyPlugin <- function(dygraph, name, path, options = list(), version = "1.0") {
if (length(options) == 0) {
options <- JS("{}")
}
# merge options if plugin was already added
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I might be missing something, but doesn't this only pick up new options? (i.e. it wouldn't pick up overwriting of an existing option).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it merges new options with the old ones:

old.options <- list(color = "red",
                    fruit = "apple",
                    days = list("Monday", "Tuesday", "Wednesday"),
                    number = 42,
                    figure = "square")
options <- list(color = "blue",
                days = list("Saturday", "Sunday"),
                animal = "cat")

i <- match(names(old.options), names(options))
i <- is.na(i)
if (any(i)) {
  options[names(old.options)[which(i)]] = old.options[which(i)]
}

options
$color
[1] "blue"

$days
$days[[1]]
[1] "Saturday"

$days[[2]]
[1] "Sunday"


$animal
[1] "cat"

$fruit
[1] "apple"

$number
[1] 42

$figure
[1] "square"

Passing such options to a Dygraph plugin instance results in the following JavaScript object:

{
   "animal" : "cat",
   "figure" : "square",
   "days" : [
      "Saturday",
      "Sunday"
   ],
   "fruit" : "apple",
   "number" : 42,
   "color" : "blue"
}

@jjallaire jjallaire merged commit 9faedea into rstudio:master Mar 6, 2017
@jjallaire
Copy link
Member

Could you add a NEWS item for this?

@przmv przmv mentioned this pull request Mar 6, 2017
@przmv
Copy link
Collaborator Author

przmv commented Mar 6, 2017

@jjallaire Done #159

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants