From ba93c07fa5e8e45a051576ffeacc56c43792645a Mon Sep 17 00:00:00 2001 From: pvictor Date: Wed, 1 Aug 2018 23:02:29 +0200 Subject: [PATCH] more docs --- R/apex-utils.R | 54 ++++++++++++++++++++++----------- dev/generate-funs.R | 34 +++++++++++++++++++++ inst/htmlwidgets/apexcharter.js | 3 ++ man/ax_annotations.Rd | 11 ++++--- man/ax_markers.Rd | 32 +++++++++---------- 5 files changed, 96 insertions(+), 38 deletions(-) diff --git a/R/apex-utils.R b/R/apex-utils.R index f78e7cd..a21f02f 100644 --- a/R/apex-utils.R +++ b/R/apex-utils.R @@ -9,11 +9,13 @@ #' Annotations properties #' #' @param ax A \code{apexcharts} \code{htmlwidget} object. -#' @param position -#' @param yaxis -#' @param xaxis -#' @param points +#' @param position Whether to put the annotations behind the charts or in front of it. Available Options: \code{"front"} or \code{"back"}. +#' @param yaxis List of lists. +#' @param xaxis List of lists. +#' @param points List of lists. #' @param ... Additional parameters. +#' +#' @note See \url{https://apexcharts.com/docs/options/annotations/}. #' #' @return A \code{apexcharts} \code{htmlwidget} object. #' @export @@ -280,18 +282,17 @@ ax_legend <- function(ax, #' Markers properties #' #' @param ax A \code{apexcharts} \code{htmlwidget} object. -#' @param discrete -#' @param size -#' @param colors -#' @param strokeColor -#' @param strokeWidth -#' @param strokeOpacity -#' @param fillOpacity -#' @param shape -#' @param radius -#' @param offsetX -#' @param offsetY -#' @param hover +#' @param size Numeric. Size of the marker point. +#' @param colors Sets the fill color(s) of the marker point. +#' @param strokeColor Stroke Color of the marker. +#' @param strokeWidth Stroke Size of the marker. +#' @param strokeOpacity Opacity of the border around marker. +#' @param fillOpacity Opacity of the marker fill color. +#' @param shape Shape of the marker. Available Options for shape: \code{"square"} or \code{"circle"}. +#' @param radius Numeric. Radius of the marker (applies to square shape) +#' @param offsetX Numeric. Sets the left offset of the marker. +#' @param offsetY Numeric. Sets the top offset of the marker. +#' @param hover List with item \code{size} (Size of the marker when it is active). #' @param ... Additional parameters. #' #' @return A \code{apexcharts} \code{htmlwidget} object. @@ -299,7 +300,6 @@ ax_legend <- function(ax, #' #' @examples ax_markers <- function(ax, - discrete = NULL, size = NULL, colors = NULL, strokeColor = NULL, @@ -368,6 +368,26 @@ ax_responsive <- function(ax, ...) { #' @export #' #' @examples +#' +#' # One serie +#' apexcharter() %>% +#' ax_series(list( +#' name = "rnorm", +#' data = rnorm(10) +#' )) +#' +#' # Two series +#' apexcharter() %>% +#' ax_series( +#' list( +#' name = "rnorm 1", +#' data = rnorm(10) +#' ), +#' list( +#' name = "rnorm 2", +#' data = rnorm(10) +#' ) +#' ) ax_series <- function(ax, ...) { .ax_opt(ax, "series", ...) } diff --git a/dev/generate-funs.R b/dev/generate-funs.R index 962c7cc..ee26891 100644 --- a/dev/generate-funs.R +++ b/dev/generate-funs.R @@ -34,6 +34,27 @@ make_fun <- function(opts, name, file = "") { 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("list(", body, ", ...)") + 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 ------------------------------------------------------------------- @@ -57,3 +78,16 @@ lapply( + + + +# Options ----------------------------------------------------------------- + +# scroller +str(ApexOpts$chart$scroller) + +make_opts(ApexOpts$chart, "scroller") + +# plotOptions -- bar +make_opts(ApexOpts$plotOptions, "bar") + diff --git a/inst/htmlwidgets/apexcharter.js b/inst/htmlwidgets/apexcharter.js index 98acab6..e867144 100644 --- a/inst/htmlwidgets/apexcharter.js +++ b/inst/htmlwidgets/apexcharter.js @@ -17,6 +17,9 @@ HTMLWidgets.widget({ ax_opts = x.ax_opts; // Sizing + if (typeof ax_opts.chart === 'undefined') { + ax_opts.chart = {}; + } ax_opts.chart.width = width; ax_opts.chart.height = height; diff --git a/man/ax_annotations.Rd b/man/ax_annotations.Rd index 581eafb..8cc4479 100644 --- a/man/ax_annotations.Rd +++ b/man/ax_annotations.Rd @@ -10,13 +10,13 @@ ax_annotations(ax, position = NULL, yaxis = NULL, xaxis = NULL, \arguments{ \item{ax}{A \code{apexcharts} \code{htmlwidget} object.} -\item{position}{} +\item{position}{Whether to put the annotations behind the charts or in front of it. Available Options: \code{"front"} or \code{"back"}.} -\item{yaxis}{} +\item{yaxis}{List of lists.} -\item{xaxis}{} +\item{xaxis}{List of lists.} -\item{points}{} +\item{points}{List of lists.} \item{...}{Additional parameters.} } @@ -26,3 +26,6 @@ A \code{apexcharts} \code{htmlwidget} object. \description{ Annotations properties } +\note{ +See \url{https://apexcharts.com/docs/options/annotations/}. +} diff --git a/man/ax_markers.Rd b/man/ax_markers.Rd index 2b7b31f..ce182f9 100644 --- a/man/ax_markers.Rd +++ b/man/ax_markers.Rd @@ -4,37 +4,35 @@ \alias{ax_markers} \title{Markers properties} \usage{ -ax_markers(ax, discrete = NULL, size = NULL, colors = NULL, - strokeColor = NULL, strokeWidth = NULL, strokeOpacity = NULL, - fillOpacity = NULL, shape = NULL, radius = NULL, offsetX = NULL, - offsetY = NULL, hover = NULL, ...) +ax_markers(ax, size = NULL, colors = NULL, strokeColor = NULL, + strokeWidth = NULL, strokeOpacity = NULL, fillOpacity = NULL, + shape = NULL, radius = NULL, offsetX = NULL, offsetY = NULL, + hover = NULL, ...) } \arguments{ \item{ax}{A \code{apexcharts} \code{htmlwidget} object.} -\item{discrete}{} +\item{size}{Numeric. Size of the marker point.} -\item{size}{} +\item{colors}{Sets the fill color(s) of the marker point.} -\item{colors}{} +\item{strokeColor}{Stroke Color of the marker.} -\item{strokeColor}{} +\item{strokeWidth}{Stroke Size of the marker.} -\item{strokeWidth}{} +\item{strokeOpacity}{Opacity of the border around marker.} -\item{strokeOpacity}{} +\item{fillOpacity}{Opacity of the marker fill color.} -\item{fillOpacity}{} +\item{shape}{Shape of the marker. Available Options for shape: \code{"square"} or \code{"circle"}.} -\item{shape}{} +\item{radius}{Numeric. Radius of the marker (applies to square shape)} -\item{radius}{} +\item{offsetX}{Numeric. Sets the left offset of the marker.} -\item{offsetX}{} +\item{offsetY}{Numeric. Sets the top offset of the marker.} -\item{offsetY}{} - -\item{hover}{} +\item{hover}{List with item \code{size} (Size of the marker when it is active).} \item{...}{Additional parameters.} }