Skip to content

Commit

Permalink
fixed slider
Browse files Browse the repository at this point in the history
  • Loading branch information
Mauron committed Dec 12, 2023
1 parent 27bee70 commit 28928df
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
4 changes: 4 additions & 0 deletions .lintr
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
linters: linters_with_defaults(
object_usage_linter = NULL,
cyclocomp_linter = NULL,
commented_code_linter = NULL)
2 changes: 2 additions & 0 deletions R/plot.R
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,8 @@ catmaply <- function(
text = !!rlang::sym(text),
y_order = !!rlang::sym(y_order),
x_order = !!rlang::sym(x_order),
y_rank = dplyr::dense_rank(!!rlang::sym(y_order)),
x_rank = dplyr::dense_rank(!!rlang::sym(x_order)),
category = !!rlang::sym(categorical_col),
legend = !!rlang::sym(legend_col),
label =
Expand Down
10 changes: 8 additions & 2 deletions R/trace.R
Original file line number Diff line number Diff line change
Expand Up @@ -285,9 +285,11 @@ add_catmaply_slider <- function(
) {

visible_index <- 1
auto_mode <- FALSE

if (all(c("slider_start", "slider_range", "slider_shift", "slider_step_name") %in% names(slider_steps))){

auto_mode <- TRUE
step_name_col <- slider_steps$slider_step_name[1]

if (!(step_name_col %in% colnames(df)))
Expand All @@ -301,7 +303,7 @@ add_catmaply_slider <- function(
stop("You need to define excactly one stepname entry per values on the x axis.")

# get range to calculate number of steps and to get step names
x_range <- unique(df[['x_order']])
x_range <- unique(df[['x_rank']])
x <- unique(df[[step_name_col]])[order(x_range)]
x_range <- x_range[order(x_range)]

Expand Down Expand Up @@ -337,7 +339,11 @@ add_catmaply_slider <- function(
if (lower_bound >= upper_bound)
stop(paste("Trying to build slider, however, lower bound is higher or equal than upper bound for step:", slider_steps[[i]]$name))

tmp <- dplyr::filter(df, dplyr::between(df[["x_order"]], lower_bound, upper_bound))
if (auto_mode) {
tmp <- dplyr::filter(df, dplyr::between(df[["x_rank"]], lower_bound, upper_bound))
} else {
tmp <- dplyr::filter(df, dplyr::between(df[["x_order"]], lower_bound, upper_bound))
}

# get the indexes of the legend items relevant to the current trace
legend_idx <- which(legend_items %in% unique(tmp[['legend']]))
Expand Down

0 comments on commit 28928df

Please sign in to comment.