Skip to content

Commit d2c9a3d

Browse files
author
Lindsay Carr
authored
Merge pull request #459 from jread-usgs/axis_trouble
Axis par args not getting into the render
2 parents 097bb32 + ef206d1 commit d2c9a3d

File tree

2 files changed

+45
-11
lines changed

2 files changed

+45
-11
lines changed

R/axis.R

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -74,28 +74,39 @@ axis.gsplot <- function(object, ..., n.minor=0, tcl.minor=NA, reverse=NULL, appe
7474

7575
fun.name <- "axis"
7676

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

80-
sides <- user_args[[fun.name]]$side
81-
user_args[[fun.name]]$side <- NULL
82-
user_args[[fun.name]]$n.minor <- n.minor
83-
user_args[[fun.name]]$tcl.minor <- tcl.minor
80+
if (length(args$extracted.args) > 0){
81+
warning('axis.gsplot is not configured to support embedded function calls', call. = FALSE)
82+
}
83+
84+
user.args <- args$call.args
85+
sides <- user.args[[fun.name]]$side
86+
87+
if (is.null(sides)){
88+
return(object)
89+
}
90+
91+
user.args[[fun.name]]$side <- NULL
92+
user.args[[fun.name]]$n.minor <- n.minor
93+
user.args[[fun.name]]$tcl.minor <- tcl.minor
94+
95+
user.args[[fun.name]] <- append_replace(user.args[[fun.name]], args$option.args)
8496

8597
for(side in sides){
8698
# append the side and give it defaults if it doesn't exist
87-
if(append){
88-
89-
} else {
99+
if(!append){
90100
object <- modify_side(object, args = list(), side=side)
91101
}
92102

93103
object[[as.side_name(side)]][['usr.axes']] <- TRUE
94-
object[[as.side_name(side)]][['axis']] <- append_replace(object[[as.side_name(side)]][['axis']], user_args[[fun.name]])
104+
object[[as.side_name(side)]][['axis']] <- append_replace(object[[as.side_name(side)]][['axis']], user.args[[fun.name]])
95105
if (!is.null(reverse)){
96106
object[[as.side_name(side)]][['reverse']] <- reverse
97107
}
98108
}
109+
99110
class(object) <- 'gsplot'
100111
return(object)
101112

tests/testthat/tests-axis.R

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,28 @@ test_that("axis tracks append FALSE by default",{
8383
# expect_equal(sum(names(gs$side.1) == 'axis'), 2)
8484
})
8585

86+
context("axis style arguments handled appropriately")
87+
88+
test_that("par args sent to axis() end up in axis args",{
89+
gs <- points(gsplot(), 1, 0) %>% axis(side=1, tcl = -0.25)
90+
expect_equal(gs$side.1$axis[["tcl"]], -0.25)
91+
})
92+
93+
test_that("special args given to axis are retained", {
94+
gs <- points(gsplot(), 1, 0) %>% axis(side=1, n.minor = 4)
95+
expect_equal(gs$side.1$axis[["n.minor"]], 4)
96+
97+
gs <- points(gsplot(), 1, 0) %>% axis(side=1, tcl.minor = -0.136)
98+
expect_equal(gs$side.1$axis[["tcl.minor"]], -0.136)
99+
})
100+
101+
test_that("style params given to points calls are in side par, style on axis stay there",{
102+
gs <- points(gsplot(), 1, 0, tcl=0.5) %>% axis(side=1, tcl = -0.136)
103+
expect_equal(gs$side.1$axis[["tcl"]], -0.136)
104+
expect_equal(gs$side.1$par[["tcl"]], 0.5)
105+
})
106+
107+
86108
context("axis user flipped on")
87109

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

99121

122+
100123
test_that("format",{
101124

102125
gs <- gsplot() %>%
103126
points(seq.Date(as.Date("2010-01-01"), as.Date("2010-12-31"), by="month"),
104127
1:12) %>%
105128
axis(side = 1, format="%Y-%m")
106-
129+
107130
expect_true(class(gs$side.1$lim) == "Date")
108131

109132
gs <- gsplot() %>%

0 commit comments

Comments
 (0)