Merge pull request #53 from dreamRs/packer

Packer
This commit is contained in:
Victor Perrier 2021-09-17 15:33:27 +02:00 committed by GitHub
commit c0672ba655
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
120 changed files with 1792 additions and 657 deletions

View File

@ -13,3 +13,10 @@
^LICENSE\.md$
^codecov\.yml$
^pkgdown$
^srcjs$
^node_modules$
^package\.json$
^package-lock\.json$
^webpack\.dev\.js$
^webpack\.prod\.js$
^webpack\.common\.js$

1
.gitignore vendored
View File

@ -4,3 +4,4 @@ inst/doc
.RData
*.Rproj
data-raw/*.csv
node_modules

View File

@ -1,7 +1,9 @@
apexcharter 0.2.1
==================
* Updated ApexCharts.js to 3.26.3
* Updated ApexCharts.js to 3.28.3
* Internal: use [{packer}](https://github.com/JohnCoene/packer) to manage JavaScript assets.
* `d3.format` JavaScript functions are now available in browser under `format()` and `formatLocale()`.

View File

@ -56,7 +56,7 @@ apexchart <- function(ax_opts = list(), auto_update = TRUE, width = NULL, height
)
}
# dput(tools::file_path_sans_ext(list.files("inst/htmlwidgets/assets/apexcharts-locales/")))
# dput(tools::file_path_sans_ext(list.files("inst/apexcharts-locale/")))
#' @importFrom jsonlite fromJSON
add_locale_apex <- function(widget) {
if (!is.null(widget$x$ax_opts$chart$defaultLocale)) {
@ -75,7 +75,7 @@ add_locale_apex <- function(widget) {
)
} else {
path <- system.file(
file.path("htmlwidgets/assets/apexcharts-locales", paste0(defaultLocale, ".json")),
file.path("apexcharts-locale", paste0(defaultLocale, ".json")),
package = "apexcharter"
)
locale <- jsonlite::fromJSON(txt = path)

View File

@ -10,25 +10,25 @@
#'
#' @return a \code{JS} function
#' @export
#'
#'
#' @importFrom htmlwidgets JS
#'
#' @example examples/format.R
format_num <- function(format, prefix = "", suffix = "", locale = "en-US") {
check_locale_d3(locale)
path <- system.file(file.path("htmlwidgets/assets/d3-format/locale", paste0(locale, ".json")), package = "apexcharter")
path <- system.file(file.path("d3-format-locale", paste0(locale, ".json")), package = "apexcharter")
if (path != "") {
locale <- paste(readLines(con = path, encoding = "UTF-8"), collapse = "")
}
JS(sprintf(
"function(value) {var locale = d3.formatLocale(JSON.parse('%s')); return '%s' + locale.format('%s')(value) + '%s';}",
"function(value) {var locale = formatLocale(JSON.parse('%s')); return '%s' + locale.format('%s')(value) + '%s';}",
locale, prefix, format, suffix
))
}
check_locale_d3 <- function(x) {
json <- list.files(system.file("htmlwidgets/assets/d3-format/locale", package = "apexcharter"))
json <- list.files(system.file("d3-format-locale", package = "apexcharter"))
njson <- gsub("\\.json", "", json)
if (!x %in% njson) {
stop(paste(

View File

@ -10,23 +10,20 @@
<!-- badges: end -->
:warning: Use RStudio >= 1.2 to properly display charts
## Installation
Install from CRAN with:
Install from [CRAN](https://cran.r-project.org/web/packages/apexcharter/index.html) with:
```r
install.packages("apexcharter")
```
Or install the development version from [GitHub](https://github.com/) with:
Or install the development version from [GitHub](https://github.com/dreamRs/apexcharter) with:
``` r
# install.packages("devtools")
devtools::install_github("dreamRs/apexcharter")
```r
# install.packages("remotes")
remotes::install_github("dreamRs/apexcharter")
```
@ -141,3 +138,27 @@ apexchart(ax_opts = list(
![](man/figures/raw-api.png)
## Development
This package use [{packer}](https://github.com/JohnCoene/packer) to manage JavaScript assets, see packer's [documentation](https://packer.john-coene.com/#/) for more.
Install nodes modules with:
```r
packer::npm_install()
```
Modify `srcjs/widgets/apexcharter.js`, then run:
```r
packer::bundle()
```
Re-install R package and try `apexcharter()` or `apex()` functions.

View File

@ -1,6 +1,6 @@
## Test environments
* local OS Widows 10 install, R 4.0.3
* ubuntu 16.04, Windows 10, macOS (on GitHub Actions), R 4.0.5
* local OS Widows 10 install, R 4.1.0
* ubuntu 20.04, Windows 10, macOS (on GitHub Actions), R 4.1.1
* win-builder (devel and release)
## R CMD check results

View File

@ -1,120 +0,0 @@
# Parsing options ---------------------------------------------------------
cx <- V8::v8()
cx$source(file = "inst/htmlwidgets/lib/apexcharts-1.0.4/Options.js")
ApexOpts <- cx$get("Options")
names(ApexOpts)
str(ApexOpts$chart, max.level = 1)
str(ApexOpts$chart$animations, max.level = 1)
# Utils -------------------------------------------------------------------
make_fun <- function(opts, name, file = "") {
args <- names(opts[[name]])
if (is.null(args)) {
args <- "..."
} else {
args <- sprintf("%s = NULL", args)
args <- paste(args, collapse = ",\n")
args <- paste0(args, ", ...")
}
body <- paste(
"\nparams <- c(as.list(environment()), list(...))[-1]",
paste0(".ax_opt2(ax, \"", name, "\", l = dropNulls(params))\n"),
sep = "\n"
)
res <- paste0("ax_", name, " <- function(ax, ", args, ") {", body, "}\n\n\n")
cat(res, file = file, append = TRUE)
return(invisible(res))
}
make_opts <- function(opts, name, file = "") {
args <- names(opts[[name]])
if (is.null(args)) {
args <- "..."
body <- "list(...)"
} else {
body <- sprintf("%s = %s", args, args)
body <- paste(body, collapse = ",\n")
body <- paste0("c(list(", body, "), list(...))")
args <- sprintf("%s = NULL", args)
args <- paste(args, collapse = ",\n")
args <- paste0(args, ", ...")
}
body <- paste0("dropNulls(", body, ")")
res <- paste0(name, "Opts", " <- function(", args, ") {", body, "}\n\n\n")
cat(res, file = file, append = TRUE)
return(invisible(res))
}
# chart -------------------------------------------------------------------
make_fun(ApexOpts, "chart")
# plotOptions -------------------------------------------------------------
make_fun(ApexOpts, "plotOptions")
# ALL ---------------------------------------------------------------------
lapply(
X = names(ApexOpts),
FUN = make_fun, opts = ApexOpts, file = "R/apex-utils.R"
)
# Options -----------------------------------------------------------------
# scroller
str(ApexOpts$chart$scroller)
make_opts(ApexOpts$chart, "scroller")
# plotOptions -- bar
make_opts(ApexOpts$plotOptions, "bar")
### write funs
# chart
str(ApexOpts$chart, max.level = 1)
make_opts(ApexOpts$chart, "scroller", file = "R/apex-options.R")
make_opts(ApexOpts$chart, "events", file = "R/apex-options.R")
make_opts(ApexOpts$chart, "selection", file = "R/apex-options.R")
# plotOptions
str(ApexOpts$plotOptions, max.level = 1)
make_opts(ApexOpts$plotOptions, "bar", file = "R/apex-options.R")
make_opts(ApexOpts$plotOptions, "heatmap", file = "R/apex-options.R")
make_opts(ApexOpts$plotOptions, "radialBar", file = "R/apex-options.R")
make_opts(ApexOpts$plotOptions, "pie", file = "R/apex-options.R")

View File

@ -1,96 +0,0 @@
# apexcharts.js raw api ---------------------------------------------------
library(apexcharter)
library(ggplot2) # for data
library(dplyr)
# bar ----
data(mpg)
dat <- count(mpg, manufacturer)
apexchart(ax_opts = list(
chart = list(type = "bar"),
plotOptions = list(
bar = list(
horizontal = FALSE,
endingShape = "flat",
columnWidth = "70%",
dataLabels = list(
position = "top"
)
)
),
colors = list("#112446"),
grid = list(
show = TRUE,
position = "front"
),
series = list(list(
name = "Count",
data = dat$n
)),
xaxis = list(categories = dat$manufacturer)
))
# line ----
# recreating (mostly): https://apexcharts.com/javascript-chart-demos/line-charts/data-labels/
apexchart(ax_opts = list(
chart = list(
type = "line"
),
stroke = list(
curve = "smooth"
),
grid = list(
borderColor = "#e7e7e7",
row = list(
colors = c("#f3f3f3", "transparent"),
opacity = 0.5
)
),
dataLabels = list(
enabled = TRUE
),
markers = list(style = "inverted", size = 6),
series = list(
list(
name = "High",
data = c(28, 29, 33, 36, 32, 32, 33)
),
list(
name = "Low",
data = c(12, 11, 14, 18, 17, 13, 13)
)
),
title = list(
text = "Average High & Low Temperature",
align = "left"
),
xaxis = list(
categories = month.abb[1:7]
),
yaxis = list(
title = list(text = "Temperature"),
labels = list(
formatter = htmlwidgets::JS("function(value) {return value + \'\u00b0C\';}")
)
)
))

File diff suppressed because one or more lines are too long

Some files were not shown because too many files have changed in this diff Show More