Skip to content

Commit

Permalink
Merge ef206d1 into 42992ce
Browse files Browse the repository at this point in the history
  • Loading branch information
Jordan S Read committed Mar 22, 2017
2 parents 42992ce + ef206d1 commit c87e466
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 11 deletions.
31 changes: 21 additions & 10 deletions R/axis.R
Original file line number Diff line number Diff line change
Expand Up @@ -74,28 +74,39 @@ axis.gsplot <- function(object, ..., n.minor=0, tcl.minor=NA, reverse=NULL, appe

fun.name <- "axis"

user_args <- filter_arguments(fun.name = fun.name, ...,
custom.config = object[["global"]][["config"]][["config.file"]])$call.args
args <- filter_arguments(fun.name = fun.name, ...,
custom.config = object[["global"]][["config"]][["config.file"]])

sides <- user_args[[fun.name]]$side
user_args[[fun.name]]$side <- NULL
user_args[[fun.name]]$n.minor <- n.minor
user_args[[fun.name]]$tcl.minor <- tcl.minor
if (length(args$extracted.args) > 0){
warning('axis.gsplot is not configured to support embedded function calls', call. = FALSE)
}

user.args <- args$call.args
sides <- user.args[[fun.name]]$side

if (is.null(sides)){
return(object)
}

user.args[[fun.name]]$side <- NULL
user.args[[fun.name]]$n.minor <- n.minor
user.args[[fun.name]]$tcl.minor <- tcl.minor

user.args[[fun.name]] <- append_replace(user.args[[fun.name]], args$option.args)

for(side in sides){
# append the side and give it defaults if it doesn't exist
if(append){

} else {
if(!append){
object <- modify_side(object, args = list(), side=side)
}

object[[as.side_name(side)]][['usr.axes']] <- TRUE
object[[as.side_name(side)]][['axis']] <- append_replace(object[[as.side_name(side)]][['axis']], user_args[[fun.name]])
object[[as.side_name(side)]][['axis']] <- append_replace(object[[as.side_name(side)]][['axis']], user.args[[fun.name]])
if (!is.null(reverse)){
object[[as.side_name(side)]][['reverse']] <- reverse
}
}

class(object) <- 'gsplot'
return(object)

Expand Down
25 changes: 24 additions & 1 deletion tests/testthat/tests-axis.R
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,28 @@ test_that("axis tracks append FALSE by default",{
# expect_equal(sum(names(gs$side.1) == 'axis'), 2)
})

context("axis style arguments handled appropriately")

test_that("par args sent to axis() end up in axis args",{
gs <- points(gsplot(), 1, 0) %>% axis(side=1, tcl = -0.25)
expect_equal(gs$side.1$axis[["tcl"]], -0.25)
})

test_that("special args given to axis are retained", {
gs <- points(gsplot(), 1, 0) %>% axis(side=1, n.minor = 4)
expect_equal(gs$side.1$axis[["n.minor"]], 4)

gs <- points(gsplot(), 1, 0) %>% axis(side=1, tcl.minor = -0.136)
expect_equal(gs$side.1$axis[["tcl.minor"]], -0.136)
})

test_that("style params given to points calls are in side par, style on axis stay there",{
gs <- points(gsplot(), 1, 0, tcl=0.5) %>% axis(side=1, tcl = -0.136)
expect_equal(gs$side.1$axis[["tcl"]], -0.136)
expect_equal(gs$side.1$par[["tcl"]], 0.5)
})


context("axis user flipped on")

test_that("axis user FALSE by default",{
Expand All @@ -97,13 +119,14 @@ test_that("axis user flipped to TRUE when specified",{
})



test_that("format",{

gs <- gsplot() %>%
points(seq.Date(as.Date("2010-01-01"), as.Date("2010-12-31"), by="month"),
1:12) %>%
axis(side = 1, format="%Y-%m")

expect_true(class(gs$side.1$lim) == "Date")

gs <- gsplot() %>%
Expand Down

0 comments on commit c87e466

Please sign in to comment.