Skip to content

Commit

Permalink
reorg internal htmlwidget config
Browse files Browse the repository at this point in the history
  • Loading branch information
pvictor committed Oct 11, 2023
1 parent 9fb0cf7 commit 2ee9185
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 19 deletions.
21 changes: 12 additions & 9 deletions R/uPlot.R
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,24 @@
#' )
#' )
uPlot <- function(data, options = list(), ..., width = NULL, height = NULL, elementId = NULL) {

options <- as.list(options)
series_nms <- names(data)
if (is.data.frame(data)) {
data <- prepare_data(data)
if (length(options) < 1) {
labels <- attr(data, ".nms")
strokes <- rep_len(palette(), length(labels))
options <- prepare_options_series(label = labels, stroke = strokes)
series_nms <- attr(data, ".nms")
if (is.null(options$series)) {
strokes <- rep_len(palette(), length(series_nms))
options$series <- prepare_options_series(label = series_nms, stroke = strokes)
}
}


x <- list(
data = data,
options = options,
...
config = list(
data = data,
options = options,
...
),
series_nms = series_nms
)

htmlwidgets::createWidget(
Expand Down
12 changes: 5 additions & 7 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,10 @@ prepare_data <- function(.data) {

prepare_options_series <- function(...) {
opts <- list(...)
list(
series = lapply(
X = seq_along(opts[[1]]),
FUN = function(i) {
lapply(X = opts, FUN = `[[`, i)
}
)
lapply(
X = seq_along(opts[[1]]),
FUN = function(i) {
lapply(X = opts, FUN = `[[`, i)
}
)
}
2 changes: 1 addition & 1 deletion inst/htmlwidgets/uPlot.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions srcjs/widgets/uPlot.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,10 @@ HTMLWidgets.widget({
if (typeof plot !== "undefined") {
plot.destroy();
}
options = x.options;
options = x.config.options;
options.width = width;
options.height = height;
data = x.data;
data = x.config.data;
if (x.stacked) {
if (!options.hooks)
options.hooks = {};
Expand Down

0 comments on commit 2ee9185

Please sign in to comment.