Skip to content

Commit 94c6d83

Browse files
committed
Merge pull request #276 from lindsaycarr/master
xaxs='o' test; fixed pt.lwd/bg issue; cex is formal of callouts.default
2 parents 75f4e72 + d143334 commit 94c6d83

File tree

5 files changed

+50
-8
lines changed

5 files changed

+50
-8
lines changed

R/calc_views.R

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,8 @@ set_view_lim <- function(views){
123123
data <- list(y=summarize_args(views,c('y','y1','y0'),ignore=c('window','gs.config')),
124124
x=summarize_args(views,c('x','x1','x0'),ignore=c('window','gs.config')))
125125

126-
axs <- list(yaxs=summarize_args(views,c('yaxs'),ignore=c('window','gs.config')),
127-
xaxs=summarize_args(views,c('xaxs'),ignore=c('window','gs.config')))
126+
axs <- list(yaxs=summarize_args(views,c('yaxs'),ignore=c('gs.config')),
127+
xaxs=summarize_args(views,c('xaxs'),ignore=c('gs.config')))
128128

129129
definedSides <- unlist(c_unname(views),recursive = FALSE)
130130
definedSides <- unique(unname(unlist(definedSides[grep("side", names(definedSides))])))
@@ -158,16 +158,17 @@ set_view_lim <- function(views){
158158

159159
usr.axs <- axs[[axs.name]][[n.i]]
160160

161-
if (!is.na(usr.axs) && usr.axs == 'o') {
161+
if (any(!is.na(usr.axs)) && any(usr.axs == 'o')) {
162162
if (all(!is.na(usr.lim)))
163163
stop('no NA given to distinguish buffered limit')
164164

165165
view.i <- which(!names(views[[n.i]]) %in% c('window', 'gs.config'))
166166
buffer <- 0.04*diff(views[[n.i]][['window']][[lim.name]])
167167
lim <- views[[n.i]][['window']][[lim.name]][[which(is.na(usr.lim))]]
168168
buffered.lim <- ifelse(which(is.na(usr.lim)) == 1, lim - buffer, lim + buffer)
169+
views[[n.i]][[view.i]][[lim.name]][[which(is.na(usr.lim))]] <- buffered.lim
169170
views[[n.i]][['window']][[lim.name]][[which(is.na(usr.lim))]] <- buffered.lim
170-
views[[n.i]][[view.i]][[axs.name]] <- NULL
171+
views[[n.i]][['window']][['par']][[axs.name]] <- NULL
171172
views[['par']][[axs.name]] <- 'i'
172173
}
173174

R/callouts.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ callouts.gsplot <- function(object, ..., side=c(1,2)){
4141
#'
4242
#' @rdname callouts
4343
#' @export
44-
callouts.default <- function(x, y=NULL, labels=NA, length=0.1, angle='auto', ...){
44+
callouts.default <- function(x, y=NULL, labels=NA, length=0.1, angle='auto', cex=1, ...){
4545

4646
if (is.null(y)) {
4747
warning("y=NULL not currently supported in callouts.default")
@@ -97,6 +97,6 @@ callouts.default <- function(x, y=NULL, labels=NA, length=0.1, angle='auto', ...
9797
pos[angle > 135 & angle <= 225] <- 2
9898

9999
segments(x0=x, y0=y, x1=x1, y1=y1, ...)
100-
text(x=x1, y=y1, labels=labels, pos=pos,...)
100+
text(x=x1, y=y1, labels=labels, pos=pos, cex=cex, ...)
101101

102102
}

R/set_args.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ set_legend_args <- function(object, fun.name, ..., legend.name) {
8585
if (fun.name == "points") {
8686
pt.names <- c("lwd","bg","cex")
8787
names(paramsAll) <- replace(names(paramsAll), which(names(paramsAll) %in% pt.names),
88-
paste0("pt.", pt.names[which(pt.names %in% names(paramsAll))]))
88+
paste0("pt.", pt.names[na.omit(match(names(paramsAll), pt.names))]))
8989
fun.specific <- list(border=quote(par("bg")),
9090
pch=1,
9191
pt.bg=quote(par("bg")),

man/callouts.Rd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
callouts(object, ...)
99

1010
callouts.default(x, y = NULL, labels = NA, length = 0.1, angle = "auto",
11-
...)
11+
cex = 1, ...)
1212
}
1313
\arguments{
1414
\item{object}{gsplot object}

tests/testthat/test-set_view_lim.R

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
context("set_view_lim")
2+
3+
test_that("gsplot xaxs = 'o' works", {
4+
gs <- gsplot() %>%
5+
points(1:4,1:4, xlim=c(NA,10), xaxs='o') %>%
6+
lines(1:6,1:6)
7+
8+
beforeBuffer <- c(1,10)
9+
buffer <- diff(beforeBuffer)*0.04
10+
afterBuffer <- c(beforeBuffer[1]-buffer, beforeBuffer[2])
11+
12+
expect_equal(xlim(gs), afterBuffer)
13+
expect_equal(par(gs)$xaxs, "i")
14+
})
15+
16+
17+
test_that("gsplot yaxs = 'o' works", {
18+
gs <- gsplot() %>%
19+
points(1:4,1:4, ylim=c(0,NA), yaxs='o') %>%
20+
lines(1:6,1:6)
21+
22+
beforeBuffer <- c(0,4)
23+
buffer <- diff(beforeBuffer)*0.04
24+
afterBuffer <- c(beforeBuffer[1], beforeBuffer[2]+buffer)
25+
26+
expect_equal(ylim(gs), afterBuffer)
27+
expect_equal(par(gs)$yaxs, "i")
28+
})
29+
30+
test_that("gsplot yaxs = 'o' works in gsplot()", {
31+
gs <- gsplot(ylim=c(0,NA), yaxs='o') %>%
32+
points(1:4,1:4) %>%
33+
lines(1:6,1:6)
34+
35+
beforeBuffer <- c(0,6)
36+
buffer <- diff(beforeBuffer)*0.04
37+
afterBuffer <- c(beforeBuffer[1], beforeBuffer[2]+buffer)
38+
39+
expect_equal(ylim(gs), afterBuffer)
40+
expect_equal(par(gs)$yaxs, "i")
41+
})

0 commit comments

Comments
 (0)