Skip to content

Commit

Permalink
fix date axis range
Browse files Browse the repository at this point in the history
  • Loading branch information
davidgohel committed Apr 13, 2021
1 parent 26107e1 commit e6af08a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
13 changes: 13 additions & 0 deletions R/axis_setting.R
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,21 @@ chart_ax_x.ms_chart <- function( x, orientation, crosses, cross_between,
num_fmt = ifelse(missing(num_fmt), x$x_axis$num_fmt, num_fmt),
rotation = ifelse(missing(rotation), x$x_axis$rotation, rotation)
)

if( missing(limit_min) && !is.null(x$x_axis$limit_min) ){
options$limit_min <- x$x_axis$limit_min
} else if( !missing(limit_min) ){
if(inherits(limit_min, "Date")){
limit_min <- as.integer(limit_min - as.Date("1899-12-30"))
}
options$limit_min <- limit_min
}
if( missing(limit_max) && !is.null(x$x_axis$limit_max) ){
options$limit_max <- x$x_axis$limit_max
} else if( !missing(limit_max) ){
if(inherits(limit_max, "Date")){
limit_max <- as.integer(limit_max - as.Date("1899-12-30"))
}
options$limit_max <- limit_max
}
if( missing(position) && !is.null(x$x_axis$position) ){
Expand Down Expand Up @@ -145,11 +152,17 @@ chart_ax_y.ms_chart <- function( x, orientation, crosses, cross_between,
if( missing(limit_min) && !is.null(x$y_axis$limit_min) ){
options$limit_min <- x$y_axis$limit_min
} else if( !missing(limit_min) ){
if(inherits(limit_min, "Date")){
limit_min <- as.integer(limit_min - as.Date("1899-12-30"))
}
options$limit_min <- limit_min
}
if( missing(limit_max) && !is.null(x$y_axis$limit_max) ){
options$limit_max <- x$y_axis$limit_max
} else if( !missing(limit_max) ){
if(inherits(limit_max, "Date")){
limit_max <- as.integer(limit_max - as.Date("1899-12-30"))
}
options$limit_max <- limit_max
}
if( missing(position) && !is.null(x$y_axis$position) ){
Expand Down
2 changes: 1 addition & 1 deletion R/series.R
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ date_ref <- function(values, region = NULL, num_fmt = NULL){

to_pml.date_ref <- function(x, add_ns = FALSE, ...){
pt_ <- "<c:pt idx=\"%.0f\"><c:v>%.0f</c:v></c:pt>"
values <- as.integer(x$values - as.Date("1900-01-01") - 2)
values <- as.integer(x$values - as.Date("1899-12-30"))
pt_ <- sprintf(pt_, seq_along(values)-1, values)
pt_ <- paste0(pt_[!is.na(values)], collapse = "")
num_fmt <- sprintf("<c:formatCode>%s</c:formatCode>", "yyyy\\-mm\\-dd" )
Expand Down

0 comments on commit e6af08a

Please sign in to comment.