Skip to content

Fix edge.width not applied to drawn line widths in nplot#18

Merged
gvegayon merged 11 commits into
masterfrom
copilot/fix-edge-width-issue
Jul 22, 2026
Merged

Fix edge.width not applied to drawn line widths in nplot#18
gvegayon merged 11 commits into
masterfrom
copilot/fix-edge-width-issue

Conversation

Copilot AI commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Fixes #17 ("edge width is not used"). Edge widths were drawn uniformly regardless of edge weight for network objects, and this PR makes edge.width behave consistently across methods, plus fixes a couple of related issues found along the way.

Changes

  • R/netplot.Rnplot.network() now defaults edge.width to the "weight" edge attribute (matching nplot.igraph()), falling back to 1 when absent. Previously network objects ignored edge weights entirely and drew all edges at a single width — the actual cause of edge width is not used #17.
  • R/netplot.R / R/netplot_base.R / R/geometry.Redge.width.range, vertex.size.range, and vertex.label.range now accept NULL to suppress rescaling and use the supplied values as-is (rescale_size() returns its input unchanged for a NULL range).
  • R/netplot.R — After color post-processing, edge.width is explicitly re-applied via set_edge_gpar(lwd = ...) for the "line" and "arrow" elements. This is defensive: grid::editGrob() merges graphical parameters, so the earlier set_edge_gpar(col = ...) did not actually drop lwd, but re-applying keeps the drawn widths robust against future changes to the post-processing order.
  • R/grob_vertex.R — Fixed vertex.rot, which was passed through as.integer() and so silently ignored fractional (radian) rotations (e.g. pi/4 became 0). Shape resolution was factored into resolve_vertex_shape(), and the named "square" orientation was corrected (pi/2pi/4).
  • R/netplot.R / R/netplot_base.Redge.line.lty is validated to be length 1 or one value per plotted edge, and edge parameters (including edge.line.lty) are subset correctly when sample.edges drops edges.
  • vignettes/examples.Rmd — Added an "Edge width" section demonstrating edge.width, edge.width.range (including NULL), and post-hoc set_edge_gpar(); updated the vertex-size example to show vertex.size.range = NULL.
  • inst/tinytest/test_netplot.R — Added tests covering edge-width mapping and NULL ranges, vertex.rot rotation, named-shape orientation, edge.line.lty validation and sampling, and the nplot.network default.
  • NEWS.md — Changelog entries for the fixes.
  • Docs (R/netplot.R, man/*) — Clarified edge.width, edge.width.range, and vertex.size.range behavior, including the NULL option and the range-mapping semantics.
  • Dev environment — Added a dev container configuration and AGENTS.md.

Copilot AI linked an issue Jun 30, 2026 that may be closed by this pull request
Copilot AI changed the title [WIP] Fix issue with edge width not being used in nplot function Fix edge.width not applied to drawn line widths in nplot Jun 30, 2026
Copilot AI requested a review from gvegayon June 30, 2026 01:15
@gvegayon
gvegayon marked this pull request as ready for review June 30, 2026 01:37
gvegayon and others added 7 commits June 30, 2026 20:21
Describe the actual fix (nplot.network now uses the weight attribute) and
the related changes (NULL ranges, vertex.rot radian fix, edge.line.lty
validation) instead of the inaccurate gpar-clobbering rationale.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes inconsistent handling of edge.width in nplot()—especially for network objects—so edge weights can correctly drive drawn line widths, and aligns scaling/rotation behaviors across the grid and base plotting implementations.

Changes:

  • Make edge.width default to the "weight" edge attribute for network objects (and ensure widths are applied to the edge grobs after color post-processing).
  • Allow edge.width.range, vertex.size.range, and vertex.label.range to be NULL to suppress rescaling and use values as-is.
  • Fix vertex rotation handling (preserve fractional radians) and correct named "square" orientation; add/expand examples, tests, and documentation.

Reviewed changes

Copilot reviewed 17 out of 19 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
R/netplot.R Updates nplot.network() defaults, adds NULL-range behavior, validates edge.line.lty, and defensively re-applies edge lwd after color edits.
R/netplot_base.R Subsets edge parameters when sample.edges drops edges; supports NULL edge.width.range; applies vertex rotation to frame geometry.
R/grob_vertex.R Fixes vertex rotation truncation; factors shape resolution into resolve_vertex_shape(); corrects "square" rotation.
R/geometry.R Makes rescale_size() return input unchanged when rel = NULL.
inst/tinytest/test_netplot.R Adds regression tests for edge width mapping, NULL ranges, vertex rotation, shape orientation, edge.line.lty validation, and sampling behavior.
vignettes/examples.Rmd Adds an “Edge width” section and updates node-scaling example to demonstrate vertex.size.range = NULL.
NEWS.md Documents the edge-width fix, NULL range behavior, vertex rotation fix, and edge.line.lty validation/sampling.
man/nplot.Rd Updates parameter docs to describe new edge.width / edge.width.range semantics and vertex.size.range = NULL.
man/nplot_base.Rd Mirrors updated parameter documentation for the base plotting variant.
Makefile Simplifies developer targets and switches to devtools::document(), devtools::check(), and devtools::install().
DESCRIPTION Updates RoxygenNote.
AGENTS.md Adds contributor/development workflow notes for agents and tooling.
.Rbuildignore Excludes AGENTS.md and devcontainer/editor configuration from builds.
.github/workflows/ci.yml Updates GitHub Actions versions used in CI.
.github/workflows/website.yml Updates GitHub Actions versions used for the website workflow.
.devcontainer/devcontainer.json Adds a devcontainer configuration for local development.
.devcontainer/devcontainer-lock.json Locks devcontainer feature versions/digests.
.devcontainer/Containerfile Defines the devcontainer image setup (R + Quarto + dependencies).
.devcontainer/.vscode/settings.json Adds VS Code settings for the devcontainer environment.
Files not reviewed (2)
  • man/nplot.Rd: Generated file
  • man/nplot_base.Rd: Generated file
Comments suppressed due to low confidence (1)

inst/tinytest/test_netplot.R:200

  • Using grDevices::pdf(NULL) will write an Rplots.pdf file in the working directory. Prefer a temporary file to avoid leaving artifacts after tests run.
  grDevices::pdf(NULL)
  expect_error(
    nplot_base(x, layout = l, skip.arrows = TRUE,
               edge.line.lty = edge_ltys[seq_len(2)]),
    "edge.line.lty",

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread R/netplot_base.R
Comment on lines +122 to +132
for (epar in edge_par) {
if (is.null(get(epar)))
next

if (is.matrix(get(epar)) || is.data.frame(get(epar))) {
if (nrow(get(epar)) == M)
assign(epar, get(epar)[sample.edges, , drop = FALSE])
} else if (length(get(epar)) == M) {
assign(epar, get(epar)[sample.edges])
}
}
Comment thread inst/tinytest/test_netplot.R Outdated
Comment on lines +182 to +190
grDevices::pdf(NULL)
set.seed(1)
base_sample_lty <- tryCatch(
nplot_base(x_sample, layout = l_sample, skip.arrows = TRUE,
sample.edges = .4, edge.line.lty = sampled_ltys),
error = function(e) e
)
grDevices::dev.off()

gvegayon and others added 2 commits July 22, 2026 16:57
- netplot_base(): cache each edge parameter once in the sample.edges block
  instead of calling get() repeatedly, so a (lazily-evaluated) argument is
  forced a single time before inspecting/subsetting it.
- tests: point the throwaway graphics device at a tempfile instead of
  pdf(NULL) to make it explicit that no artifact is written.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown

Thank you for your contribution @gvegayon 🚀! The pkgdown site preview is ready for review 👉 Download here 👈!
(The artifact expires on 2026-10-20T23:08:15Z. You can re-generate it by re-running the workflow here.)

@gvegayon
gvegayon merged commit 2846e8a into master Jul 22, 2026
9 checks passed
@gvegayon
gvegayon deleted the copilot/fix-edge-width-issue branch July 22, 2026 23:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

edge width is not used

3 participants