Skip to content

Commit

Permalink
Remove duplicate function getLegendCaption
Browse files Browse the repository at this point in the history
  • Loading branch information
pchelle committed Dec 14, 2021
1 parent 7e25d85 commit e2f393a
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 98 deletions.
1 change: 0 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ export(setXGrid)
export(setYAxis)
export(setYGrid)
export(tlfStatFunctions)
export(updateLegendCaption)
export(useDarkTheme)
export(useExcelTheme)
export(useHighChartTheme)
Expand Down
56 changes: 0 additions & 56 deletions R/plotconfiguration.R
Original file line number Diff line number Diff line change
Expand Up @@ -245,59 +245,3 @@ PlotConfiguration <- R6::R6Class(
)
)


## -------------------------------------------------------------------
# List of auxiliary functions used by plotConfiguration

#' @title dataMappingLabel
#' @param mapping mapping variable on label
#' @param metaData metaData containing unit of variable
#' @return label character of variable with its unit
#' @description
#' dataMappingLabel create an axis label with unit if available
#' @keywords internal
dataMappingLabel <- function(mapping = NULL, metaData = NULL) {
label <- NULL
ifnotnull(mapping, label <- getLabelWithUnit(metaData[[mapping]]$dimension, metaData[[mapping]]$unit))

return(label)
}

#' @title getLabelWithUnit
#' @param label text of axis label
#' @param unit metaData containing unit of variable
#' @return label character of variable with its unit when available
#' @description
#' getLabelWithUnit paste unit to label when available
#' @export
getLabelWithUnit <- function(label, unit = NULL) {
if (isTRUE(unit %in% "")) {
unit <- NULL
}
ifnotnull(unit, label <- paste(label, " [", unit, "]", sep = ""))
return(label)
}

#' @title getLegendCaption
#' @param captionData data used for legend caption
#' @param which caption position in the legend
#' @return legend captions
#' @description
#' getLegendCaption return the legend captions or a subset using which
#' @export
getLegendCaption <- function(captionData, which = seq(1, length(levels(captionData)))) {
return(levels(captionData)[which])
}

#' @title updateLegendCaption
#' @param captionData data used for legend caption
#' @param newCaption new legend caption
#' @param which caption position in the legend
#' @return updated caption data
#' @description
#' updateLegendCaption return the updated data used for legend caption
#' @export
updateLegendCaption <- function(captionData, newCaption = NULL, which = NULL) {
ifnotnull(which, levels(captionData)[which] <- newCaption %||% levels(captionData)[which])
return(captionData)
}
21 changes: 21 additions & 0 deletions R/utilities-label.R
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,24 @@ asLabel <- function(text = "", font = NULL) {

return(text)
}

#' @title getLabelWithUnit
#' @description
#' Get label with its unit within square brackets when available
#' @param label text of axis label
#' @param unit Character value corresponding to unit of `label`
#' @return
#' `label [unit]` or `label` depending if `unit` is `NULL` or `""`
#' @export
#' @examples
#' getLabelWithUnit("Time", "min")
#'
#' getLabelWithUnit("Label without unit")
#'
getLabelWithUnit <- function(label, unit = NULL) {
if (isTRUE(unit %in% "")) {
unit <- NULL
}
ifnotnull(unit, label <- paste(label, " [", unit, "]", sep = ""))
return(label)
}
15 changes: 15 additions & 0 deletions R/utilities-mapping.R
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,20 @@ smartMapping <- function(data) {
return(mapping)
}

#' @title dataMappingLabel
#' @description
#' Get label with unit based on mapping
#' @param mapping Variable name in `data` and `metaData` to get label from
#' @param metaData List of information about `data` including `dimension` and `unit`
#' @return Label as `dimention [unit]` from the mapping of the variable name
#' @keywords internal
dataMappingLabel <- function(mapping = NULL, metaData = NULL) {
label <- NULL
ifnotnull(mapping, label <- getLabelWithUnit(metaData[[mapping]]$dimension, metaData[[mapping]]$unit))

return(label)
}

#' @title DefaultDataMappingValues
#' @description List of default values used in dataMapping
DefaultDataMappingValues <- list(
Expand Down Expand Up @@ -311,3 +325,4 @@ getAggregatedData <- function(data,

return(aggregatedData)
}

10 changes: 5 additions & 5 deletions man/dataMappingLabel.Rd

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

14 changes: 10 additions & 4 deletions man/getLabelWithUnit.Rd

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

12 changes: 1 addition & 11 deletions man/getLegendCaption.Rd

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

21 changes: 0 additions & 21 deletions man/updateLegendCaption.Rd

This file was deleted.

0 comments on commit e2f393a

Please sign in to comment.