Skip to content

Commit

Permalink
Merge pull request #28 from uclahs-cds/stefaneng-s3-print-26
Browse files Browse the repository at this point in the history
Add print/plot S3 methods for VennDiagram
  • Loading branch information
dan-knight authored Aug 23, 2023
2 parents 81b03a9 + 2b56e43 commit 509fd27
Show file tree
Hide file tree
Showing 10 changed files with 38 additions and 6 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Package: VennDiagram
Version: 1.7.6
Version: 1.8.0
Type: Package
Title: Generate High-Resolution Venn and Euler Plots
Date: 2023-08-23
Expand Down
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,5 @@ importFrom("methods", "is")
import(grid,
futile.logger
)
S3method(print, VennDiagram)
S3method(plot, VennDiagram)
7 changes: 4 additions & 3 deletions NEWS
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
VennDiagram 1.7.6 2023-08-23 (Dan Knight)
VennDiagram 1.8.0 2023-08-23 (Stefan Eng, Dan Knight)
---------------------------------------------------------------------------------------------------
MINOR UPDATE
* Update CICD-base workflow
MINOR UPDATES
* Implemented S3 print/plot methods for VennDiagram class
* Update CICD workflows

VennDiagram 1.7.5 2023-02-28 (Stefan Eng)
---------------------------------------------------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions R/draw.pairwise.venn.R
Original file line number Diff line number Diff line change
Expand Up @@ -1214,5 +1214,6 @@ stop('Invalid value for "cat.default.pos", should be either "outer" or "text"');
grob.list <- adjust.venn(rotate.venn.degrees(grob.list, rotation.degree, rotation.centre[1], rotation.centre[2]), ...);
# draw the plot before returning the grob if specified
if (ind) { grid.draw(grob.list); }
class(grob.list) <- c('VennDiagram', class(grob.list));
return(grob.list);
}
1 change: 1 addition & 0 deletions R/draw.quad.venn.R
Original file line number Diff line number Diff line change
Expand Up @@ -356,5 +356,6 @@ stop(paste0('Unknown value passed to cex.prop: ', cex.prop))

# draw diagram before returning gList is specified by user
if (ind) { grid.draw(grob.list); }
class(grob.list) <- c('VennDiagram', class(grob.list));
return(grob.list);
}
1 change: 1 addition & 0 deletions R/draw.quintuple.venn.R
Original file line number Diff line number Diff line change
Expand Up @@ -448,5 +448,6 @@ stop(paste0('Unknown value passed to cex.prop: ', cex.prop))
# adjust grob.list to fit and return grob.list
grob.list <- VennDiagram::adjust.venn(VennDiagram::rotate.venn.degrees(grob.list, rotation.degree, rotation.centre[1], rotation.centre[2]), ...);
if (ind) { grid.draw(grob.list); }
class(grob.list) <- c('VennDiagram', class(grob.list));
return(grob.list);
}
1 change: 1 addition & 0 deletions R/draw.single.venn.R
Original file line number Diff line number Diff line change
Expand Up @@ -157,5 +157,6 @@ stop('Unexpected parameter format for "cat.just"'); }
grob.list <- gList(grob.list, tmp);
grob.list <- VennDiagram::adjust.venn(VennDiagram::rotate.venn.degrees(grob.list, rotation.degree, rotation.centre[1], rotation.centre[2]), ...);
if (ind) { grid.draw(grob.list); }
class(grob.list) <- c('VennDiagram', class(grob.list));
return(grob.list);
}
3 changes: 2 additions & 1 deletion R/draw.sp.case.R
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ stop('Invalid cat.default.pos setting');
if (reverse) {
return(VennDiagram::flip.venn(grob.list, axis = 'v'));
}
}
}
class(grob.list) <- c('VennDiagram', class(grob.list));
return(grob.list);
}
1 change: 1 addition & 0 deletions R/draw.triple.venn.R
Original file line number Diff line number Diff line change
Expand Up @@ -590,5 +590,6 @@ stop('Invalid setting of cat.default.pos');

# draw diagram before returning gList is specified by user
if (ind) { grid.draw(grob.list); }
class(grob.list) <- c('VennDiagram', class(grob.list));
return(grob.list);
}
25 changes: 24 additions & 1 deletion R/venn.diagram.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,26 @@
# If publications result from research using this SOFTWARE, we ask that the Ontario Institute for Cancer Research be acknowledged and/or
# credit be given to OICR scientists, as scientifically appropriate.

print.VennDiagram <- plot.VennDiagram <- function(x, newpage = is.null(vp), vp = NULL, ...) {
if (newpage)
grid.newpage();
grDevices::recordGraphics(
expr = requireNamespace("VennDiagram", quietly = TRUE),
list = list(),
env = getNamespace("VennDiagram")
);
if (is.null(vp)) {
grid.draw(x);
} else {
if (is.character(vp))
seekViewport(vp)
else pushViewport(vp);
grid.draw(x);
upViewport();
}
invisible(x);
}

### UMBRELLA FUNCTION TO DRAW VENN DIAGRAMS #######################################################
venn.diagram <- function(
x,
Expand Down Expand Up @@ -501,7 +521,10 @@ stop('You have misspelled your "imagetype", please try again');
# return a success code
return(1);
}


if (! 'VennDiagram' %in% class(grob.list)) {
class(grob.list) <- c('VennDiagram', class(grob.list));
}
# if file creation was not requested return the plotting object
return(grob.list);
}
Expand Down

0 comments on commit 509fd27

Please sign in to comment.