From e010f773df434074753f4bab9a1725ef05621405 Mon Sep 17 00:00:00 2001 From: Thomas Lin Pedersen Date: Thu, 11 Jan 2024 10:33:24 +0100 Subject: [PATCH] Fix #247 --- NEWS.md | 1 + R/tbl_graph.R | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/NEWS.md b/NEWS.md index 154afcd6..707d9d53 100644 --- a/NEWS.md +++ b/NEWS.md @@ -4,6 +4,7 @@ * `GeomEdgeTile` now uses `edge_width` instead of `edge_size` for the border * Fix a bug in `geom_edge_parallel()` when used with edge labels. Edges are now correctly offset, though label may still overlap (#227) +* Fix a bug with auto layout on undirected trees (#247) # ggraph 2.1.0 diff --git a/R/tbl_graph.R b/R/tbl_graph.R index ef320296..a0cce5f2 100644 --- a/R/tbl_graph.R +++ b/R/tbl_graph.R @@ -85,8 +85,9 @@ prepare_graph <- function(graph, layout, direction = 'out', ...) { 'circlepack', 'partition' ) - if (is_hierarchy || (layout == 'auto' && with_graph(graph, graph_is_tree() || graph_is_forest()))) { - graph <- graph_to_tree(graph, mode = direction) + graph_is_treeish <- with_graph(graph, graph_is_tree() || graph_is_forest()) + if (is_hierarchy || (layout == 'auto' && graph_is_treeish)) { + if (!graph_is_treeish) graph <- graph_to_tree(graph, mode = direction) graph <- permute(graph, match(seq_len(gorder(graph)), order(node_depth(graph, direction)))) } as_tbl_graph(graph)