Skip to content

Commit 61ecc73

Browse files
committed
Merging conflicts.
Merge branch 'master' of github.com:USGS-R/gsplot Conflicts: README_files/figure-markdown_github/unnamed-chunk-2-1.png README_files/figure-markdown_github/unnamed-chunk-4-1.png
2 parents 72e0c96 + f666b14 commit 61ecc73

File tree

9 files changed

+212
-2
lines changed

9 files changed

+212
-2
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.4.0
4+
Version: 0.4.1
55
Date: 2015-09-16
66
Authors@R: c( person("Jordan", "Read", role = "aut",
77
email = "[email protected]"),

NAMESPACE

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
# Generated by roxygen2 (4.1.1): do not edit by hand
22

33
S3method(gsplot,default)
4+
S3method(logged,gsplot)
45
S3method(print,gsplot)
6+
S3method(xlim,gsplot)
7+
S3method(ylim,gsplot)
58
export("%>%")
69
export(abline)
710
export(arrows)
@@ -19,6 +22,7 @@ export(is.gsplot)
1922
export(legend)
2023
export(lines)
2124
export(loadConfig)
25+
export(logged)
2226
export(mtext)
2327
export(par)
2428
export(points)
@@ -28,6 +32,8 @@ export(segments)
2832
export(symbols)
2933
export(text)
3034
export(title)
35+
export(xlim)
36+
export(ylim)
3137
exportMethods(gsplot)
3238
importFrom(graphics,box)
3339
importFrom(graphics,mtext)

R/access-gsplot.R

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
2+
3+
#' xlim for gsplot
4+
#'
5+
#' get the xlim for views in gsplot object
6+
#'
7+
#' @param object a gsplot object
8+
#' @param side which side(s) to use
9+
#'
10+
#' @export
11+
xlim <- function(object, side) UseMethod("xlim")
12+
13+
#' @export
14+
xlim.gsplot <- function(object, side=NULL){
15+
16+
if (!is.null(side))
17+
views <- object[views_with_side(views(object), side)]
18+
else
19+
views <- views(object)
20+
names = unname(sapply(views, function(x) paste0('side.',x$window$side[1])))
21+
unique(lapply(views, function(x) x$window$xlim)) %>%
22+
setNames(unique(names))
23+
}
24+
25+
#' ylim for gsplot
26+
#'
27+
#' get the ylim for views in gsplot object
28+
#'
29+
#' @param object a gsplot object
30+
#' @param side which side(s) to use
31+
#'
32+
#' @export
33+
ylim <- function(object, side) UseMethod("ylim")
34+
35+
#' @export
36+
ylim.gsplot <- function(object, side=NULL){
37+
if (!is.null(side))
38+
views <- object[views_with_side(views(object), side)]
39+
else
40+
views <- views(object)
41+
names = unname(sapply(views, function(x) paste0('side.',x$window$side[2])))
42+
unique(lapply(views, function(x) x$window$ylim)) %>%
43+
setNames(unique(names))
44+
}
45+
46+
#' log for gsplot
47+
#'
48+
#' get the log for views in gsplot object
49+
#'
50+
#' @name logged
51+
#' @param object a gsplot object
52+
#' @param side which side(s) to use (returns logical)
53+
#' @export
54+
logged <- function(object, side) UseMethod('logged')
55+
56+
#' @rdname logged
57+
#' @export
58+
logged.gsplot <- function(object, side=NULL){
59+
60+
is.logged <- function(window, side){
61+
log = window$log
62+
if (side %% 2 == 0){ # is y
63+
grepl(pattern = 'y',log)
64+
} else {
65+
grepl(pattern = 'x',log)
66+
}
67+
}
68+
if (!is.null(side)){
69+
sapply(side, function(x) is.logged(object[[views_with_side(views(object), side=x)[1]]]$window, x))
70+
} else {
71+
names = unname(sapply(views(object), function(x) paste0('side.',paste(x$window$side[1:2],collapse='.'))))
72+
lapply(views(object), function(x) x$window$log) %>%
73+
setNames(names)
74+
}
75+
}

R/override.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#' @importFrom utils getFromNamespace
22
#' @importFrom stats setNames
33
#' @importFrom methods existsFunction
4+
45
override <- function(package, name, object, ...) {
56
if(!missing(object) && class(object) == "gsplot") {
67
fun <- function(object, ...) {

R/par.R

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,12 @@ par <- function(object, ...) {
2727

2828

2929
par.gsplot <- function(object, ...){
30-
current_list <- config("par")
3130
arguments <- list(...)
31+
32+
if (length(arguments)==0 && !is.null(object$par))
33+
return(object$par)
34+
current_list <- config("par")
35+
3236

3337
# // only add config list items if they aren't in ..., and aren't already set in par (i.e., don't reset them)
3438
indicesToAdd <- !(names(current_list) %in% names(arguments)) & !(names(current_list) %in% names(object[['par']]))

man/logged.Rd

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
% Generated by roxygen2 (4.1.1): do not edit by hand
2+
% Please edit documentation in R/access-gsplot.R
3+
\name{logged}
4+
\alias{logged}
5+
\alias{logged.gsplot}
6+
\title{log for gsplot}
7+
\usage{
8+
logged(object, side)
9+
10+
\method{logged}{gsplot}(object, side = NULL)
11+
}
12+
\arguments{
13+
\item{object}{a gsplot object}
14+
15+
\item{side}{which side(s) to use (returns logical)}
16+
}
17+
\description{
18+
get the log for views in gsplot object
19+
}
20+

man/xlim.Rd

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
% Generated by roxygen2 (4.1.1): do not edit by hand
2+
% Please edit documentation in R/access-gsplot.R
3+
\name{xlim}
4+
\alias{xlim}
5+
\title{xlim for gsplot}
6+
\usage{
7+
xlim(object, side)
8+
}
9+
\arguments{
10+
\item{object}{a gsplot object}
11+
12+
\item{side}{which side(s) to use}
13+
}
14+
\description{
15+
get the xlim for views in gsplot object
16+
}
17+

man/ylim.Rd

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
% Generated by roxygen2 (4.1.1): do not edit by hand
2+
% Please edit documentation in R/access-gsplot.R
3+
\name{ylim}
4+
\alias{ylim}
5+
\title{ylim for gsplot}
6+
\usage{
7+
ylim(object, side)
8+
}
9+
\arguments{
10+
\item{object}{a gsplot object}
11+
12+
\item{side}{which side(s) to use}
13+
}
14+
\description{
15+
get the ylim for views in gsplot object
16+
}
17+
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
context("test get xlim for gsplot object")
2+
test_that("xlim for single axis", {
3+
4+
usrDef <- gsplot(mar=c(4,4,4,4), xaxs='r', yaxs='r') %>%
5+
points(x=1, y=2, side=c(3,2), legend.name="Points 1", cex=3, xlab='cat')
6+
7+
expect_equal(xlim(usrDef)[[1]], c(1,1))
8+
9+
usrDef <- points(usrDef,x=3:10,y=4:11, side=c(3,2))
10+
11+
expect_equal(xlim(usrDef)[[1]], c(1,10))
12+
13+
})
14+
15+
test_that("xlim for dual axis", {
16+
17+
usrDef <- gsplot(mar=c(4,4,4,4), xaxs='r', yaxs='r') %>%
18+
points(x=1, y=2, side=c(3,2), legend.name="Points 1", cex=3, xlab='cat') %>%
19+
points(x=3:10,y=4:11, side=c(1,2))
20+
21+
expect_equal(xlim(usrDef)[[1]], c(1,1))
22+
expect_equal(xlim(usrDef)[[2]], c(3,10))
23+
24+
})
25+
26+
test_that("xlim for string input", {
27+
28+
usrDef <- gsplot(mar=c(4,4,4,4), xaxs='r', yaxs='r') %>%
29+
points(x=1, y=2, side=c(3,2), legend.name="Points 1", cex=3, xlab='cat') %>%
30+
points(x=3:10,y=4:11, side=c(1,2))
31+
32+
expect_equal(xlim(usrDef)[['side.3']], c(1,1))
33+
expect_equal(xlim(usrDef, side = 3)[[1]], c(1,1))
34+
expect_equal(xlim(usrDef, side = 1)[[1]], c(3,10))
35+
36+
})
37+
38+
context("test get par for gsplot object")
39+
40+
test_that("par for simple object",{
41+
expect_equal(par(gsplot(mar=c(4,4,4,4), xaxs='r', yaxs='r'))$xaxs,'r')
42+
expect_is(par(gsplot(mar=c(4,4,4,4), xaxs='r', yaxs='r')), 'list')
43+
})
44+
45+
context("test get logged for gsplot object")
46+
47+
test_that("logged for simple object",{
48+
usrDef <- gsplot(mar=c(4,4,4,4), xaxs='r', yaxs='r') %>%
49+
points(x=1, y=2, side=c(3,2), legend.name="Points 1", cex=3, xlab='cat') %>%
50+
points(x=3:10,y=4:11, side=c(1,2))
51+
expect_equal(logged(usrDef)[[1]],"")
52+
expect_equal(logged(usrDef)[[2]],"")
53+
54+
usrDef <- lines(usrDef,1:2,4:5, log='xy')
55+
expect_equal(logged(usrDef)[[1]],"")
56+
expect_equal(logged(usrDef)[[2]],"xy")
57+
58+
})
59+
60+
test_that("logged side extractor ",{
61+
usrDef <- gsplot(mar=c(4,4,4,4), xaxs='r', yaxs='r') %>%
62+
points(x=1, y=2, side=c(3,2), legend.name="Points 1", cex=3, xlab='cat',log='y') %>%
63+
points(x=3:10,y=4:11, side=c(1,2), log='xy')
64+
expect_true(logged(usrDef, side=1))
65+
expect_false(logged(usrDef, side=3))
66+
67+
dual = logged(usrDef, side=c(1,2))
68+
expect_equal(length(dual), 2)
69+
expect_true(all(dual))
70+
})

0 commit comments

Comments
 (0)