axis labs & pre-multi
This commit is contained in:
parent
6ebd778537
commit
8c471242f0
29
R/apex.R
29
R/apex.R
|
@ -77,6 +77,10 @@ apex <- function(data, mapping, type = "column", ...,
|
||||||
opts$yaxis$labels$minWidth <- 15
|
opts$yaxis$labels$minWidth <- 15
|
||||||
}
|
}
|
||||||
opts <- modifyList(opts, choose_config(type, mapdata))
|
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 <- apexchart(
|
||||||
ax_opts = opts,
|
ax_opts = opts,
|
||||||
width = width,
|
width = width,
|
||||||
|
@ -96,7 +100,7 @@ apex <- function(data, mapping, type = "column", ...,
|
||||||
|
|
||||||
# Construct series
|
# Construct series
|
||||||
make_series <- function(mapdata, mapping, type = NULL, serie_name = NULL) {
|
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)))
|
if (!all(c("x", "start", "end") %in% names(mapping)))
|
||||||
stop("For timeline charts 'x', 'start', and 'end' aesthetice must be provided.", call. = FALSE)
|
stop("For timeline charts 'x', 'start', and 'end' aesthetice must be provided.", call. = FALSE)
|
||||||
if (is.null(mapdata$group))
|
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))
|
if (is.null(serie_name) & !is.null(mapping$y))
|
||||||
serie_name <- rlang::as_label(mapping$y)
|
serie_name <- rlang::as_label(mapping$y)
|
||||||
series <- list(list(
|
series <- list(dropNulls(list(
|
||||||
name = serie_name,
|
name = serie_name,
|
||||||
|
type = multi_type(type),
|
||||||
data = parse_df(mapdata, add_names = add_names)
|
data = parse_df(mapdata, add_names = add_names)
|
||||||
))
|
)))
|
||||||
if (is_grouped(mapping)) {
|
if (is_grouped(mapping)) {
|
||||||
mapdata <- rename_aes(mapdata)
|
mapdata <- rename_aes(mapdata)
|
||||||
len_grp <- tapply(mapdata$group, mapdata$group, length)
|
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.")
|
warning("apex: all groups must have same length! You can use `tidyr::complete` for this.")
|
||||||
}
|
}
|
||||||
series <- lapply(
|
series <- lapply(
|
||||||
|
@ -130,13 +135,14 @@ make_series <- function(mapdata, mapping, type = NULL, serie_name = NULL) {
|
||||||
data <- mapdata[mapdata$group %in% x, ]
|
data <- mapdata[mapdata$group %in% x, ]
|
||||||
data <- data[, setdiff(names(data), "group"), drop = FALSE]
|
data <- data[, setdiff(names(data), "group"), drop = FALSE]
|
||||||
data <- data[match(x = x_order, table = data$x, nomatch = 0L), , drop = FALSE]
|
data <- data[match(x = x_order, table = data$x, nomatch = 0L), , drop = FALSE]
|
||||||
list(
|
dropNulls(list(
|
||||||
name = x,
|
name = x,
|
||||||
|
type = multi_type(type),
|
||||||
data = parse_df(
|
data = parse_df(
|
||||||
data = data,
|
data = data,
|
||||||
add_names = add_names
|
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) {
|
range_num <- function(x) {
|
||||||
if (is.numeric(x)) {
|
if (is.numeric(x)) {
|
||||||
range(pretty(x))
|
range(pretty(x))
|
||||||
|
|
4
R/labs.R
4
R/labs.R
|
@ -41,13 +41,13 @@ ax_labs <- function(ax, title = NULL, subtitle = NULL, x = NULL, y = NULL) {
|
||||||
if (!is.null(x)) {
|
if (!is.null(x)) {
|
||||||
ax <- ax_xaxis(
|
ax <- ax_xaxis(
|
||||||
ax = ax,
|
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)) {
|
if (!is.null(y)) {
|
||||||
ax <- ax_yaxis(
|
ax <- ax_yaxis(
|
||||||
ax = ax,
|
ax = ax,
|
||||||
title = list(text = y, style = list(fontWeight = 600, fontSize = "14px"))
|
title = list(text = y, style = list(fontWeight = 400, fontSize = "14px"))
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
ax
|
ax
|
||||||
|
|
Loading…
Reference in New Issue