-
-
Notifications
You must be signed in to change notification settings - Fork 4
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
feat(gridView): implement feature (#24) #25
Merged
Changes from 7 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
95cd322
feat(gridView): implement feature (#24)
swsoyee 83a530c
docs(news): update news
swsoyee 67ef3fc
docs(home): add multiple viewers exmaple
swsoyee 23afa5e
style(home): format code
swsoyee 0a4e61c
ci: downgrade package version in lockfile
swsoyee 90653e1
Merge branch 'master' into grid-view
swsoyee b8ef3dc
edit: m_grid()
BradyAJohnston 2730039
docs: update vignette with new m_grid()
BradyAJohnston 1f8cf12
style(grid): format code
swsoyee dd9313e
docs(todo): add some TODO comments
swsoyee File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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,97 @@ | ||
#' Create a grid of viewers that share a WebGL canvas | ||
#' | ||
#' @param viewer a list contains sub-viewers. | ||
#' @param element_id HTML string identifier. | ||
#' @param rows Number of rows in viewer grid. | ||
#' @param cols Number of columns in viewer grid. | ||
#' @param control_all Logical, simaultaneous mouse control of all windows in the | ||
#' grid. | ||
#' @param viewer_config viewer specification to apply to all subviewers. | ||
#' @param width Fixed width for combined viewer (in css units). Ignored when | ||
#' used in a Shiny app -- use the \code{width} parameter in | ||
#' \code{\link[r3dmol]{r3dmolOutput}}. | ||
#' It is not recommended to use this parameter because the widget knows how to | ||
#' adjust its width automatically. | ||
#' @param height Fixed height for combined viewer (in css units). It is | ||
#' recommended to not use this parameter since the widget knows how to adjust | ||
#' its height automatically. | ||
#' | ||
#' @export | ||
#' | ||
#' @examples | ||
#' library(r3dmol) | ||
#' | ||
#' m1 <- r3dmol() %>% | ||
#' m_add_model(data = pdb_6zsl, format = "pdb") %>% | ||
#' m_zoom_to() | ||
#' | ||
#' m2 <- m1 %>% | ||
#' m_set_style(style = m_style_cartoon(color = "spectrum")) | ||
#' | ||
#' m3 <- m1 %>% | ||
#' m_set_style(style = m_style_stick()) | ||
#' | ||
#' m4 <- m1 %>% | ||
#' m_set_style(style = m_style_sphere()) | ||
#' | ||
#' m_grid( | ||
#' viewer = list(m1, m2, m3, m4), | ||
#' control_all = TRUE, | ||
#' viewer_config = m_viewer_spec( | ||
#' backgroundColor = "black" | ||
#' ) | ||
#' ) | ||
m_grid <- function(viewer, | ||
element_id, | ||
rows = NULL, | ||
cols = NULL, | ||
control_all = TRUE, | ||
viewer_config = m_viewer_spec(), | ||
width = NULL, | ||
height = NULL) { | ||
if (missing(element_id)) { | ||
element_id <- (sample(256, 10, replace = TRUE) - 1) %>% | ||
as.hexmode() %>% | ||
format(width = 2) %>% | ||
paste(collapse = "") | ||
} | ||
|
||
if (is.null(rows)) { | ||
rows <- ceiling(sqrt(length(viewer))) | ||
} | ||
|
||
if (is.null(cols)) { | ||
cols <- ceiling(length(viewer) / rows) | ||
} | ||
swsoyee marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
configs <- list( | ||
rows = rows, | ||
cols = cols, | ||
control_all = control_all | ||
) | ||
|
||
x <- list( | ||
viewer = viewer, | ||
element_id = element_id, | ||
configs = configs, | ||
viewer_config = viewer_config, | ||
api = "grid" | ||
) | ||
|
||
widget <- htmlwidgets::createWidget( | ||
name = "r3dmol", | ||
x, | ||
width = width, | ||
height = height, | ||
package = "r3dmol", | ||
elementId = element_id, | ||
sizingPolicy = htmlwidgets::sizingPolicy( | ||
defaultWidth = "100%", | ||
knitr.figure = FALSE, | ||
browser.fill = TRUE, | ||
padding = 0 | ||
) | ||
) | ||
|
||
return(widget) | ||
} |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
brilliant implemantation! I'm really bad at math...