facets: added grid_width arg
This commit is contained in:
parent
23dbb5e869
commit
4ef564e605
|
@ -81,10 +81,12 @@ export(vars)
|
||||||
importFrom(ggplot2,aes)
|
importFrom(ggplot2,aes)
|
||||||
importFrom(ggplot2,label_value)
|
importFrom(ggplot2,label_value)
|
||||||
importFrom(ggplot2,vars)
|
importFrom(ggplot2,vars)
|
||||||
|
importFrom(htmltools,css)
|
||||||
importFrom(htmltools,renderTags)
|
importFrom(htmltools,renderTags)
|
||||||
importFrom(htmltools,resolveDependencies)
|
importFrom(htmltools,resolveDependencies)
|
||||||
importFrom(htmltools,tagList)
|
importFrom(htmltools,tagList)
|
||||||
importFrom(htmltools,tags)
|
importFrom(htmltools,tags)
|
||||||
|
importFrom(htmltools,validateCssUnit)
|
||||||
importFrom(htmlwidgets,JS)
|
importFrom(htmlwidgets,JS)
|
||||||
importFrom(htmlwidgets,JSEvals)
|
importFrom(htmlwidgets,JSEvals)
|
||||||
importFrom(htmlwidgets,createWidget)
|
importFrom(htmlwidgets,createWidget)
|
||||||
|
|
19
R/facets.R
19
R/facets.R
|
@ -221,7 +221,7 @@ build_facets <- function(chart) {
|
||||||
# serie_name = chart$x$add_line$serie_name
|
# serie_name = chart$x$add_line$serie_name
|
||||||
# )
|
# )
|
||||||
}
|
}
|
||||||
new$height <- chart$x$facet$chart_height
|
new$height <- chart$height %||% chart$x$facet$chart_height
|
||||||
new$x$facet <- NULL
|
new$x$facet <- NULL
|
||||||
class(new) <- setdiff(class(new), "apex_facet")
|
class(new) <- setdiff(class(new), "apex_facet")
|
||||||
return(new)
|
return(new)
|
||||||
|
@ -262,7 +262,8 @@ get_last_row <- function(mat) {
|
||||||
#' @param scales Should scales be fixed (`"fixed"`, the default),
|
#' @param scales Should scales be fixed (`"fixed"`, the default),
|
||||||
#' free (`"free"`), or free in one dimension (`"free_x"`, `"free_y"`)?
|
#' free (`"free"`), or free in one dimension (`"free_x"`, `"free_y"`)?
|
||||||
#' @param labeller A function with one argument containing for each facet the value of the faceting variable.
|
#' @param labeller A function with one argument containing for each facet the value of the faceting variable.
|
||||||
#' @param chart_height Individual chart height.
|
#' @param chart_height Individual chart height, ignored if an height is defined in `apex()` or `apexcharter()`.
|
||||||
|
#' @param grid_width Total width for the grid, regardless of the number of column.
|
||||||
#'
|
#'
|
||||||
#' @return An [apexchart()] `htmlwidget` object with an additionnal class `"apex_facet"`.
|
#' @return An [apexchart()] `htmlwidget` object with an additionnal class `"apex_facet"`.
|
||||||
#'
|
#'
|
||||||
|
@ -282,7 +283,8 @@ ax_facet_wrap <- function(ax,
|
||||||
ncol = NULL,
|
ncol = NULL,
|
||||||
scales = c("fixed", "free", "free_y", "free_x"),
|
scales = c("fixed", "free", "free_y", "free_x"),
|
||||||
labeller = label_value,
|
labeller = label_value,
|
||||||
chart_height = "300px") {
|
chart_height = "300px",
|
||||||
|
grid_width = "100%") {
|
||||||
if (!inherits(ax, "apex"))
|
if (!inherits(ax, "apex"))
|
||||||
stop("ax_facet_wrap only works with charts generated with apex()", call. = FALSE)
|
stop("ax_facet_wrap only works with charts generated with apex()", call. = FALSE)
|
||||||
scales <- match.arg(scales)
|
scales <- match.arg(scales)
|
||||||
|
@ -295,6 +297,7 @@ ax_facet_wrap <- function(ax,
|
||||||
scales = scales,
|
scales = scales,
|
||||||
labeller = labeller,
|
labeller = labeller,
|
||||||
chart_height = chart_height,
|
chart_height = chart_height,
|
||||||
|
grid_width = grid_width,
|
||||||
type = "wrap"
|
type = "wrap"
|
||||||
)
|
)
|
||||||
class(ax) <- c("apex_facet", class(ax))
|
class(ax) <- c("apex_facet", class(ax))
|
||||||
|
@ -314,7 +317,8 @@ ax_facet_grid <- function(ax,
|
||||||
cols = NULL,
|
cols = NULL,
|
||||||
scales = c("fixed", "free", "free_y", "free_x"),
|
scales = c("fixed", "free", "free_y", "free_x"),
|
||||||
labeller = label_value,
|
labeller = label_value,
|
||||||
chart_height = "300px") {
|
chart_height = "300px",
|
||||||
|
grid_width = "100%") {
|
||||||
if (!inherits(ax, "apex"))
|
if (!inherits(ax, "apex"))
|
||||||
stop("ax_facet_wrap only works with charts generated with apex()", call. = FALSE)
|
stop("ax_facet_wrap only works with charts generated with apex()", call. = FALSE)
|
||||||
scales <- match.arg(scales)
|
scales <- match.arg(scales)
|
||||||
|
@ -330,6 +334,7 @@ ax_facet_grid <- function(ax,
|
||||||
scales = scales,
|
scales = scales,
|
||||||
labeller = labeller,
|
labeller = labeller,
|
||||||
chart_height = chart_height,
|
chart_height = chart_height,
|
||||||
|
grid_width = grid_width,
|
||||||
type = "grid"
|
type = "grid"
|
||||||
)
|
)
|
||||||
class(ax) <- c("apex_facet", class(ax))
|
class(ax) <- c("apex_facet", class(ax))
|
||||||
|
@ -343,6 +348,7 @@ ax_facet_grid <- function(ax,
|
||||||
# Tag ---------------------------------------------------------------------
|
# Tag ---------------------------------------------------------------------
|
||||||
|
|
||||||
#' @importFrom rlang %||%
|
#' @importFrom rlang %||%
|
||||||
|
#' @importFrom htmltools tags css validateCssUnit
|
||||||
build_facet_tag <- function(x) {
|
build_facet_tag <- function(x) {
|
||||||
facets <- build_facets(x)
|
facets <- build_facets(x)
|
||||||
content <- facets$facets
|
content <- facets$facets
|
||||||
|
@ -469,6 +475,11 @@ build_facet_tag <- function(x) {
|
||||||
TAG
|
TAG
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
TAG <- tags$div(
|
||||||
|
style = css(width = validateCssUnit(x$x$facet$grid_width)),
|
||||||
|
class = "apexcharter-facet",
|
||||||
|
TAG
|
||||||
|
)
|
||||||
return(TAG)
|
return(TAG)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,8 @@ ax_facet_wrap(
|
||||||
ncol = NULL,
|
ncol = NULL,
|
||||||
scales = c("fixed", "free", "free_y", "free_x"),
|
scales = c("fixed", "free", "free_y", "free_x"),
|
||||||
labeller = label_value,
|
labeller = label_value,
|
||||||
chart_height = "300px"
|
chart_height = "300px",
|
||||||
|
grid_width = "100\%"
|
||||||
)
|
)
|
||||||
|
|
||||||
ax_facet_grid(
|
ax_facet_grid(
|
||||||
|
@ -22,7 +23,8 @@ ax_facet_grid(
|
||||||
cols = NULL,
|
cols = NULL,
|
||||||
scales = c("fixed", "free", "free_y", "free_x"),
|
scales = c("fixed", "free", "free_y", "free_x"),
|
||||||
labeller = label_value,
|
labeller = label_value,
|
||||||
chart_height = "300px"
|
chart_height = "300px",
|
||||||
|
grid_width = "100\%"
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
\arguments{
|
\arguments{
|
||||||
|
@ -37,7 +39,9 @@ free (\code{"free"}), or free in one dimension (\code{"free_x"}, \code{"free_y"}
|
||||||
|
|
||||||
\item{labeller}{A function with one argument containing for each facet the value of the faceting variable.}
|
\item{labeller}{A function with one argument containing for each facet the value of the faceting variable.}
|
||||||
|
|
||||||
\item{chart_height}{Individual chart height.}
|
\item{chart_height}{Individual chart height, ignored if an height is defined in \code{apex()} or \code{apexcharter()}.}
|
||||||
|
|
||||||
|
\item{grid_width}{Total width for the grid, regardless of the number of column.}
|
||||||
|
|
||||||
\item{rows, cols}{A set of variables or expressions quoted by \code{vars()}
|
\item{rows, cols}{A set of variables or expressions quoted by \code{vars()}
|
||||||
and defining faceting groups on the rows or columns dimension.}
|
and defining faceting groups on the rows or columns dimension.}
|
||||||
|
|
Loading…
Reference in New Issue