Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,6 @@ netplot\._.*\.tar\.gz
^Rplots\.pdf$
^doc$
^Meta$
^AGENTS\.md$
^\.devcontainer$
^\.vscode$
4 changes: 4 additions & 0 deletions .devcontainer/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"r.plot.useHttpgd": true,
"r.alwaysUseActiveTerminal": true
}
19 changes: 19 additions & 0 deletions .devcontainer/Containerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
FROM ghcr.io/rocker-org/devcontainer/r-ver:4.5

# Architecture-specific variable (built in Docker BuildKit)
ARG TARGETARCH

# Install quarto-cli and the orange-book extension
RUN wget https://github.com/quarto-dev/quarto-cli/releases/download/v1.9.35/quarto-1.9.35-linux-${TARGETARCH}.deb && \
dpkg -i quarto-1.9.35-linux-${TARGETARCH}.deb && \
rm quarto-1.9.35-linux-${TARGETARCH}.deb

# Adding R packages
RUN install2.r --error knitr rmarkdown markdown igraphdata intergraph \
ggraph gridGraphics ggplot2 gridExtra gridBase magrittr tinytest \
sna igraph network

RUN apt-get update && apt-get install --no-install-recommends -y \
libglpk-dev

CMD ["bash"]
9 changes: 9 additions & 0 deletions .devcontainer/devcontainer-lock.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"features": {
"ghcr.io/devcontainers/features/github-cli:1": {
"version": "1.1.0",
"resolved": "ghcr.io/devcontainers/features/github-cli@sha256:d22f50b70ed75339b4eed1ba9ecde3a1791f90e88d37936517e3bace0bbad671",
"integrity": "sha256:d22f50b70ed75339b4eed1ba9ecde3a1791f90e88d37936517e3bace0bbad671"
}
}
}
42 changes: 42 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers/templates/tree/main/src/cpp
{
"name": "netplot",
"build": {
"dockerfile": "Containerfile"
},
"customizations": {
"vscode": {
"extensions": [
"reditorsupport.r",
"rdebugger.r-debugger",
"quarto.quarto",
"tianyishi.rmarkdown",
"github.vscode-github-actions",
"ms-vscode.live-server"
]
}
},
"mounts": [
// Mount the .vscode configuration into the container
"source=${localWorkspaceFolder}/.devcontainer/.vscode,target=/workspaces/${localWorkspaceFolderBasename}/.vscode,type=bind,consistency=cached"
],
// Features to add to the dev container. More info: https://containers.dev/features.
"features": {
"ghcr.io/devcontainers/features/github-cli:1": {
"version": "1.1.0"
}
},

// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],

// Use 'postCreateCommand' to run commands after the container is created.
// "postCreateCommand": "gcc -v",

// Configure tool-specific properties.
// "customizations": {},

// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
"remoteUser": "root"
}
11 changes: 11 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# What is this project about

This is an R package that uses the `grid` package to create network plots. The package is focused on aesthetics and tries to provide an interface that has a lower footprint in dependencies than other packages, leveraging existing base R packages.

## Development workflow and preferences

- We follow the tinyverse style for code (so minimal dependencies, but still using `roxygen2` for documentation).

- For testing the package, we use `tinytest`.

- For checking the R package, we use `devtools::check()`, and for documenting we call `devtools::document()`.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Depends:
License: MIT + file LICENSE
Encoding: UTF-8
LazyData: true
RoxygenNote: 7.3.1
RoxygenNote: 7.3.3
Roxygen: list(markdown = TRUE)
Imports:
graphics,
Expand Down
56 changes: 11 additions & 45 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,50 +1,16 @@
VERSION:=$(shell Rscript -e 'x<-readLines("DESCRIPTION");cat(gsub(".+[:]\\s*", "", x[grepl("^Vers", x)]))')
PKGNAME:=$(shell Rscript -e 'x<-readLines("DESCRIPTION");cat(gsub(".+[:]\\s*", "", x[grepl("^Package", x)]))')
README.md: README.qmd
quarto render README.qmd

install: build
cd ../ && \
R CMD INSTALL $(PKGNAME)_$(VERSION).tar.gz

$(PKGNAME)_$(VERSION).tar.gz:
cd ../ && R CMD build $(PKGNAME)/
.PHONY: build check install checkfull checkv clean man docker checkd

build: $(PKGNAME)_$(VERSION).tar.gz
build: docs
R CMD build .

inst/NEWS: NEWS.md
Rscript -e "rmarkdown::pandoc_convert('NEWS.md', 'plain', output='inst/NEWS')"&& \
head -n 80 inst/NEWS
check: docs
Rscript -e "devtools::check()"

README.md: README.Rmd
Rscript -e 'rmarkdown::render("README.Rmd")'
install: docs
Rscript -e "devtools::install()"

.PHONY: checfull checkv clean

check: $(PKGNAME)_$(VERSION).tar.gz
R CMD check --no-vignettes --no-manual $(PKGNAME)_$(VERSION).tar.gz

checkfull: R/*.R inst/NEWS README.md
R CMD build . \&&
R CMD check --as-cran $(PKGNAME)_$(VERSION).tar.gz

checkv: $(PKGNAME)_$(VERSION).tar.gz
R CMD check --as-cran --use-valgrind $(PKGNAME)_$(VERSION).tar.gz

clean:
cd ../ && \
rm -rf $(PKGNAME).Rcheck $(PKGNAME)_$(VERSION).tar.gz

.PHONY: man docker
man: R/*
Rscript --vanilla -e 'roxygen2::roxygenize()'

docker:
docker run -v$(pwd):/pkg/ -w/pkg --rm -i uscbiostats/fmcmc:latest make check

checkd:
apt update && \
tlmgr install amsmath && \
install2.r igraph gridGraphics gridBase gridExtra magrittr tinytest sna \
ggraph rmarkdown knitr intergraph igraphdata pkgdown markdown && \
apt install libglpk-dev --no-install-recommends -y && \
R CMD build . && \
R CMD check --no-manual $(PKGNAME)_$(VERSION).tar.gz
docs:
Rscript -e "devtools::document()"
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# netplot 0.3-0

* `edge.width` now correctly reflected in the drawn line widths. Previously,
the width was computed but not consistently applied via the graphical
parameters of each edge grob. Closes #17.

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

* Figures with legends are not drawn twice.
Expand Down
5 changes: 4 additions & 1 deletion R/geometry.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@
#' @param size Numeric vector. Size of the node (radious).
#' @param rel Numeric vector of length 3. Relative size for the minimum and maximum
#' of the plot, and curvature of the scale. The third number is used as `size^rel[3]`.
#' If `NULL`, scaling is suppressed.
#'
#' @details
#' This function is to be called after [plot.new], as it takes the parameter `usr`
#' from the
#' @noRd
rescale_size <- function(size, rel=c(.01, .05, 1)) {

if (is.null(rel))
return(size)

# Checking the rel size
if (length(rel) == 2)
rel <- c(rel, 1)
Expand Down Expand Up @@ -204,4 +208,3 @@ map_attribute_to_shape <- function(x) {
names(sides_lookup)[as.numeric(factor(x))]

}

60 changes: 34 additions & 26 deletions R/grob_vertex.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
sides_lookup <- list(
line = list(sides = 2, rot = 0), # 1
triangle = list(sides = 3, rot = 0), # 2
square = list(sides = 4, rot = pi/2), # 3
square = list(sides = 4, rot = pi/4), # 3
diamond = list(sides = 4, rot = 0), # 4
pentagon = list(sides = 5, rot = 0), # 5
hexagon = list(sides = 6, rot = 0), # 6
Expand All @@ -10,6 +10,31 @@
circle = list(sides = 25, rot = 0) # 9
)

resolve_vertex_shape <- function(nsides, rot) {

if (!is.numeric(nsides) & !is.character(nsides)) {
stop("vertex.nsides must be numeric or character")
}

rot <- as.numeric(rot)

if (is.character(nsides)) {

shape <- nsides

if (shape %in% names(sides_lookup)) {
info <- sides_lookup[[shape]]
return(list(sides = info$sides, rot = info$rot + rot))
} else {
stop("Invalid shape name: ", shape)
}

}

list(sides = nsides, rot = rot)

}

#' Functions to calculate graph polygons coordinates
#' @param netenv An object of class network environment.
#' @param v,e Integer scalars. vertex or edge index.
Expand All @@ -25,27 +50,10 @@ grob_vertex <- function(netenv, v) {
# netenv$vertex.nsides <- eval(netenv$vertex.nsides, envir = data)
# }

# Relax vertex.nsides validation
if(!is.numeric(netenv$vertex.nsides[v]) & !is.character(netenv$vertex.nsides[v])) {
stop("vertex.nsides must be numeric or character")
}

# Handle shape names
if(is.character(netenv$vertex.nsides[v])) {

shape <- netenv$vertex.nsides[v]

if(shape %in% names(sides_lookup)) {
info <- sides_lookup[[shape]]
netenv$vertex.nsides[v] <- info$sides
netenv$vertex.rot[v] <- info$rot
} else {
stop("Invalid shape name: ", shape)
}

}


vertex_shape <- resolve_vertex_shape(
nsides = netenv$vertex.nsides[v],
rot = netenv$vertex.rot[v]
)

if (netenv$skip.vertex)
return(
Expand All @@ -63,18 +71,18 @@ grob_vertex <- function(netenv, v) {
coords <- npolygon(
x = netenv$layout[v, 1],
y = netenv$layout[v, 2],
n = as.integer(netenv$vertex.nsides[v]),
n = as.integer(vertex_shape$sides),
r = netenv$vertex.size[v]*(1 - netenv$vertex.frame.prop[v]),
d = as.integer(netenv$vertex.rot[v])
d = vertex_shape$rot
)

# Frame coordinates
framecoords <- npolygon(
x = netenv$layout[v, 1],
y = netenv$layout[v, 2],
n = as.integer(netenv$vertex.nsides[v]),
n = as.integer(vertex_shape$sides),
r = netenv$vertex.size[v],
d = as.integer(netenv$vertex.rot[v])
d = vertex_shape$rot
)

# Create color palette
Expand Down
Loading
Loading