Skip to content

Commit

Permalink
format with {styler} (#366)
Browse files Browse the repository at this point in the history
  • Loading branch information
IndrajeetPatil committed Aug 11, 2022
1 parent 7bdcb83 commit e30924b
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 46 deletions.
9 changes: 4 additions & 5 deletions R/aaa-utilities.R
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,11 @@
#' @return A `ggplot` object
#' @keywords internal
.updateSameAxes <- function(plotObject, data, dataMapping) {
if(!all(
if (!all(
plotObject$plotConfiguration$defaultSymmetricAxes,
isEmpty(plotObject$plotConfiguration$xAxis$limits),
isEmpty(plotObject$plotConfiguration$yAxis$limits)
)){
)) {
return(plotObject)
}
limits <- .getSameLimitsFromMapping(data, dataMapping)
Expand All @@ -131,14 +131,13 @@
#' @return A `ggplot` object
#' @keywords internal
.updateSymmetricAxes <- function(plotObject, data, dataMapping) {
if(!all(
if (!all(
plotObject$plotConfiguration$defaultSymmetricAxes,
isEmpty(plotObject$plotConfiguration$yAxis$limits)
)){
)) {
return(plotObject)
}
limits <- getSymmetricLimits(data[, dataMapping$y])
plotObject$plotConfiguration$yAxis$limits <- limits
return(plotObject)
}

18 changes: 9 additions & 9 deletions R/helpers.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
#' @param values numeric values
#' @return An array of 2 symmetric values equally distant from 0
#' @export
#' @examples
#' @examples
#' getSymmetricLimits(seq(-3, 8))
#'
getSymmetricLimits <- function(values){
#'
getSymmetricLimits <- function(values) {
validateIsNumeric(values, nullAllowed = TRUE)
# Remove Inf and NA values
values <- values[!is.infinite(values)]
values <- values[!is.na(values)]
if(isEmpty(values)){
if (isEmpty(values)) {
return(NULL)
}
return(c(-max(abs(values)), max(abs(values))))
Expand All @@ -23,17 +23,17 @@ getSymmetricLimits <- function(values){
#' @param ... numeric values
#' @return An array of 2 values
#' @export
#' @examples
#' @examples
#' getSameLimits(seq(-3, 8), seq(-12, 4))
#'
getSameLimits <- function(...){
#'
getSameLimits <- function(...) {
values <- c(...)
validateIsNumeric(values, nullAllowed = TRUE)
# Remove Inf and NA values
values <- values[!is.infinite(values)]
values <- values[!is.na(values)]
if(isEmpty(values)){
if (isEmpty(values)) {
return(NULL)
}
return(c(min(values), max(values)))
}
}
41 changes: 20 additions & 21 deletions R/plot-timeprofile.R
Original file line number Diff line number Diff line change
Expand Up @@ -389,46 +389,46 @@ updateTimeProfileLegend <- function(plotObject, caption) {
linetype = ggplot2::scale_linetype_manual,
fill = ggplot2::scale_fill_manual
)

unDefinedNames <- list()
for(property in c("shape", "linetype", "fill")){
# Use suppressMessages to prevent ggplot2 to
for (property in c("shape", "linetype", "fill")) {
# Use suppressMessages to prevent ggplot2 to
# throw message that scale was updated
suppressMessages(
plotObject <- plotObject +
scaleFunction[[property]](
breaks = caption[[property]]$names,
labels = caption[[property]]$labels,
values = caption[[property]]$values
)
)
suppressMessages(
plotObject <- plotObject +
scaleFunction[[property]](
breaks = caption[[property]]$names,
labels = caption[[property]]$labels,
values = caption[[property]]$values
)
)
# Get legend names that are not scaled but in final legend
unDefinedNames[[property]] <- setdiff(
caption$color$names,
caption$color$names,
caption[[property]]$colorNames
)
# Fill in the caption guide for shape, linetype and fill
caption[[property]] <- rbind.data.frame(
caption[[property]],
data.frame(
names = unDefinedNames[[property]],
names = unDefinedNames[[property]],
labels = unDefinedNames[[property]],
colorNames = unDefinedNames[[property]],
colorNames = unDefinedNames[[property]],
values = rep(blankValues[[property]], length(unDefinedNames[[property]]))
),
stringsAsFactors = FALSE
)
# Keep only names and order provided by color legend
captionOrder <- sapply(
caption$color$names,
function(colorName){
function(colorName) {
head(which(caption[[property]]$colorNames == colorName), 1)
}
)
}
)
caption[[property]] <- caption[[property]][captionOrder, ]
}
# Update color scale and use color caption

# Update color scale and use color caption
# as reference for displaying final legend
suppressMessages(
plotObject <- plotObject +
Expand All @@ -446,11 +446,10 @@ updateTimeProfileLegend <- function(plotObject, caption) {
shape = caption$shape$values,
fill = caption$fill$values,
linetype = caption$linetype$values
)
)
)
)
)
plotObject$plotConfiguration$legend$caption <- caption
return(plotObject)
}

4 changes: 2 additions & 2 deletions R/plotconfiguration-axis.R
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ AxisConfiguration <- R6::R6Class(
private$.ticks
)
},

#' @description Get tick values for pretty default log plots
#' @return User defined tick values or tlf default ticks
prettyMinorTicks = function() {
Expand All @@ -160,7 +160,7 @@ AxisConfiguration <- R6::R6Class(
return(private$.minorTicks)
}
# Default tick values as a function of scale
if(isIncluded(private$.scale, Scaling$log)){
if (isIncluded(private$.scale, Scaling$log)) {
return(tlfEnv$logMinorTicks)
}
return(private$.minorTicks)
Expand Down
4 changes: 2 additions & 2 deletions R/plotconfiguration-background.R
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ BackgroundConfiguration <- R6::R6Class(
panel.grid.major.x = private$.xGrid$createPlotElement(),
panel.grid.major.y = private$.yGrid$createPlotElement(),
# Minor grid is same as Major grid but less thick
panel.grid.minor.x = private$.xGrid$createPlotElement(size = as.numeric(private$.xGrid$size)/2),
panel.grid.minor.y = private$.yGrid$createPlotElement(size = as.numeric(private$.yGrid$size)/2)
panel.grid.minor.x = private$.xGrid$createPlotElement(size = as.numeric(private$.xGrid$size) / 2),
panel.grid.minor.y = private$.yGrid$createPlotElement(size = as.numeric(private$.yGrid$size) / 2)
)
return(plotObject)
}
Expand Down
2 changes: 1 addition & 1 deletion R/tlf-env.R
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ setDefaultWatermark <- function(watermark = NULL) {
tlfEnv$logTicks <- 10^seq(-10, 10)
tlfEnv$lnTicks <- exp(seq(-10, 10))
# Log minor ticks for every integer
tlfEnv$logMinorTicks <- rep(seq(1,9), 21)*rep(10^seq(-10, 10), each = 9)
tlfEnv$logMinorTicks <- rep(seq(1, 9), 21) * rep(10^seq(-10, 10), each = 9)

#' @title setDefaultLogTicks
#' @description Set default values for log ticks
Expand Down
6 changes: 3 additions & 3 deletions R/utilities-aesthetics.R
Original file line number Diff line number Diff line change
Expand Up @@ -159,14 +159,14 @@
#' @param propertyName Name of aesthetic property (e.g. `"shape"`...)
#' @return Selected levels of `data[,columnNames$color]`
#' @keywords internal
.getColorNamesForFirstAesValues <- function(data, columnNames, propertyName){
.getColorNamesForFirstAesValues <- function(data, columnNames, propertyName) {
colorNames <- sapply(
levels(data[, columnNames[[propertyName]]]),
function(propertyLevel){
function(propertyLevel) {
head(data[which(data[, columnNames[[propertyName]]] %in% propertyLevel), columnNames$color], 1)
}
)
return(colorNames)
return(colorNames)
}


Expand Down
5 changes: 2 additions & 3 deletions R/utilities-mapping.R
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,6 @@ getLinesFromFoldDistance <- function(foldDistance) {
#' @param data A data.frame with labels mapped to properties and obtained from a `DataMapping` object
#' @param dataMapping A `ObsVsPredDataMapping` object
#' @keywords internal
.getSameLimitsFromMapping <- function(data, dataMapping){
getSameLimits(data[,dataMapping$x], data[,dataMapping$y], data[,dataMapping$xmin], data[,dataMapping$xmax])
.getSameLimitsFromMapping <- function(data, dataMapping) {
getSameLimits(data[, dataMapping$x], data[, dataMapping$y], data[, dataMapping$xmin], data[, dataMapping$xmax])
}

0 comments on commit e30924b

Please sign in to comment.