Skip to content

Commit

Permalink
Merge pull request #14 from USCCANA/graph-not-edgelist [skip ci]
Browse files Browse the repository at this point in the history
Fixing GHA and adding Porter as coauth
  • Loading branch information
gvegayon committed Jul 26, 2023
2 parents 3a5fda4 + 308c76e commit ce490b4
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 60 deletions.
6 changes: 4 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
Package: netplot
Title: Beautiful Graph Drawing
Version: 0.2-0
Authors@R: person("George", "Vega Yon", email = "g.vegayon@gmail.com", role = c("aut", "cre"),
comment = c(ORCID = "0000-0002-3171-0844")
Authors@R: c(
person("George", "Vega Yon", email = "g.vegayon@gmail.com", role = c("aut", "cre"),
comment = c(ORCID = "0000-0002-3171-0844")),
person("Porter", "Bischoff", email = "portergbischoff@gmail.com", role = c("aut"), comment = c(ORCID = "0009-0004-6742-6281"))
)
Description: A graph visualization engine that puts an emphasis on
aesthetics at the same time of providing default parameters that yield
Expand Down
24 changes: 0 additions & 24 deletions R/coloring-nodes.R

This file was deleted.

14 changes: 7 additions & 7 deletions R/gpar.R
Original file line number Diff line number Diff line change
Expand Up @@ -191,22 +191,22 @@ set_vertex_gpar <- function(x, element, idx, ...) {
dots <- list(...)

# Step 1: Check if col/fill is a formula
if(is.formula(dots$col) || is.formula(dots$fill)) {
if(inherits(dots$col, "formula") || inherits(dots$fill, "formula")) {

# Step 2: Extract RHS of formula using terms()
if(!missing(dots$col)) {
if (inherits(dots$col, "formula")) {
color_var <- attr(terms(dots$col), "term.labels")
}
if(!missing(dots$fill)) {
if (inherits(dots$fill, "formula")) {
fill_var <- attr(terms(dots$fill), "term.labels")
}

# Step 3: Call color_nodes() with graph and attribute
if(!missing(dots$col)) {
dots$col <- color_nodes(x, color_var)
if (inherits(dots$col, "formula")) {
dots$col <- color_nodes(x$.graph, color_var)
}
if(!missing(dots$fill)) {
dots$fill <- color_nodes(x, fill_var)
if (inherits(dots$fill, "formula")) {
dots$fill <- color_nodes(x$.graph, fill_var)
}

}
Expand Down
46 changes: 27 additions & 19 deletions R/netplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ NULL

#' @export
#' @rdname nplot
nplot <- function(...) UseMethod("nplot")
nplot <- function(x, ..., edgelist) UseMethod("nplot")

#' @export
#' @rdname nplot
Expand All @@ -98,13 +98,15 @@ nplot.igraph <- function(
vertex.label = igraph::vertex_attr(x, "name"),
edge.width = igraph::edge_attr(x, "weight"),
skip.arrows = !igraph::is_directed(x),
...
...,
edgelist = NULL
) {

if (!length(edge.width))
edge.width <- 1L

nplot.default(
x = x,
edgelist = igraph::as_edgelist(x, names = FALSE),
layout = layout,
vertex.size = vertex.size,
Expand All @@ -126,28 +128,31 @@ nplot.network <- function(
vertex.size = sna::degree(x, cmode="indegree"),
vertex.label = network::get.vertex.attribute(x, "vertex.names"),
skip.arrows = !network::is.directed(x),
...
...,
edgelist = NULL
) {

nplot.default(
edgelist = network::as.edgelist(x),
x = x,
layout = layout,
vertex.size = vertex.size,
vertex.label = vertex.label,
skip.arrows = skip.arrows,
...
...,
edgelist = network::as.edgelist(x)
)

}

#' @export
#' @rdname nplot
#' @importFrom igraph graph_from_adjacency_matrix
nplot.matrix <- function(x, ...) {
nplot.matrix <- function(x, ..., edgelist = NULL) {

nplot.igraph(
igraph::graph_from_adjacency_matrix(x),
...
x = igraph::graph_from_adjacency_matrix(x),
...,
edgelist = NULL
)

}
Expand Down Expand Up @@ -218,7 +223,7 @@ netplot_theme <- (function() {
#' of the figure.
#' @seealso [nplot_base]
nplot.default <- function(
edgelist,
x,
layout,
vertex.size = 1,
bg.col = "transparent",
Expand Down Expand Up @@ -248,10 +253,10 @@ nplot.default <- function(
skip.arrows = skip.edges,
add = FALSE,
zero.margins = TRUE,
...
...,
edgelist
) {


# listing objects
netenv <- environment()

Expand All @@ -265,6 +270,7 @@ nplot.default <- function(

netenv$N <- nrow(layout)
netenv$M <- nrow(edgelist)
netenv$graph_class <- class(x)

# Sampling edges -------------------------------------------------------------
if (sample.edges < 1) {
Expand Down Expand Up @@ -441,14 +447,16 @@ nplot.default <- function(
)

ans <- grid::gTree(
children = grid::gList(background, ans),
name = netplot_name$new(),
.xlim = netenv$xlim,
.ylim = netenv$ylim,
.layout = netenv$layout,
.edgelist = netenv$edgelist,
.N = netenv$N,
.M = netenv$M
children = grid::gList(background, ans),
name = netplot_name$new(),
.xlim = netenv$xlim,
.ylim = netenv$ylim,
.layout = netenv$layout,
.edgelist = netenv$edgelist,
.N = netenv$N,
.M = netenv$M,
.graph = netenv$x,
.graph_class = netenv$graph_class
)

class(ans) <- c("netplot", class(ans))
Expand Down
19 changes: 11 additions & 8 deletions man/nplot.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit ce490b4

Please sign in to comment.