Skip to content
Merged
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
5 changes: 5 additions & 0 deletions R/plot.R
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,11 @@ plot.igraph <- function(
}

layout <- i.postprocess.layout(params("plot", "layout"))
if (nrow(layout) != vc) {
cli::cli_abort(c(
"The layout has {nrow(layout)} rows, but the graph has {vc} vertices.",
"i" = "It is recommended to store the layout as x and y vertex attributes and not as a matrix graph attribute."))
}
margin <- params("plot", "margin")
margin <- rep(margin, length.out = 4)
rescale <- params("plot", "rescale")
Expand Down
9 changes: 9 additions & 0 deletions tests/testthat/_snaps/plot.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# layout as graph attribute error works

Code
plot(g)
Condition
Error in `plot()`:
! The layout has 5 rows, but the graph has 10 vertices.
i It is recommended to store the layout as x and y vertex attributes and not as a matrix graph attribute.

9 changes: 9 additions & 0 deletions tests/testthat/test-plot.R
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,15 @@ test_that("Edges stop at outside of rectangle node", {
vdiffr::expect_doppelganger("rectangle-edges", rectangle_edges)
})


test_that("layout as graph attribute error works", {
g <- make_full_graph(10)
g$layout <- layout_in_circle(g)[1:5, ]
expect_snapshot(error = TRUE, {
plot(g)
})
})

test_that("Multi loops are arranged correctly", {
skip_if_not_installed("vdiffr")

Expand Down
Loading