-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
040a1a1
commit 0a77f2f
Showing
1 changed file
with
59 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
#' Create a theme for a custom JBrowse 2 view | ||
#' | ||
#' Creates the necessary configuration string | ||
#' for a custom theme palette for your browser. | ||
#' Accepts up to four hexadecimal colors. For more | ||
#' information on how JBrowse 2 custom themes work, | ||
#' visit \url{https://jbrowse.org/jb2/docs/config_guide#configuring-the-theme} | ||
#' | ||
#' @param primary the primary color of your custom palette | ||
#' @param secondary the secondary color of your custom palette | ||
#' @param tertiary the tertiary color of your custom palette | ||
#' @param quaternary the quaternary color of your custom palette | ||
#' | ||
#' @return | ||
#' @export | ||
#' | ||
#' @examples | ||
#' theme("#311b92") | ||
#' theme("#311b92", "#0097a7") | ||
#' theme("#311b92", "#0097a7", "#f57c00") | ||
#' theme("#311b92", "#0097a7", "#f57c00", "#d50000") | ||
theme <- function(primary, secondary = NULL, tertiary = NULL, quaternary = NULL) { | ||
if (is.null(secondary)) { | ||
secondary_string <- "" | ||
} else { | ||
secondary_string <- stringr::str_glue( | ||
', "secondary": {{ "main": "{secondary}" }}' | ||
) | ||
} | ||
|
||
if (is.null(tertiary)) { | ||
tertiary_string <- "" | ||
} else { | ||
tertiary_string <- stringr::str_glue( | ||
', "tertiary": {{ "main": "{tertiary}" }}' | ||
) | ||
} | ||
|
||
if (is.null(quaternary)) { | ||
quaternary_string <- "" | ||
} else { | ||
quaternary_string <- stringr::str_glue( | ||
', "quaternary": {{ "main": "{quaternary}" }}' | ||
) | ||
} | ||
|
||
as.character( | ||
stringr::str_glue( | ||
"{{ ", | ||
'"palette": {{ ', | ||
'"primary": {{ "main": "{primary}" }}', | ||
"{secondary_string}", | ||
"{tertiary_string}", | ||
"{quaternary_string}", | ||
"}}", | ||
"}}" | ||
) | ||
) | ||
} |