Skip to content

Commit

Permalink
Change *_mode orientation arg to be consistent with that in gg_* func…
Browse files Browse the repository at this point in the history
…tions
  • Loading branch information
davidhodge931 committed Jul 1, 2024
1 parent 1fee994 commit 054335d
Show file tree
Hide file tree
Showing 12 changed files with 90 additions and 45 deletions.
24 changes: 17 additions & 7 deletions R/dark_mode.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
#' @param legend_ticks_colour The colour of the legend.ticks theme element.
#' @param legend_ticks_linewidth The linewidth of the legend.ticks theme element.
#' @param legend_ticks_length The legend.ticks.length theme element.
#' @param orientation The orientation of the plot. Either "x" or "y". Defaults to NULL. Not intended for use with the mode argument of gg_* functions.
#' @param x_orientation TRUE or FALSE for whether it should be orientated to the x axis. Use outside of gg_* functions only.
#' @param y_orientation TRUE or FALSE for whether it should be orientated to the y axis. Use outside of gg_* functions only.
#'
#' @return A ggplot theme.
#' @export
Expand Down Expand Up @@ -84,7 +85,8 @@ dark_mode_r <- function (
legend_ticks_colour = legend_axis_line_colour,
legend_ticks_linewidth = legend_axis_line_linewidth,
legend_ticks_length = ggplot2::rel(c(0.175, 0)),
orientation = NULL) {
x_orientation = NULL,
y_orientation = NULL) {

flex_mode_r(
base_size = base_size,
Expand Down Expand Up @@ -122,7 +124,9 @@ dark_mode_r <- function (
legend_ticks_colour = legend_ticks_colour,
legend_ticks_linewidth = legend_ticks_linewidth,
legend_ticks_length = legend_ticks_length,
orientation = orientation)
x_orientation = x_orientation,
y_orientation = y_orientation
)
}

#' @rdname dark_mode_r
Expand All @@ -149,7 +153,8 @@ dark_mode_t <- function (
legend_ticks_colour = legend_axis_line_colour,
legend_ticks_linewidth = legend_axis_line_linewidth,
legend_ticks_length = ggplot2::rel(c(0.175, 0)),
orientation = NULL) {
x_orientation = NULL,
y_orientation = NULL) {

flex_mode_t(
base_size = base_size,
Expand Down Expand Up @@ -187,7 +192,9 @@ dark_mode_t <- function (
legend_ticks_colour = legend_ticks_colour,
legend_ticks_linewidth = legend_ticks_linewidth,
legend_ticks_length = legend_ticks_length,
orientation = orientation)
x_orientation = x_orientation,
y_orientation = y_orientation
)
}

#' @rdname dark_mode_r
Expand All @@ -214,7 +221,8 @@ dark_mode_b <- function (
legend_ticks_colour = legend_axis_line_colour,
legend_ticks_linewidth = legend_axis_line_linewidth,
legend_ticks_length = ggplot2::rel(c(0.175, 0)),
orientation = NULL) {
x_orientation = NULL,
y_orientation = NULL) {

flex_mode_b(
base_size = base_size,
Expand Down Expand Up @@ -252,5 +260,7 @@ dark_mode_b <- function (
legend_ticks_colour = legend_ticks_colour,
legend_ticks_linewidth = legend_ticks_linewidth,
legend_ticks_length = legend_ticks_length,
orientation = orientation)
x_orientation = x_orientation,
y_orientation = y_orientation
)
}
36 changes: 26 additions & 10 deletions R/flex_mode.R
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ flex_mode_base <- function(
legend_ticks_colour = legend_axis_line_colour,
legend_ticks_linewidth = legend_axis_line_linewidth,
legend_ticks_length = ggplot2::rel(c(0.175, 0)),
orientation = NULL
x_orientation = NULL,
y_orientation = NULL
) {

theme <- ggplot2::theme(
Expand Down Expand Up @@ -183,8 +184,17 @@ flex_mode_base <- function(
complete = FALSE
)

if (!rlang::is_null(orientation)) {
if (orientation == "x") {
# if (rlang::is_null(x_orientation)) x_orientation <- FALSE
# if (rlang::is_null(y_orientation)) y_orientation <- FALSE

if (!rlang::is_null(x_orientation) | !rlang::is_null(y_orientation)) {
if (rlang::is_null(x_orientation) & !rlang::is_null(y_orientation)) {
x_orientation <- !y_orientation
}
else if (rlang::is_null(y_orientation) & !rlang::is_null(x_orientation)) {
y_orientation <- !x_orientation
}
if (x_orientation | !y_orientation) {
theme <- theme +
ggplot2::theme(
panel.grid.major.x = ggplot2::element_blank(),
Expand All @@ -197,7 +207,7 @@ flex_mode_base <- function(
axis.minor.ticks.y.right = ggplot2::element_blank()
)
}
if (orientation == "y") {
else if (!x_orientation | y_orientation) {
theme <- theme +
ggplot2::theme(
panel.grid.major.y = ggplot2::element_blank(),
Expand Down Expand Up @@ -261,7 +271,8 @@ flex_mode_r <- function (
legend_ticks_colour = legend_axis_line_colour,
legend_ticks_linewidth = legend_axis_line_linewidth,
legend_ticks_length = ggplot2::rel(c(0.175, 0)),
orientation = NULL) {
x_orientation = NULL,
y_orientation = NULL) {

flex_mode_base(
base_size = base_size,
Expand Down Expand Up @@ -298,7 +309,8 @@ flex_mode_r <- function (
legend_ticks_colour = legend_ticks_colour,
legend_ticks_linewidth = legend_ticks_linewidth,
legend_ticks_length = legend_ticks_length,
orientation = orientation
x_orientation = x_orientation,
y_orientation = y_orientation
)
}

Expand Down Expand Up @@ -347,7 +359,8 @@ flex_mode_t <- function (
legend_ticks_colour = legend_axis_line_colour,
legend_ticks_linewidth = legend_axis_line_linewidth,
legend_ticks_length = ggplot2::rel(c(0.175, 0)),
orientation = NULL) {
x_orientation = NULL,
y_orientation = NULL) {

flex_mode_base(
base_size = base_size,
Expand Down Expand Up @@ -384,7 +397,8 @@ flex_mode_t <- function (
legend_ticks_colour = legend_ticks_colour,
legend_ticks_linewidth = legend_ticks_linewidth,
legend_ticks_length = legend_ticks_length,
orientation = orientation
x_orientation = x_orientation,
y_orientation = y_orientation
) +
ggplot2::theme(
legend.position = "top",
Expand Down Expand Up @@ -448,7 +462,8 @@ flex_mode_b <- function (
legend_ticks_colour = legend_axis_line_colour,
legend_ticks_linewidth = legend_axis_line_linewidth,
legend_ticks_length = ggplot2::rel(c(0.175, 0)),
orientation = NULL) {
x_orientation = NULL,
y_orientation = NULL) {

flex_mode_base(
base_size = base_size,
Expand Down Expand Up @@ -485,7 +500,8 @@ flex_mode_b <- function (
legend_ticks_colour = legend_ticks_colour,
legend_ticks_linewidth = legend_ticks_linewidth,
legend_ticks_length = legend_ticks_length,
orientation = orientation
x_orientation = x_orientation,
y_orientation = y_orientation
) +
ggplot2::theme(
legend.position = "bottom",
Expand Down
25 changes: 18 additions & 7 deletions R/light_mode.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
#' @param legend_ticks_colour The colour of the legend.ticks theme element.
#' @param legend_ticks_linewidth The linewidth of the legend.ticks theme element.
#' @param legend_ticks_length The legend.ticks.length theme element.
#' @param orientation The orientation of the plot. Either "x" or "y". Defaults to NULL. Not intended for use with the mode argument of gg_* functions.
#' @param x_orientation TRUE or FALSE for whether it should be orientated to the x axis. Use outside of gg_* functions only.
#' @param y_orientation TRUE or FALSE for whether it should be orientated to the y axis. Use outside of gg_* functions only.
#'
#' @return A ggplot theme.
#' @export
Expand Down Expand Up @@ -84,7 +85,9 @@ light_mode_r <- function (
legend_ticks_colour = legend_axis_line_colour,
legend_ticks_linewidth = legend_axis_line_linewidth,
legend_ticks_length = ggplot2::rel(c(0.175, 0)),
orientation = NULL) {
x_orientation = NULL,
y_orientation = NULL
) {

flex_mode_r(
base_size = base_size,
Expand Down Expand Up @@ -122,7 +125,8 @@ light_mode_r <- function (
legend_ticks_colour = legend_ticks_colour,
legend_ticks_linewidth = legend_ticks_linewidth,
legend_ticks_length = legend_ticks_length,
orientation = orientation
x_orientation = x_orientation,
y_orientation = y_orientation
)
}

Expand Down Expand Up @@ -150,7 +154,9 @@ light_mode_t <- function (
legend_ticks_colour = legend_axis_line_colour,
legend_ticks_linewidth = legend_axis_line_linewidth,
legend_ticks_length = ggplot2::rel(c(0.175, 0)),
orientation = NULL) {
x_orientation = NULL,
y_orientation = NULL
) {

flex_mode_t(
base_size = base_size,
Expand Down Expand Up @@ -188,7 +194,8 @@ light_mode_t <- function (
legend_ticks_colour = legend_ticks_colour,
legend_ticks_linewidth = legend_ticks_linewidth,
legend_ticks_length = legend_ticks_length,
orientation = orientation,
x_orientation = x_orientation,
y_orientation = y_orientation
)
}

Expand Down Expand Up @@ -216,7 +223,9 @@ light_mode_b <- function (
legend_ticks_colour = legend_axis_line_colour,
legend_ticks_linewidth = legend_axis_line_linewidth,
legend_ticks_length = ggplot2::rel(c(0.175, 0)),
orientation = NULL) {
x_orientation = NULL,
y_orientation = NULL
) {

flex_mode_b(
base_size = base_size,
Expand Down Expand Up @@ -254,6 +263,8 @@ light_mode_b <- function (
legend_ticks_colour = legend_ticks_colour,
legend_ticks_linewidth = legend_ticks_linewidth,
legend_ticks_length = legend_ticks_length,
orientation = orientation)
x_orientation = x_orientation,
y_orientation = y_orientation
)
}

2 changes: 1 addition & 1 deletion R/set_blanket.R
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ set_blanket <- function(
col_palette_na_c = "#988F88FF",
col_palette_o = scales::pal_viridis(option = "G", direction = -1),
col_palette_na_o = "#988F88FF",
theme = light_mode_r(orientation = "x")) {
theme = light_mode_r(x_orientation = TRUE)) {

weave_mode(new = mode)

Expand Down
2 changes: 1 addition & 1 deletion R/weave.R
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ weave_mode <- function(new = light_mode_r()) {
#' @param new A ggplot2 theme to be `+`-ed on unmodified to `gg_*` functions.
#'
#' @noRd
weave_theme <- function(new = light_mode_r(orientation = "x")) {
weave_theme <- function(new = light_mode_r(x_orientation = TRUE)) {
old <- ggblanket_global$theme
ggblanket_global$theme <- new
invisible(old)
Expand Down
13 changes: 9 additions & 4 deletions man/dark_mode_r.Rd

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

5 changes: 2 additions & 3 deletions man/flex_mode_b.Rd

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

3 changes: 2 additions & 1 deletion man/flex_mode_base.Rd

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

5 changes: 2 additions & 3 deletions man/flex_mode_r.Rd

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

5 changes: 2 additions & 3 deletions man/flex_mode_t.Rd

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

Loading

0 comments on commit 054335d

Please sign in to comment.