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

feat(gridView): implement feature (#24) #25

Merged
merged 10 commits into from
Mar 9, 2021
47 changes: 30 additions & 17 deletions R/grid.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,20 @@
#'
#' @param viewer a list contains sub-viewers.
#' @param element_id HTML string identifier.
#' @param configs grid configuration.
#' @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 viewer (in css units). Ignored when used in a
#' Shiny app -- use the \code{width} parameter in
#' @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 viewer (in css units). It is recommended to
#' not use this parameter since the widget knows how to adjust its height
#' 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.
#'
#' @return
#' @export
#'
#' @examples
Expand All @@ -34,13 +36,17 @@
#'
#' m_grid(
#' viewer = list(m1, m2, m3, m4),
#' configs = list(rows = 2, cols = 2, control_all = TRUE),
#' viewer_config = list(backgroundColor = "black")
#' control_all = TRUE,
#' viewer_config = m_viewer_spec(
#' backgroundColor = "black"
#' )
#' )
m_grid <- function(viewer,
element_id,
configs,
viewer_config = list(),
rows = NULL,
cols = NULL,
control_all = TRUE,
viewer_config = m_viewer_spec(),
width = NULL,
height = NULL) {
if (missing(element_id)) {
Expand All @@ -49,14 +55,21 @@ m_grid <- function(viewer,
format(width = 2) %>%
paste(collapse = "")
}
if (missing(configs)) {
configs <- list(
rows = 1,
cols = length(viewer),
control_all = TRUE
)

if (is.null(rows)) {
rows <- ceiling(sqrt(length(viewer)))
}

if (is.null(cols)) {
cols <- ceiling(length(viewer) / rows)
Comment on lines +62 to +67
Copy link
Owner Author

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...

}
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,
Expand Down
32 changes: 19 additions & 13 deletions man/m_grid.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.