Progress: store value as raw value instead of normalized

This commit is contained in:
Winston Chang
2017-01-18 14:41:07 -05:00
parent 4feee00d34
commit 0e519a4e97

View File

@@ -110,8 +110,8 @@ Progress <- R6Class(
private$id <- createUniqueId(8)
private$min <- min
private$max <- max
private$value <- min
private$style <- match.arg(style, choices = c("notification", "old"))
private$value <- 0
private$closed <- FALSE
session$sendProgress('open', list(id = private$id, style = private$style))
@@ -123,16 +123,15 @@ Progress <- R6Class(
return()
}
if (is.null(value) || is.na(value)) {
if (is.null(value) || is.na(value))
value <- NULL
} else {
if (!is.null(value)) {
private$value <- value
# Normalize value to number between 0 and 1
value <- min(1, max(0, (value - private$min) / (private$max - private$min)))
}
if (!is.null(value))
private$value <- value
data <- dropNulls(list(
id = private$id,
message = message,
@@ -145,7 +144,7 @@ Progress <- R6Class(
},
inc = function(amount = 0.1, message = NULL, detail = NULL) {
value <- min(self$getValue() + amount, private$max)
value <- min(private$value + amount, private$max)
self$set(value, message, detail)
},
@@ -153,10 +152,7 @@ Progress <- R6Class(
getMax = function() private$max,
# Return value (not the normalized 0-1 value, but in the original range)
getValue = function() {
private$value * (private$max - private$min) + private$min
},
getValue = function() private$value,
close = function() {
if (private$closed) {
@@ -172,12 +168,12 @@ Progress <- R6Class(
),
private = list(
session = 'environment',
session = 'ShinySession',
id = character(0),
min = numeric(0),
max = numeric(0),
style = character(0),
value = NULL,
value = numeric(0),
closed = logical(0)
)
)