Skip to content

Commit 5517e74

Browse files
committed
Fixes #206
Plenty of improvements could be made.
1 parent 09e8bd2 commit 5517e74

File tree

4 files changed

+66
-0
lines changed

4 files changed

+66
-0
lines changed

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
S3method(gsplot,default)
44
S3method(logged,gsplot)
55
S3method(print,gsplot)
6+
S3method(summary,gsplot)
67
S3method(xlim,gsplot)
78
S3method(ylim,gsplot)
89
export("%>%")

R/gsplot-class.R

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,35 @@ gsplot.list <- function(x){
2626
class(x) <- "gsplot"
2727
invisible(x)
2828
}
29+
30+
#' Summary of gsplot object
31+
#'
32+
#' Summary information
33+
#'
34+
#' @param object list
35+
#' @param \dots additional parameters
36+
#' @export
37+
#' @examples
38+
#' gs <- gsplot() %>%
39+
#' points(1:10,1:10) %>%
40+
#' axis(side=1, at=seq(1,10,length.out=18),las=3) %>%
41+
#' axis(side=3, labels=FALSE) %>%
42+
#' grid(side=c(1,2),col="green") %>%
43+
#' grid(side=c(3,4))
44+
#' summary(gs)
45+
summary.gsplot <- function(object,...){
46+
47+
view.info <- view_info(object)
48+
cat("Summary information of plotting object:\n")
49+
cat(nrow(view.info),"views:\n")
50+
for(i in seq_len(nrow(view.info))){
51+
cat("View:",i,"\nx side:", view.info$x[i], ",y side:", view.info$y[i], "\n")
52+
cat("xlim:",as.numeric(xlim(object, side=view.info$x[i])[[1]]),",")
53+
cat("ylim:",as.numeric(ylim(object, side=view.info$y[i])[[1]]))
54+
if(view.info$log[i] != ""){
55+
cat(",log:",view.info$log[i])
56+
}
57+
cat("\n")
58+
}
59+
}
60+

man/summary.gsplot.Rd

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
% Generated by roxygen2 (4.1.1): do not edit by hand
2+
% Please edit documentation in R/gsplot-class.R
3+
\name{summary.gsplot}
4+
\alias{summary.gsplot}
5+
\title{Summary of gsplot object}
6+
\usage{
7+
\method{summary}{gsplot}(object, ...)
8+
}
9+
\arguments{
10+
\item{object}{list}
11+
12+
\item{\dots}{additional parameters}
13+
}
14+
\description{
15+
Summary information
16+
}
17+
\examples{
18+
gs <- gsplot() \%>\%
19+
points(1:10,1:10) \%>\%
20+
axis(side=1, at=seq(1,10,length.out=18),las=3) \%>\%
21+
axis(side=3, labels=FALSE) \%>\%
22+
grid(side=c(1,2),col="green") \%>\%
23+
grid(side=c(3,4))
24+
summary(gs)
25+
}
26+

tests/testthat/test-access_gsplot.R

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,10 @@ test_that("logged side extractor ",{
6868
expect_equal(length(dual), 2)
6969
expect_true(all(dual))
7070
})
71+
72+
test_that("summary ",{
73+
usrDef <- gsplot(mar=c(4,4,4,4), xaxs='r', yaxs='r') %>%
74+
points(x=1, y=2, side=c(3,2), legend.name="Points 1", cex=3, xlab='cat',log='y') %>%
75+
points(x=3:10,y=4:11, side=c(1,2), log='xy')
76+
expect_output(summary(usrDef),regexp = "2 views:")
77+
})

0 commit comments

Comments
 (0)