From 8c471242f058616377d898e7883fa63ca5365a13 Mon Sep 17 00:00:00 2001 From: pvictor Date: Wed, 29 Apr 2020 11:35:06 +0200 Subject: [PATCH] axis labs & pre-multi --- R/apex.R | 29 +++++++++++++++++++++++------ R/labs.R | 4 ++-- 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/R/apex.R b/R/apex.R index 854bea9..0ea3038 100644 --- a/R/apex.R +++ b/R/apex.R @@ -77,6 +77,10 @@ apex <- function(data, mapping, type = "column", ..., opts$yaxis$labels$minWidth <- 15 } opts <- modifyList(opts, choose_config(type, mapdata)) + if (isTRUE(getOption("apex.axis.light", default = TRUE))) { + opts$yaxis$labels$style$colors <- "#848484" + opts$xaxis$labels$style$colors <- "#848484" + } ax <- apexchart( ax_opts = opts, width = width, @@ -96,7 +100,7 @@ apex <- function(data, mapping, type = "column", ..., # Construct series make_series <- function(mapdata, mapping, type = NULL, serie_name = NULL) { - if (identical(type, "timeline")) { + if (identical(type, "rangeBar")) { if (!all(c("x", "start", "end") %in% names(mapping))) stop("For timeline charts 'x', 'start', and 'end' aesthetice must be provided.", call. = FALSE) if (is.null(mapdata$group)) @@ -114,14 +118,15 @@ make_series <- function(mapdata, mapping, type = NULL, serie_name = NULL) { } if (is.null(serie_name) & !is.null(mapping$y)) serie_name <- rlang::as_label(mapping$y) - series <- list(list( + series <- list(dropNulls(list( name = serie_name, + type = multi_type(type), data = parse_df(mapdata, add_names = add_names) - )) + ))) if (is_grouped(mapping)) { mapdata <- rename_aes(mapdata) len_grp <- tapply(mapdata$group, mapdata$group, length) - if (length(unique(len_grp)) > 1) { + if (length(unique(len_grp)) > 1 & !isTRUE(type %in% c("scatter", "bubble"))) { warning("apex: all groups must have same length! You can use `tidyr::complete` for this.") } series <- lapply( @@ -130,13 +135,14 @@ make_series <- function(mapdata, mapping, type = NULL, serie_name = NULL) { data <- mapdata[mapdata$group %in% x, ] data <- data[, setdiff(names(data), "group"), drop = FALSE] data <- data[match(x = x_order, table = data$x, nomatch = 0L), , drop = FALSE] - list( + dropNulls(list( name = x, + type = multi_type(type), data = parse_df( data = data, add_names = add_names ) - ) + )) } ) } @@ -206,6 +212,17 @@ correct_type <- function(type) { } } +multi_type <- function(x) { + multis <- c("column", "area", "line", + "spline", "step", "scatter", + "bubble") + if (isTRUE(x %in% multis)) { + x + } else { + NULL + } +} + range_num <- function(x) { if (is.numeric(x)) { range(pretty(x)) diff --git a/R/labs.R b/R/labs.R index b30487c..f7a0742 100644 --- a/R/labs.R +++ b/R/labs.R @@ -41,13 +41,13 @@ ax_labs <- function(ax, title = NULL, subtitle = NULL, x = NULL, y = NULL) { if (!is.null(x)) { ax <- ax_xaxis( ax = ax, - title = list(text = x, style = list(fontWeight = 600, fontSize = "14px")) + title = list(text = x, style = list(fontWeight = 400, fontSize = "14px")) ) } if (!is.null(y)) { ax <- ax_yaxis( ax = ax, - title = list(text = y, style = list(fontWeight = 600, fontSize = "14px")) + title = list(text = y, style = list(fontWeight = 400, fontSize = "14px")) ) } ax