Skip to content

Commit

Permalink
Add chart/folder deletion + refactor delete, add name(Chart) and proj…
Browse files Browse the repository at this point in the history
…ectId(Chart)
  • Loading branch information
katieb1 committed Mar 12, 2024
1 parent a134aff commit 41deeab
Show file tree
Hide file tree
Showing 20 changed files with 836 additions and 222 deletions.
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ Collate:
'autogentags.R'
'backup.R'
'chart.R'
'chartId.R'
'chartMapConstructor.R'
'command.R'
'condaFilepath.R'
Expand Down
13 changes: 12 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# Generated by roxygen2: do not edit by hand

export("%+%")
S3method("+",Chart)
S3method(ssimChart_add,Criteria)
S3method(ssimChart_add,column_chart)
S3method(ssimChart_add,line_chart)
S3method(ssimChart_add,y)
export("+.Chart")
export("autogentags<-")
export("condaFilepath<-")
export("dependency<-")
Expand All @@ -14,16 +19,20 @@ export("readOnly<-")
export("session<-")
export("silent<-")
export("useConda<-")
export(Chart)
export(Folder)
export(Project)
export(Scenario)
export(Session)
export(SsimLibrary)
export(addPackage)
export(addRow)
export(add_ssimChart)
export(as.Chart)
export(autogentags)
export(backup)
export(chart)
export(chartId)
export(command)
export(condaFilepath)
export(datasheet)
Expand All @@ -39,6 +48,7 @@ export(ignoreDependencies)
export(info)
export(installConda)
export(installPackage)
export(is.Chart)
export(mergeDependencies)
export(name)
export(owner)
Expand All @@ -61,6 +71,7 @@ export(scenarioId)
export(session)
export(silent)
export(sqlStatement)
export(ssimChart_add)
export(ssimEnvironment)
export(ssimLibrary)
export(ssimUpdate)
Expand Down
20 changes: 11 additions & 9 deletions R/AAAClassDefinitions.R
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,12 @@ Project <- setClass("Project", contains = "SsimObject",
#' @name Folder-class
#' @rdname Folder-class
#' @export Folder
Folder <- setClass("Folder", representation(session = "Session",
filepath = "character",
folderId = "numeric",
parentId = "numeric",
projectId = "numeric"))
Folder <- setClass("Folder", contains = "SsimObject",
representation(session = "Session",
filepath = "character",
folderId = "numeric",
parentId = "numeric",
projectId = "numeric"))

#' SyncroSim Chart class
#'
Expand All @@ -149,9 +150,10 @@ Folder <- setClass("Folder", representation(session = "Session",
#' @name Chart-class
#' @rdname Chart-class
#' @export Chart
Chart <- setClass("Chart", representation(session = "Session",
filepath = "character",
chartId = "numeric",
projectId = "numeric"))
Chart <- setClass("Chart", contains = "SsimObject",
representation(session = "Session",
filepath = "character",
chartId = "numeric",
projectId = "numeric"))


2 changes: 1 addition & 1 deletion R/chart.R
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ setMethod(
#'
#' # Create a new chart
#' myChart <- chart(myProject, chart = "New Chart")
#'
#' }
#' @name chart
#' @export
chart <- function(ssimObject = NULL, chart = NULL, create = FALSE, summary = FALSE) {
Expand Down
43 changes: 43 additions & 0 deletions R/chartId.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Copyright (c) 2024 Apex Resource Management Solution Ltd. (ApexRMS). All rights reserved.
# MIT License
#' @include AAAClassDefinitions.R
NULL

#' Retrieves chartId of SyncroSim Chart
#'
#' Retrieves the Chart Id of a SyncroSim \code{\link{Chart}}.
#'
#' @param chart \code{\link{Chart}} object
#'
#' @return
#' An integer: chart id.
#'
#' @examples
#' \donttest{
#' # Set the file path and name of the new SsimLibrary
#' myLibraryName <- file.path(tempdir(),"testlib")
#'
#' # Set the SyncroSim Session, SsimLibrary, and Project
#' mySession <- session()
#' myLibrary <- ssimLibrary(name = myLibraryName,
#' session = mySession,
#' overwrite = TRUE)
#' myProject <- project(myLibrary, project = "Definitions")
#'
#' # Get the chart object corresponding to the chart called "My Chart"
#' myChart <- chart(myProject, chart = "My Chart")
#'
#' # Get Chart ID for SyncroSim Chart
#' chartId(myChart)
#' }
#'
#' @export
setGeneric("chartId", function(ssimObject) standardGeneric("chartId"))
#' @rdname chartId
setMethod("chartId", signature(ssimObject = "character"), function(ssimObject) {
return(SyncroSimNotFound(ssimObject))
})
#' @rdname chartId
setMethod("chartId", signature(ssimObject = "Chart"), function(ssimObject) {
return(ssimObject@chartId)
})
75 changes: 66 additions & 9 deletions R/chartMapConstructor.R
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
# Testing out plotting construction code
# Below taken and modified from ggplot plot-construction.R

# Create function for adding together SyncroSim charting and mapping objects
"+.ssim" <- function(e1, e2) {
#' Testing out plotting construction code
#' Below taken and modified from ggplot plot-construction.R
#'
#' Create function for adding together SyncroSim charting and mapping objects
#' @param e1 An object of class [ssimChart()].
#' @param e2 A chart or map component, as described below.
#' @export
#' @method + Chart
#' @rdname chart-add
"+.Chart" <- function(e1, e2) {
if (missing(e2)) {
cli::cli_abort(c(
"Cannot use {.code +} with a single argument.",
Expand All @@ -14,26 +19,78 @@
# can be displayed in error messages
e2name <- deparse(substitute(e2))

if (is.ssimChart(e1)) add_ssimChart(e1, e2, e2name)
else if (is.ssimMap(e1)) add_ssimMap(e1, e2, e2name)
if (is.Chart(e1)) add_ssimChart(e1, e2, e2name)
else if (is.Map(e2)) add_ssimMap(e1, e2, e2name)
}

# Overload the "+"
#' @rdname ssim-add
#' @rdname chart-add
#' @export
"%+%" <- `+.ssim`
`+.Chart` <- function(e1, e2){
UseMethod("ssimChart_add")
}

#' Customize the chart
#'
#' This generic allows you to add your own methods for adding custom objects to
#' a chart with [+.Chart].
#'
#' @param object An object to add to the chart
#' @param plot The chart object to add `object` to
#' @param object_name The name of the object to add
#'
#' @return A modified chart object
#'
#' @keywords internal
#' @export
add_ssimChart <- function(c, object, objectname) {
if (is.null(object)) return(c)

c <- ssimChart_add(object, c, objectname)
c
}

#' @export
as.Chart <- function(x){
if(!inherits(x, "Chart")) class(x) <- c("Chart", class(x))
x
}

#' @export
is.Chart <- function(x){
inherits(x, "Chart")
}

#' @export
ssimChart_add <- function(object, chart, object_name) {
UseMethod("ssimChart_add")
}


# Below we specify what happens when an object of a certain type is added
# to a chart object (e.g., legend object, format object, title object, etc.)

# Adds an object of type "Criteria" to the chart and returns a chart object
#' @export
ssimChart_add.Criteria <- function(object, chart, object_name){
browser()
chart$type <- "line"
chart
}

#' @export
ssimChart_add.line_chart <- function(object, chart, object_name){
chart$type <- "line"
chart
}

#' @export
ssimChart_add.column_chart <- function(object, chart, object_name){
chart$type <- "column"
chart
}

#' @export
ssimChart_add.y <- function(object, chart, object_name){
chart$yVariable <- object
chart
Expand Down
Loading

0 comments on commit 41deeab

Please sign in to comment.