zz_dygraphs_utils.R 1.43 KB
Newer Older
1
2
3
4
5
6
7
8
9
## Code from the last version of the 'dygraphs' package that is only available on GitHub
## Will be removed from airGRteaching when the last ‘dygraphs’ version will be available on the CRAN
## https://github.com/rstudio/dygraphs
## License MIT
## RStudio Team
## Many thanks to J.J. Allaire and Petr Shevtsov



10
.mergeLists <- function (base_list, overlay_list, recursive = TRUE) {
11
12
13
14
15
16
17
18
19
20
  if (length(base_list) == 0)
    overlay_list
  else if (length(overlay_list) == 0)
    base_list
  else {
    merged_list <- base_list
    for (name in names(overlay_list)) {
      base <- base_list[[name]]
      overlay <- overlay_list[[name]]
      if (is.list(base) && is.list(overlay) && recursive)
21
        merged_list[[name]] <- .mergeLists(base, overlay)
22
23
24
25
26
27
28
29
      else {
        merged_list[[name]] <- NULL
        merged_list <- append(merged_list,
                              overlay_list[which(names(overlay_list) %in% name)])
      }
    }
    merged_list
  }
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
}


.resolveStrokePattern <- function (strokePattern) {
  if (is.character(strokePattern)) {
    if (strokePattern == "dotted") 
      strokePattern <- c(2, 2)
    else if (strokePattern == "dashed") 
      strokePattern <- c(7, 3)
    else if (strokePattern == "dotdash") 
      strokePattern <- c(7, 2, 2, 2)
    else if (strokePattern == "solid") 
      strokePattern <- c(1, 0)
    else stop("Invalid stroke pattern: valid values are dotted, ", 
              "dashed, and dotdash")
  }
  strokePattern
}