-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create function for setting chart error bars
- Loading branch information
Showing
4 changed files
with
133 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
# Copyright (c) 2024 Apex Resource Management Solution Ltd. (ApexRMS). All rights reserved. | ||
# MIT License | ||
#' @include AAAClassDefinitions.R | ||
NULL | ||
|
||
#' Modify the error bars of a \code{\link{Chart}} | ||
#' | ||
#' Set the type and properties of the error bars of a \code{\link{Chart}}. | ||
#' | ||
#' @param chart \code{\link{Chart}} object | ||
#' @param type character. Type of error bar. Values can be "percentile", | ||
#' "minmax", or "none". Default is "none". | ||
#' @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}. | ||
#' @param upper float. If the error bar type is set to "percentile", then | ||
#' sets the maximum percentile for the upper range of the error bar. Default is | ||
#' \code{NULL}. | ||
#' | ||
#' @return | ||
#' A \code{Chart} object representing a SyncroSim chart | ||
#' | ||
#' @examples | ||
#' \dontrun{ | ||
#' # Open a chart object | ||
#' myChart <- chart(myProject, chart = "My Chart") | ||
#' | ||
#' # Set the chart error bars to display the minimum/maximum of the data | ||
#' myChart <- chartErrorBar(myChart, type = "minmax") | ||
#' | ||
#' # Disable the chart error bars | ||
#' myChart <- chartErrorBar(myChart, type = "none") | ||
#' | ||
#' # Set the chart error bars to display the 95th percentile error bars | ||
#' myChart <- chartErrorBar(myChart, type = "percentile", lower = 2.5, | ||
#' upper = 97.5) | ||
#' } | ||
#' | ||
#' @export | ||
setGeneric("chartErrorBar", function(chart, type = "none", lower = NULL, | ||
upper = NULL) standardGeneric("chartErrorBar")) | ||
|
||
#' @rdname chartErrorBar | ||
setMethod("chartErrorBar", signature(chart = "Chart"), | ||
function(chart, type, lower, upper) { | ||
|
||
# Grab project and chart ID from chart | ||
proj <- .project(chart) | ||
chartCID <- .chartId(chart) | ||
chartDSName <- "core_Chart" | ||
|
||
# Load chart configuration datasheet | ||
ds <- .datasheet(proj, name = chartDSName, optional = T, | ||
returnInvisible = T, includeKey = T) | ||
|
||
# Set error bar type | ||
if (type == "none"){ | ||
ds[ds$ChartId == chartCID,]$ErrorBarType <- "No Ranges" | ||
} else if (type == "minmax"){ | ||
ds[ds$ChartId == chartCID,]$ErrorBarType <- "Min/Max" | ||
} else if (type == "percentile"){ | ||
ds[ds$ChartId == chartCID,]$ErrorBarType <- "Percentile" | ||
} else { | ||
stop(paste("Invalid error bar type:", type)) | ||
} | ||
|
||
# Set min / max percentiles | ||
if (is.numeric(lower)){ | ||
ds[ds$ChartId == chartCID,]$ErrorBarMinPercentile <- lower | ||
} else { | ||
stop("Invalid lower percentile value:", lower) | ||
} | ||
|
||
if (is.numeric(upper)){ | ||
ds[ds$ChartId == chartCID,]$ErrorBarMaxPercentile <- upper | ||
} else { | ||
stop("Invalid upper percentile value:", upper) | ||
} | ||
|
||
saveDatasheet(proj, ds, name = chartDSName, append = FALSE, force = TRUE) | ||
|
||
return(chart) | ||
}) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.