From 69104bb6a979eda069bd4871b2540a1d8518f746 Mon Sep 17 00:00:00 2001 From: pvictor Date: Wed, 30 Dec 2020 11:12:28 +0100 Subject: [PATCH] facets: colors manual fix + floating title --- R/colors.R | 4 ++++ R/facets.R | 13 +++++++++++-- examples/facet_wrap.R | 1 + man/ax_facet_wrap.Rd | 1 + 4 files changed, 17 insertions(+), 2 deletions(-) diff --git a/R/colors.R b/R/colors.R index b321108..97e6fa4 100644 --- a/R/colors.R +++ b/R/colors.R @@ -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) diff --git a/R/facets.R b/R/facets.R index f392881..e0386b3 100644 --- a/R/facets.R +++ b/R/facets.R @@ -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. diff --git a/examples/facet_wrap.R b/examples/facet_wrap.R index 00ba9d8..23a581b 100644 --- a/examples/facet_wrap.R +++ b/examples/facet_wrap.R @@ -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) { diff --git a/man/ax_facet_wrap.Rd b/man/ax_facet_wrap.Rd index 6e07e31..dec5219 100644 --- a/man/ax_facet_wrap.Rd +++ b/man/ax_facet_wrap.Rd @@ -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) {