formating & examples
This commit is contained in:
parent
e3d9c9ffc9
commit
c8c23aa43b
|
@ -1,8 +1,4 @@
|
|||
|
||||
|
||||
|
||||
|
||||
|
||||
# ApexCharts API ----------------------------------------------------------
|
||||
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@ apexchart <- function(ax_opts = list(), auto_update = TRUE, width = NULL, height
|
|||
if (isTRUE(auto_update)) {
|
||||
auto_update <- config_update()
|
||||
}
|
||||
|
||||
|
||||
x <- list(
|
||||
ax_opts = ax_opts,
|
||||
auto_update = auto_update
|
||||
|
@ -34,24 +34,7 @@ apexchart <- function(ax_opts = list(), auto_update = TRUE, width = NULL, height
|
|||
height = height,
|
||||
package = "apexcharter",
|
||||
elementId = elementId,
|
||||
preRenderHook = function(widget) {
|
||||
if (!is.null(widget$x$ax_opts$chart$defaultLocale)) {
|
||||
defaultLocale <- widget$x$ax_opts$chart$defaultLocale
|
||||
defaultLocale <- match.arg(
|
||||
arg = defaultLocale,
|
||||
choices = c("ca", "de", "el", "en", "es", "fi", "fr", "hi", "hr", "hy",
|
||||
"id", "it", "ko", "nl", "pt-br", "ru", "se", "tr", "ua")
|
||||
)
|
||||
if (!is.null(widget$x$ax_opts$chart$locales)) {
|
||||
warning("defaultLocale is used but will be ignored since a custom array for locales is provided.")
|
||||
} else {
|
||||
path <- system.file(file.path("htmlwidgets/lib/apexcharts-locales", paste0(defaultLocale, ".json")), package = "apexcharter")
|
||||
locale <- jsonlite::fromJSON(txt = path)
|
||||
widget$x$ax_opts$chart$locales <- list(locale)
|
||||
}
|
||||
}
|
||||
widget
|
||||
},
|
||||
preRenderHook = add_locale,
|
||||
sizingPolicy = htmlwidgets::sizingPolicy(
|
||||
defaultWidth = "100%",
|
||||
defaultHeight = "100%",
|
||||
|
@ -63,12 +46,39 @@ apexchart <- function(ax_opts = list(), auto_update = TRUE, width = NULL, height
|
|||
browser.fill = TRUE,
|
||||
viewer.suppress = FALSE,
|
||||
browser.external = TRUE,
|
||||
padding = 20
|
||||
padding = 0
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
add_locale <- function(widget) {
|
||||
if (!is.null(widget$x$ax_opts$chart$defaultLocale)) {
|
||||
defaultLocale <- widget$x$ax_opts$chart$defaultLocale
|
||||
defaultLocale <- match.arg(
|
||||
arg = defaultLocale,
|
||||
choices = c("ca", "de", "el", "en", "es", "fi", "fr", "hi", "hr", "hy",
|
||||
"id", "it", "ko", "nl", "pt-br", "ru", "se", "tr", "ua")
|
||||
)
|
||||
if (!is.null(widget$x$ax_opts$chart$locales)) {
|
||||
warning(
|
||||
"defaultLocale is used but will be ignored since",
|
||||
" a custom array for locales is provided."
|
||||
)
|
||||
} else {
|
||||
path <- system.file(
|
||||
file.path("htmlwidgets/lib/apexcharts-locales", paste0(defaultLocale, ".json")),
|
||||
package = "apexcharter"
|
||||
)
|
||||
locale <- jsonlite::fromJSON(txt = path)
|
||||
widget$x$ax_opts$chart$locales <- list(locale)
|
||||
}
|
||||
}
|
||||
widget
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
#' Configuration for auto update
|
||||
#'
|
||||
|
|
13
R/utils.R
13
R/utils.R
|
@ -5,7 +5,6 @@ dropNulls <- function(x) {
|
|||
x[!vapply(x, is.null, FUN.VALUE = logical(1))]
|
||||
}
|
||||
|
||||
|
||||
`%||%` <- function(x, y) {
|
||||
if (!is.null(x)) x else y
|
||||
}
|
||||
|
@ -32,7 +31,11 @@ formatNoSci <- function(x) {
|
|||
if (is.null(ax$x$ax_opts[[name]])) {
|
||||
ax$x$ax_opts[[name]] <- list(...)
|
||||
} else {
|
||||
ax$x$ax_opts[[name]] <- utils::modifyList(x = ax$x$ax_opts[[name]], val = list(...), keep.null = TRUE)
|
||||
ax$x$ax_opts[[name]] <- utils::modifyList(
|
||||
x = ax$x$ax_opts[[name]],
|
||||
val = list(...),
|
||||
keep.null = TRUE
|
||||
)
|
||||
}
|
||||
|
||||
return(ax)
|
||||
|
@ -52,7 +55,11 @@ formatNoSci <- function(x) {
|
|||
if (is.null(ax$x$ax_opts[[name]])) {
|
||||
ax$x$ax_opts[[name]] <- l
|
||||
} else {
|
||||
ax$x$ax_opts[[name]] <- utils::modifyList(x = ax$x$ax_opts[[name]], val = l, keep.null = TRUE)
|
||||
ax$x$ax_opts[[name]] <- utils::modifyList(
|
||||
x = ax$x$ax_opts[[name]],
|
||||
val = l,
|
||||
keep.null = TRUE
|
||||
)
|
||||
}
|
||||
|
||||
return(ax)
|
||||
|
|
|
@ -1,13 +1,21 @@
|
|||
library(dplyr)
|
||||
data("diamonds", package = "ggplot2")
|
||||
|
||||
# Stack bar type
|
||||
## Stack bar type
|
||||
# default is dodge
|
||||
apex(
|
||||
data = count(diamonds, cut, color),
|
||||
mapping = aes(x = cut, y = n, fill = color)
|
||||
)
|
||||
|
||||
# stack
|
||||
apex(
|
||||
data = count(diamonds, cut, color),
|
||||
mapping = aes(x = cut, y = n, fill = color)
|
||||
) %>%
|
||||
ax_chart(stacked = TRUE)
|
||||
|
||||
# stack filled
|
||||
apex(
|
||||
data = count(diamonds, cut, color),
|
||||
mapping = aes(x = cut, y = n, fill = color)
|
||||
|
@ -15,12 +23,49 @@ apex(
|
|||
ax_chart(stacked = TRUE, stackType = "100%")
|
||||
|
||||
|
||||
# Toolbar
|
||||
|
||||
|
||||
# Toolbar --------------------------------------
|
||||
|
||||
# Hide the toolbar
|
||||
apex(
|
||||
data = count(diamonds, cut, color),
|
||||
mapping = aes(x = cut, y = n, fill = color)
|
||||
) %>%
|
||||
ax_chart(toolbar = list(show = FALSE))
|
||||
|
||||
|
||||
|
||||
# Hide download buttons
|
||||
data("economics", package = "ggplot2")
|
||||
apex(
|
||||
data = economics,
|
||||
mapping = aes(x = date, y = pce),
|
||||
type = "line"
|
||||
) %>%
|
||||
ax_chart(
|
||||
toolbar = list(tools= list(download = FALSE))
|
||||
)
|
||||
|
||||
|
||||
|
||||
# Zoom -----------------------------------------
|
||||
|
||||
# Disable
|
||||
apex(
|
||||
data = economics,
|
||||
mapping = aes(x = date, y = pce),
|
||||
type = "line"
|
||||
) %>%
|
||||
ax_chart(
|
||||
zoom = list(enabled = FALSE)
|
||||
)
|
||||
|
||||
|
||||
# Auto-scale Y axis
|
||||
apex(
|
||||
data = economics,
|
||||
mapping = aes(x = date, y = pce),
|
||||
type = "line"
|
||||
) %>%
|
||||
ax_chart(
|
||||
zoom = list(autoScaleYaxis = TRUE)
|
||||
)
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
|
||||
# Localization ---------------------------------
|
||||
|
||||
|
||||
# Use included localization config
|
||||
dat <- data.frame(
|
||||
x = Sys.Date() + 1:20,
|
||||
|
@ -18,7 +22,7 @@ apex(dat, aes(x, y), "line") %>%
|
|||
apex(dat, aes(x, y), "line") %>%
|
||||
ax_chart(locales = list(
|
||||
list(
|
||||
name = "en", # override en locale
|
||||
name = "en", # override 'en' locale
|
||||
options = list(
|
||||
toolbar = list(
|
||||
exportToSVG = "GET SVG",
|
||||
|
|
|
@ -82,13 +82,21 @@ Chart parameters
|
|||
library(dplyr)
|
||||
data("diamonds", package = "ggplot2")
|
||||
|
||||
# Stack bar type
|
||||
## Stack bar type
|
||||
# default is dodge
|
||||
apex(
|
||||
data = count(diamonds, cut, color),
|
||||
mapping = aes(x = cut, y = n, fill = color)
|
||||
)
|
||||
|
||||
# stack
|
||||
apex(
|
||||
data = count(diamonds, cut, color),
|
||||
mapping = aes(x = cut, y = n, fill = color)
|
||||
) \%>\%
|
||||
ax_chart(stacked = TRUE)
|
||||
|
||||
# stack filled
|
||||
apex(
|
||||
data = count(diamonds, cut, color),
|
||||
mapping = aes(x = cut, y = n, fill = color)
|
||||
|
@ -96,15 +104,56 @@ apex(
|
|||
ax_chart(stacked = TRUE, stackType = "100\%")
|
||||
|
||||
|
||||
# Toolbar
|
||||
|
||||
|
||||
# Toolbar --------------------------------------
|
||||
|
||||
# Hide the toolbar
|
||||
apex(
|
||||
data = count(diamonds, cut, color),
|
||||
mapping = aes(x = cut, y = n, fill = color)
|
||||
) \%>\%
|
||||
ax_chart(toolbar = list(show = FALSE))
|
||||
|
||||
|
||||
|
||||
# Hide download buttons
|
||||
data("economics", package = "ggplot2")
|
||||
apex(
|
||||
data = economics,
|
||||
mapping = aes(x = date, y = pce),
|
||||
type = "line"
|
||||
) \%>\%
|
||||
ax_chart(
|
||||
toolbar = list(tools= list(download = FALSE))
|
||||
)
|
||||
|
||||
|
||||
|
||||
# Zoom -----------------------------------------
|
||||
|
||||
# Disable
|
||||
apex(
|
||||
data = economics,
|
||||
mapping = aes(x = date, y = pce),
|
||||
type = "line"
|
||||
) \%>\%
|
||||
ax_chart(
|
||||
zoom = list(enabled = FALSE)
|
||||
)
|
||||
|
||||
|
||||
# Auto-scale Y axis
|
||||
apex(
|
||||
data = economics,
|
||||
mapping = aes(x = date, y = pce),
|
||||
type = "line"
|
||||
) \%>\%
|
||||
ax_chart(
|
||||
zoom = list(autoScaleYaxis = TRUE)
|
||||
)
|
||||
|
||||
# Localization ---------------------------------
|
||||
|
||||
|
||||
# Use included localization config
|
||||
dat <- data.frame(
|
||||
x = Sys.Date() + 1:20,
|
||||
|
@ -125,7 +174,7 @@ apex(dat, aes(x, y), "line") \%>\%
|
|||
apex(dat, aes(x, y), "line") \%>\%
|
||||
ax_chart(locales = list(
|
||||
list(
|
||||
name = "en", # override en locale
|
||||
name = "en", # override 'en' locale
|
||||
options = list(
|
||||
toolbar = list(
|
||||
exportToSVG = "GET SVG",
|
||||
|
|
Loading…
Reference in New Issue