Skip to content

Commit

Permalink
Figures with legends no longer drawn twice
Browse files Browse the repository at this point in the history
  • Loading branch information
gvegayon committed Feb 16, 2024
1 parent 8b69d99 commit d1f84b1
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

* Unvalid arguments passed to `nplot()` now raise an error.

* Figures with legends are not drawn twice.


# netplot 0.2-0

Expand Down
15 changes: 8 additions & 7 deletions R/netplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -615,20 +615,21 @@ nplot.default <- function(
#' @param y,... Ignored
print.netplot <- function(x, y = NULL, newpage = TRUE, legend = TRUE, ...) {

# If legend, then we avoid drawing twice
if (length(x$.legend_vertex_fill) && legend) {

color_nodes_legend(x)
return(invisible(x))

}

# Drawing
if (newpage) {
grid::grid.newpage()
}

grid::grid.draw(x)

# If legend
if (legend) {

color_nodes_legend(x)

}

# Storing the value
.Last.netplot$set(x)

Expand Down
2 changes: 1 addition & 1 deletion R/nplot_legend.R
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ nplot_legend <- function(
gf <- grid::packGrob(grid::frameGrob(), g)

# Adding the legend
legend.args <- do.call(
legend.args <- do.call(
grid::legendGrob,
c(list(labels = labels, pch = pch, gp = gp), list(...))
)
Expand Down

0 comments on commit d1f84b1

Please sign in to comment.