Skip to content

Commit

Permalink
Fix issue with project not being returned from chart
Browse files Browse the repository at this point in the history
  • Loading branch information
katieb1 committed Apr 29, 2024
1 parent 3a33200 commit f782d26
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 12 deletions.
15 changes: 12 additions & 3 deletions R/chartErrorBar.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ NULL
#'
#' @param chart \code{\link{Chart}} object
#' @param type character. Type of error bar. Values can be "percentile",
#' "minmax", or "none". Default is "none".
#' "minmax", or "none". Default is NULL.
#' @param lower float. If the error bar type is set to "percentile", then
#' sets the minimum percentile for the lower range of the error bar. Default is
#' \code{NULL}.
Expand All @@ -18,7 +18,8 @@ NULL
#' \code{NULL}.
#'
#' @return
#' A \code{Chart} object representing a SyncroSim chart
#' A \code{Chart} object representing a SyncroSim chart or a data.frame of
#' the current chart error bar settings.
#'
#' @examples
#' \dontrun{
Expand All @@ -37,13 +38,14 @@ NULL
#' }
#'
#' @export
setGeneric("chartErrorBar", function(chart, type = "none", lower = NULL,
setGeneric("chartErrorBar", function(chart, type = NULL, lower = NULL,
upper = NULL) standardGeneric("chartErrorBar"))

#' @rdname chartErrorBar
setMethod("chartErrorBar", signature(chart = "Chart"),
function(chart, type, lower, upper) {

browser()
# Grab project and chart ID from chart
proj <- .project(chart)
chartCID <- .chartId(chart)
Expand All @@ -53,6 +55,13 @@ setMethod("chartErrorBar", signature(chart = "Chart"),
ds <- .datasheet(proj, name = chartDSName, optional = T,
returnInvisible = T, includeKey = T)

if (is.null(type)){
errorBarInfo <- data.frame(type = ds$ErrorBarType,
lower = ds$ErrorBarMinPercentile,
upper = ds$ErrorBarMaxPercentile)
return(errorBarInfo)
}

# Set error bar type
if (type == "none"){
ds[ds$ChartId == chartCID,]$ErrorBarType <- "No Ranges"
Expand Down
21 changes: 18 additions & 3 deletions R/internalHelpers.R
Original file line number Diff line number Diff line change
Expand Up @@ -814,14 +814,15 @@ datasheets <- function(x, project = NULL, scenario = NULL, scope = NULL, refresh
}

# If the goal is a project, return one or more, or complain
if (!is.null(goal) && ((goal == "project") || (goal == "folder") || (goal == "chart"))) {
if (!is.null(goal) && (goal == "project")) {
# if ssimObject is a scenario, return the parent project
if ((is(ssimObject, "Scenario"))) {
if (is.element(class(ssimObject), c("Scenario", "Folder", "Chart"))) {
if (convertObject | !returnIds) {
ssimObject <- new("Project", ssimObject, id = .projectId(ssimObject))
}
}
if (is.element(class(ssimObject), c("Project", "Scenario"))) {

if (is.element(class(ssimObject), c("Project", "Scenario", "Folder", "Chart"))) {
if (returnIds) {
project <- .projectId(ssimObject)
if (convertObject) {
Expand Down Expand Up @@ -1019,6 +1020,20 @@ datasheets <- function(x, project = NULL, scenario = NULL, scope = NULL, refresh
return(list(ssimObject = ssimObject, project = project, scenario = scenario, scenarioSet = fullScnSet, goal = goal))
}

# if goal is chart, and we have one, return immediately
if (!is.null(goal) && (goal == "chart")) {
if (is.element(class(ssimObject), c("Chart"))) {
return(ssimObject)
}
}

# if goal is folder, and we have one, return immediately
if (!is.null(goal) && (goal == "folder")) {
if (is.element(class(ssimObject), c("Folder"))) {
return(ssimObject)
}
}

stop(paste0("Could not identify a SsimLibrary, Project or Scenario from ssimObject, project, and scenario arguments."))
}

Expand Down
13 changes: 7 additions & 6 deletions R/project.R
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,11 @@ setMethod(f = "initialize", signature = "Project", definition = function(.Object
#' Creates or retrieves a \code{\link{Project}} or multiple Projects from a
#' SsimLibrary.
#'
#' @param ssimObject \code{\link{Scenario}} or
#' \code{\link{SsimLibrary}} object, or a character string (i.e. a filepath)
#' @param ssimObject \code{\link{Scenario}}, \code{\link{SsimLibrary}}, or
#' \code{\link{Chart}} object, or a character string (i.e. a filepath)
#' @param project \code{\link{Project}} object, character, integer, or vector
#' of these. Names or ids of one or more Projects. Note that integer ids are
#' slightly faster (optional)
#' of these. Names or ids of one or more Projects. Note that integer ids are
#' slightly faster (optional)
#' @param sourceProject \code{\link{Project}} object, character, or integer. If
#' not \code{NULL} (default), new Projects will be copies of the sourceProject
#' @param summary logical. If \code{TRUE} then return the Project(s) in a data.frame with
Expand All @@ -145,7 +145,7 @@ setMethod(f = "initialize", signature = "Project", definition = function(.Object
#' list; otherwise returns a single project as a \code{\link{Project}} object.
#' Applies only when \code{summary=FALSE} Default is \code{FALSE}
#' @param overwrite logical. If \code{TRUE} an existing Project will be overwritten.
#' Default is \code{FALSE}
#' Default is \code{FALSE}
#'
#' @details
#' For each element of project:
Expand Down Expand Up @@ -199,14 +199,15 @@ project <- function(ssimObject = NULL, project = NULL, sourceProject = NULL, sum
if ((is(ssimObject, "character")) && (is(ssimObject, SyncroSimNotFound(warn = FALSE)))) {
return(SyncroSimNotFound())
}

if (is.null(ssimObject)) {
e <- ssimEnvironment()
ssimObject <- ssimLibrary(e$LibraryFilePath)
project <- as.integer(e$ProjectId)
}

# if ssimObject is a scenario or project, return the project
if (is.element(class(ssimObject), c("Scenario", "Project")) & is.null(project)) {
if (is.element(class(ssimObject), c("Scenario", "Project", "Chart")) & is.null(project)) {
if (is.null(summary)) {
summary <- FALSE
}
Expand Down

0 comments on commit f782d26

Please sign in to comment.