Skip to content

Commit 4413167

Browse files
committed
Resolved local conflict
Merge branch 'master' of github.com:USGS-R/gsplot into config_cleanup Conflicts: R/config.R
2 parents b3fb977 + 768766f commit 4413167

File tree

8 files changed

+77
-29
lines changed

8 files changed

+77
-29
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: gsplot
22
Type: Package
33
Title: Geological Survey Plotting
4-
Version: 0.5.1
4+
Version: 0.5.4
55
Date: 2015-12-13
66
Authors@R: c( person("Jordan", "Read", role = "aut",
77
email = "[email protected]"),

R/bgCol.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ bgCol.default <- function(col,...){
6262
y2 <- par("usr")[4]
6363
}
6464

65-
rect(x1,y1,x2,y2,col = col,...)
65+
rect(x1,y1,x2,y2,col = col, border = NA, ...)
6666

6767
}
6868

R/callouts.R

Lines changed: 51 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,12 @@ callouts.default <- function(x, y=NULL, labels=NA, length=0.1, angle='auto', cex
4949
return()
5050
}
5151

52-
stopifnot(angle=='auto' | (angle >= 0 & angle <= 360))
52+
stopifnot(all(angle=='auto' | is.na(angle) | (angle >= 0 & angle <= 360)))
5353

5454
x <- x[!is.na(labels)]
5555
y <- y[!is.na(labels)]
5656
labels <- labels[!is.na(labels)]
57+
if(length(angle) > 1){angle[!is.na(labels)]}
5758

5859
# // to do: possibly support angle and length as vectors equal in length to x
5960
x.usr <- par("usr")[c(1,2)]
@@ -66,30 +67,58 @@ callouts.default <- function(x, y=NULL, labels=NA, length=0.1, angle='auto', cex
6667
xrange <- diff(x.usr)
6768
yrange <- diff(y.usr)
6869

69-
if (angle != "auto") {
70-
x1 <- x + length * xrange * cos(2*pi*(angle/360))
71-
y1 <- y + length * yrange * sin(2*pi*(angle/360))
70+
calc_x1y1 <- function(x, y, angle, length, xrange, yrange, x.usr, y.usr){
71+
72+
if (is.na(angle) | angle == "auto") {
73+
auto.angle <- c(30, 330, 150, 210)
74+
x1 <- sapply(auto.angle, function(a) {
75+
x + length * xrange * cos(2*pi*(a/360))
76+
})
77+
y1 <- sapply(auto.angle, function(a) {
78+
y + length * yrange * sin(2*pi*(a/360))
79+
})
80+
81+
good.y1 <- y1 >= y.usr[1] & y1 <= y.usr[2]
82+
good.x1 <- x1 >= x.usr[1] & x1 <= x.usr[2]
83+
good.pt <- good.y1 & good.x1
84+
if (!is.null(dim(good.pt))){
85+
angle <- auto.angle[apply(good.pt, 1, function(z){
86+
ifelse(!any(z), 1, min(which(z)))
87+
})]
88+
} else {
89+
angle <- auto.angle[ifelse(!any(good.pt), 1, min(which(good.pt)))]
90+
}
91+
x1 <- x + length * xrange * cos(2*pi*(angle/360))
92+
y1 <- y + length * yrange * sin(2*pi*(angle/360))
93+
} else {
94+
x1 <- x + length * xrange * cos(2*pi*(angle/360))
95+
y1 <- y + length * yrange * sin(2*pi*(angle/360))
96+
}
97+
98+
return(list(x1 = x1, y1 = y1, angle = angle))
99+
}
100+
101+
if(length(angle) == 1){
102+
x1_y1_angle <- calc_x1y1(x = x, y = y, angle = angle,
103+
length, xrange, yrange, x.usr, y.usr)
104+
x1 <- x1_y1_angle$x1
105+
y1 <- x1_y1_angle$y1
106+
angle <- x1_y1_angle$angle
72107
} else {
73-
auto.angle <- c(30, 330, 150, 210)
74-
x1 <- sapply(auto.angle, function(a) {
75-
x + length * xrange * cos(2*pi*(a/360))
76-
})
77-
y1 <- sapply(auto.angle, function(a) {
78-
y + length * yrange * sin(2*pi*(a/360))
79-
})
108+
stopifnot(length(x)%%length(angle) == 0) #stop if the defined angles aren't a multiple of the points
109+
stopifnot(!is.character(angle)) #stop if it's not a numeric vector ('auto' is not used for the vector)
110+
111+
num_pts <- length(x)
112+
x1 <- vector(mode = "numeric", length = num_pts)
113+
y1 <- vector(mode = "numeric", length = num_pts)
80114

81-
good.y1 <- y1 >= y.usr[1] & y1 <= y.usr[2]
82-
good.x1 <- x1 >= x.usr[1] & x1 <= x.usr[2]
83-
good.pt <- good.y1 & good.x1
84-
if (!is.null(dim(good.pt))){
85-
angle <- auto.angle[apply(good.pt, 1, function(z){
86-
ifelse(!any(z), 1, min(which(z)))
87-
})]
88-
} else {
89-
angle <- auto.angle[ifelse(!any(good.pt), 1, min(which(good.pt)))]
115+
for(r in seq(num_pts)){
116+
x1_y1_angle <- calc_x1y1(x = x[r], y = y[r], angle = angle[r],
117+
length, xrange, yrange, x.usr, y.usr)
118+
x1[r] <- x1_y1_angle$x1
119+
y1[r] <- x1_y1_angle$y1
120+
angle[r] <- x1_y1_angle$angle
90121
}
91-
x1 <- x + length * xrange * cos(2*pi*(angle/360))
92-
y1 <- y + length * yrange * sin(2*pi*(angle/360))
93122
}
94123

95124
pos <- rep(1, length(angle))

R/print.R

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ print.gsplot <- function(x, ...){
6262

6363
# -- initial view --
6464
if(i == view.index[1]){
65-
bgCol(bg.arg)
65+
if (!is.null(bg.arg))
66+
bgCol(bg.arg)
6667
title(title.arg)
6768
}
6869

R/set_args.R

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,23 @@ set_legend_args <- function(object, fun.name, ..., legend.name) {
5454

5555
paramsAll <- set_args(fun.name, list(...))
5656

57+
if(length(legend.name) > 1){
58+
paramsAll_df <- as.data.frame(paramsAll, stringsAsFactors = FALSE)
59+
60+
for(p in seq(nrow(paramsAll_df))) {
61+
paramsAll_list <- as.list(paramsAll_df[p,])
62+
object <- get_legend_args(object, fun.name, paramsAll_list, legend.name[p])
63+
}
64+
65+
} else {
66+
object <- get_legend_args(object, fun.name, paramsAll, legend.name)
67+
}
68+
69+
return(object)
70+
}
71+
72+
get_legend_args <- function(object, fun.name, paramsAll, legend.name){
73+
5774
fun.default <- list(legend=legend.name,
5875
fill=quote(par("bg")),
5976
col=par("col"),
@@ -68,7 +85,7 @@ set_legend_args <- function(object, fun.name, ..., legend.name) {
6885
pt.lwd=NA,
6986
text.col=par("col"),
7087
text.font=1)
71-
88+
7289
type <- paramsAll[['type']]
7390
if(!is.null(type)){
7491
type.name <- switch(type, p='p', b='bo', o='bo', l='lchsS',
@@ -81,7 +98,7 @@ set_legend_args <- function(object, fun.name, ..., legend.name) {
8198
paramsAll <- set_type_params(paramsAll, type.name, params.needed)
8299
if(type.name %in% c('p', 'lchsS')) {fun.name <- switch(type.name, p="points", lchsS="lines")}
83100
}
84-
101+
85102
if (fun.name == "points") {
86103
pt.names <- c("lwd","bg","cex")
87104
names(paramsAll) <- replace(names(paramsAll), which(names(paramsAll) %in% pt.names),
@@ -91,7 +108,7 @@ set_legend_args <- function(object, fun.name, ..., legend.name) {
91108
pt.bg=quote(par("bg")),
92109
pt.cex=par("cex"),
93110
pt.lwd=par("lwd"))
94-
111+
95112
} else if (fun.name %in% c("lines", "abline", "arrows", "segments")) {
96113
fun.specific <- list(border=quote(par("bg")),
97114
lty=1,
@@ -108,13 +125,14 @@ set_legend_args <- function(object, fun.name, ..., legend.name) {
108125
fun.all <- replace(fun.default, match(names(fun.specific), names(fun.default)), fun.specific)
109126
add.args <- fun.all[!names(fun.all) %in% names(usr.args)]
110127
fun.legend.args <- append(usr.args, add.args)
111-
128+
112129
if(!is.character(fun.legend.args$lty)){
113130
lineTypes <- c("blank", "solid", "dashed", "dotted", "dotdash", "longdash", "twodash")
114131
fun.legend.args$lty <- lineTypes[fun.legend.args$lty + 1]
115132
}
116133

117134
object[['legend']] <- append(object[['legend']], list(legend.args=fun.legend.args))
135+
118136
return(object)
119137
}
120138

43 Bytes
Loading
135 Bytes
Loading
-27 Bytes
Loading

0 commit comments

Comments
 (0)