Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #263 add enum helpers for units and format #266

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.