Skip to content

Commit

Permalink
introduce customisable month_label_string for support to other langua…
Browse files Browse the repository at this point in the history
…ges and other use cases, fixes #46
  • Loading branch information
giocomai committed Jan 19, 2024
1 parent 8a4db8b commit 6f7a438
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Description: 'ganttrify' facilitates the creation of nice-looking Gantt charts,
License: GPL-3
Encoding: UTF-8
LazyData: true
RoxygenNote: 7.2.3
RoxygenNote: 7.3.0
Imports:
magrittr,
tibble,
Expand Down
6 changes: 4 additions & 2 deletions R/ganttrify.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#' @param size_text_relative Numeric, defaults to 1. Changes the size of all textual elements relative to their default size. If you set this to e.g. 1.5 all text elements will be 50\% bigger.
#' @param label_wrap Defaults to FALSE. If given, must be numeric, referring to the number of characters per line allowed in the labels of projects and activities, or logical (if set to TRUE, it will default to 32). To be used when labels would otherwise be excessively long.
#' @param month_number_label Logical, defaults to TRUE. If TRUE, it includes month numbering on x axis.
#' @param month_label_string Defaults to "M", relevant only if `month_number_label` is set to \code{TRUE}. String that precedes the month number: e.g. if set to "M", then months are labeled as "M1", "M2", etc.
#' @param month_date_label Logical, defaults to TRUE. If TRUE, it includes month names and dates on the x axis.
#' @param x_axis_position Logical, defaults to "top". Can also be "bottom". Used only when only one of `month_number_label` and `month_date_label` is TRUE, otherwise ignored.
#' @param colour_stripe Character, defaults to "lightgray". This is the stripe colour in the background used in alternate months.
Expand Down Expand Up @@ -58,6 +59,7 @@ ganttrify <- function(project,
size_text_relative = 1,
label_wrap = FALSE,
month_number_label = TRUE,
month_label_string = "M",
month_date_label = TRUE,
x_axis_position = "top",
colour_stripe = "lightgray",
Expand Down Expand Up @@ -253,7 +255,7 @@ ganttrify <- function(project,
breaks = date_breaks,
date_labels = "%b\n%Y",
minor_breaks = NULL,
sec.axis = ggplot2::dup_axis(labels = paste0("M", seq_along(date_breaks)*month_breaks-(month_breaks-1))))
sec.axis = ggplot2::dup_axis(labels = paste0(month_label_string, seq_along(date_breaks)*month_breaks-(month_breaks-1))))


} else if (month_number_label==FALSE&month_date_label==TRUE) {
Expand All @@ -267,7 +269,7 @@ ganttrify <- function(project,
gg_gantt <- gg_gantt +
ggplot2::scale_x_date(name = "",
breaks = date_breaks,
date_labels = paste0("M", seq_along(date_breaks)),
date_labels = paste0(month_label_string, seq_along(date_breaks)),
minor_breaks = NULL,
position = x_axis_position)
} else if (month_number_label==FALSE&month_date_label==FALSE) {
Expand Down
3 changes: 3 additions & 0 deletions man/ganttrify.Rd

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

0 comments on commit 6f7a438

Please sign in to comment.