facets: colors manual fix + floating title

This commit is contained in:
pvictor 2020-12-30 11:12:28 +01:00
parent 12c02b5336
commit 69104bb6a9
4 changed files with 17 additions and 2 deletions

View File

@ -9,6 +9,10 @@
#'
#' @example examples/colors.R
ax_colors_manual <- function(ax, values) {
if (!inherits(ax, "apexcharter"))
stop("ax_colors_manual: ax must be an apexcharter object", call. = FALSE)
ax$x$colors_manual <- values
ax$x$ax_opts$colors <- NULL
groups <- get_groups(ax)
values <- validate_values(values, groups)
ax_colors(ax = ax, values$val)

View File

@ -105,7 +105,8 @@ build_facets <- function(chart) {
facet <- facets_data[[i]]
if (!is_null(labeller) && is_function(labeller)) {
keys <- attr(facet, "keys")
new <- ax_title(new, text = labeller(keys))
text <- labeller(keys)
new <- ax_title(new, text = text, margin = 0, floating = length(text) <= 1)
}
mapdata <- lapply(chart$x$mapping, eval_tidy, data = facet)
if (chart$x$facet$scales %in% c("fixed", "free_y") & chart$x$type %in% c("bar")) {
@ -126,6 +127,9 @@ build_facets <- function(chart) {
if (chart$x$facet$scales %in% c("fixed", "free_y") & chart$x$type %in% c("bar", "column")) {
new <- ax_xaxis(new, labels = list(show = i %in% lrow))
}
if (!is.null(new$x$colors_manual)) {
new <- ax_colors_manual(ax = new, values = new$x$colors_manual)
}
new$height <- chart$x$facet$chart_height
new$x$facet <- NULL
class(new) <- setdiff(class(new), "apex_facet")
@ -161,7 +165,7 @@ get_last_row <- function(mat) {
}
#' @importFrom htmltools tags
build_grid <- function(content, nrow = NULL, ncol = NULL, col_gap = "0px", row_gap = "10px") {
build_grid <- function(content, nrow = NULL, ncol = NULL, col_gap = "0px", row_gap = "5px") {
d <- get_grid_dims(content, nrow, ncol)
tags$div(
class = "apexcharter-facet-container",
@ -176,6 +180,11 @@ build_grid <- function(content, nrow = NULL, ncol = NULL, col_gap = "0px", row_g
apex_grid <- function(..., nrow = NULL, ncol = NULL, col_gap = "0px", row_gap = "10px") {
}
#' Facet wrap for ApexCharts
#'
#' @param ax An \code{apexcharts} \code{htmlwidget} object.

View File

@ -37,6 +37,7 @@ apex(mpg, aes(displ, cty), type = "scatter") %>%
ax_facet_wrap(vars(year, drv))
apex(mpg, aes(displ, cty), type = "scatter") %>%
ax_chart(toolbar = list(show = FALSE)) %>%
ax_facet_wrap(
vars(year, drv),
labeller = function(x) {

View File

@ -74,6 +74,7 @@ apex(mpg, aes(displ, cty), type = "scatter") \%>\%
ax_facet_wrap(vars(year, drv))
apex(mpg, aes(displ, cty), type = "scatter") \%>\%
ax_chart(toolbar = list(show = FALSE)) \%>\%
ax_facet_wrap(
vars(year, drv),
labeller = function(x) {