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

406 data mapping factors #407

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
3 changes: 0 additions & 3 deletions R/observed-data-mapping.R
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,6 @@ ObservedDataMapping <- R6::R6Class(
#' @param data A data.frame
#' @return A data.frame to be plotted in right axis
getRightAxis = function(data) {
if(!self$requireDualAxis(data)){
return(NULL)
}
# Ensure NAs in that data don't mess up the selection
selectedRows <- as.logical(data[, self$y2Axis]) %in% FALSE
if (isIncluded(self$ymax, names(data))) {
Expand Down
3 changes: 0 additions & 3 deletions R/timeprofile-datamapping.R
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,6 @@ TimeProfileDataMapping <- R6::R6Class(
#' @param data A data.frame
#' @return A data.frame to be plotted in right axis
getRightAxis = function(data) {
if (!self$requireDualAxis(data)) {
return(NULL)
}
# Ensure NAs in that data don't mess up the selection
selectedRows <- as.logical(data[, self$y2Axis]) %in% FALSE
if (isIncluded(self$ymax, names(data))) {
Expand Down
70 changes: 39 additions & 31 deletions R/utilities-mapping.R
Original file line number Diff line number Diff line change
Expand Up @@ -97,44 +97,52 @@
#'
#' # Get captions separating variables witha space (character " ")
#' getDefaultCaptions(data, metaData, sep = " ")
getDefaultCaptions <- function(data, metaData, variableList = colnames(data), sep = "-") {
getDefaultCaptions <- function(data, metaData = NULL, variableList = colnames(data), sep = "-") {
# Check that the grouping is in the list of data variables
stopifnot(variableList %in% colnames(data))

groupingVariable <- .asLegendCaptionSubset(
data[, variableList[1]],
metaData[[variableList[1]]]
)

# Loop on the variableList except first one
# pasting as a single data.frame column the association of names in all selected variables
for (variable in utils::tail(variableList, -1)) {
groupingVariable <- paste(
groupingVariable,
validateIsIncluded(variableList, colnames(data))

captions <- NULL
for(variableName in variableList){
if(is.null(captions)){
captions <- .asLegendCaptionSubset(
data[, variableName],
metaData[[variableName]]$unit
)
next
}
captions <- paste(
captions,
.asLegendCaptionSubset(
data[, variable],
metaData[[variable]]
),
sep = sep
data[, variableName],
metaData[[variableName]]$unit
),
sep = sep
)
}

if (isEmpty(captions)) {
return(factor(""))
}

if (length(groupingVariable) == 0) {
groupingVariable <- 1
}
groupingVariable <- as.factor(groupingVariable)
return(groupingVariable)
return(as.factor(captions))
}


.asLegendCaptionSubset <- function(data, metaData) {
captionSubset <- as.character(data)

# If numeric create a character as rounded numeric + unit from metadata
if ("numeric" %in% class(data)) {
captionSubset <- paste(as.character(round(data)), metaData$unit, sep = "")
#' @title .asLegendCaptionSubset
#' @param labels
#' @param unit A character added as unit to label
#' @description
#' Creates default legend captions subset
#' @keywords internal
.asLegendCaptionSubset <- function(labels, unit = NULL) {
# Keep ordering of labels as is if factor
captionLevels <- sort(unique(labels))
if(isOfType(labels, "factor")){
captionLevels <- levels(labels)
}

captionSubset <- factor(
getLabelWithUnit(labels, unit = unit),
levels = getLabelWithUnit(captionLevels, unit = unit)
)

return(captionSubset)
}

Expand Down
17 changes: 17 additions & 0 deletions man/dot-asLegendCaptionSubset.Rd

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

7 changes: 6 additions & 1 deletion man/getDefaultCaptions.Rd

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