Skip to content

Commit

Permalink
Fixes Open-Systems-Pharmacology#263 add enum helpers for units and fo…
Browse files Browse the repository at this point in the history
…rmat
  • Loading branch information
pchelle committed May 12, 2022
1 parent 4c25a51 commit 78fb2dc
Show file tree
Hide file tree
Showing 13 changed files with 101 additions and 8 deletions.
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ export(DDIComparisonTypes)
export(DDIRatioDataMapping)
export(DDIRatioPlotConfiguration)
export(ExportConfiguration)
export(ExportFormats)
export(ExportUnits)
export(Font)
export(FontFaces)
export(GroupMapping)
Expand Down
4 changes: 2 additions & 2 deletions R/tlf-env.R
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ tlfEnv$defaultExportParameters <- list(
#' @param name base file name of the exported plots
#' @export
setDefaultExportParameters <- function(format = NULL, width = NULL, height = NULL, units = NULL, dpi = NULL, name = NULL) {
validateIsString(format, nullAllowed = TRUE)
validateIsIncluded(units, c("cm", "in", "mm", "px"), nullAllowed = TRUE)
validateIsIncluded(format, ExportFormats, nullAllowed = TRUE)
validateIsIncluded(units, ExportUnits, nullAllowed = TRUE)
validateIsNumeric(width, nullAllowed = TRUE)
validateIsNumeric(height, nullAllowed = TRUE)
validateIsNumeric(dpi, nullAllowed = TRUE)
Expand Down
29 changes: 23 additions & 6 deletions R/utilities-export.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
#' @title ExportUnits
#' @import ospsuite.utils
#' @export
#' @description
#' List of all available units for `width` and `height` to export a ggplot object
#' @family enum helpers
ExportUnits <- enum(c("cm", "in", "mm", "px"))


#' @title ExportFormats
#' @import ospsuite.utils
#' @export
#' @description
#' List of all available formats to export a ggplot object
#' @family enum helpers
ExportFormats <- enum(c("png", "pdf", "eps", "ps", "tex", "jpeg", "tiff", "bmp", "svg", "wmf"))

#' @title setPlotExport
#' @description Set plot export properties
#' @param plotObject Graphical object created from ggplot
Expand All @@ -12,8 +29,8 @@
setPlotExport <- function(plotObject, name = NULL, format = NULL, width = NULL, height = NULL, units = NULL, dpi = NULL) {
validateIsOfType(plotObject, "ggplot")
validateIsString(name, nullAllowed = TRUE)
validateIsString(format, nullAllowed = TRUE)
validateIsIncluded(units, c("cm", "in", "mm", "px"), nullAllowed = TRUE)
validateIsIncluded(format, ExportFormats, nullAllowed = TRUE)
validateIsIncluded(units, ExportUnits, nullAllowed = TRUE)
validateIsNumeric(width, nullAllowed = TRUE)
validateIsNumeric(height, nullAllowed = TRUE)
validateIsNumeric(dpi, nullAllowed = TRUE)
Expand All @@ -34,7 +51,7 @@ setPlotExport <- function(plotObject, name = NULL, format = NULL, width = NULL,
#' @export
setPlotExportFormat <- function(plotObject, format = NULL) {
validateIsOfType(plotObject, "ggplot")
validateIsString(format, nullAllowed = TRUE)
validateIsIncluded(format, ExportFormats, nullAllowed = TRUE)

newPlotObject <- plotObject
newPlotObject$plotConfiguration <- plotObject$plotConfiguration$clone(deep = TRUE)
Expand All @@ -57,7 +74,7 @@ setPlotExportFormat <- function(plotObject, format = NULL) {
#' @export
setPlotExportDimensions <- function(plotObject, width = NULL, height = NULL, units = NULL, dpi = NULL) {
validateIsOfType(plotObject, "ggplot")
validateIsIncluded(units, c("cm", "in", "mm", "px"), nullAllowed = TRUE)
validateIsIncluded(units, ExportUnits, nullAllowed = TRUE)
validateIsNumeric(width, nullAllowed = TRUE)
validateIsNumeric(height, nullAllowed = TRUE)
validateIsNumeric(dpi, nullAllowed = TRUE)
Expand Down Expand Up @@ -93,8 +110,8 @@ exportPlot <- function(plotObject, fileName = NULL, name = NULL, format = NULL,
validateIsOfType(plotObject, "ggplot")
validateIsString(fileName, nullAllowed = TRUE)
validateIsString(name, nullAllowed = TRUE)
validateIsString(format, nullAllowed = TRUE)
validateIsIncluded(units, c("cm", "in", "mm", "px"), nullAllowed = TRUE)
validateIsIncluded(format, ExportFormats, nullAllowed = TRUE)
validateIsIncluded(units, ExportUnits, nullAllowed = TRUE)
validateIsNumeric(width, nullAllowed = TRUE)
validateIsNumeric(height, nullAllowed = TRUE)
validateIsNumeric(dpi, nullAllowed = TRUE)
Expand Down
2 changes: 2 additions & 0 deletions man/AestheticProperties.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions man/Alignments.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 29 additions & 0 deletions man/ExportFormats.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 29 additions & 0 deletions man/ExportUnits.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions man/FontFaces.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions man/LegendPositions.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions man/Linetypes.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions man/Scaling.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions man/Shapes.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions man/tlfStatFunctions.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 78fb2dc

Please sign in to comment.