From 937a2d9fd56d69319ea3959125dae725e6ec5c1a Mon Sep 17 00:00:00 2001 From: Akira Hayashi Date: Wed, 30 Oct 2024 23:57:02 +0900 Subject: [PATCH] Show circular reference in red --- R/VisGraphAuto.R | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/R/VisGraphAuto.R b/R/VisGraphAuto.R index d934bfa..1702fa8 100644 --- a/R/VisGraphAuto.R +++ b/R/VisGraphAuto.R @@ -261,7 +261,30 @@ plot.dependenciesGraphs <- function(object, block = FALSE, width = NULL, height visPhysics(solver = "repulsion", stabilization = list(enabled = FALSE, iterations = 5000, onlyDynamicEdges = FALSE)) } +plot.dependenciesGraphs <- function(object, block = FALSE, width = NULL, height = NULL) { + # Show circular reference in red + red_if_circular <- function(edges) { + from_to <- paste(edges$from, edges$to) + to_from <- paste(edges$to, edges$from) + circular <- from_to %in% to_from + ifelse(circular, "red", "#848484") + } + object[[2]]$color <- red_if_circular(object[[2]]) + + visNetwork(object[[1]], object[[2]], width = width, height = height) %>% + visEdges(arrows = "from") %>% + visOptions(highlightNearest = TRUE, nodesIdSelection = TRUE) %>% + visInteraction(dragNodes = !block) %>% + visPhysics( + solver = "repulsion", + stabilization = list( + enabled = FALSE, + iterations = 5000, + onlyDynamicEdges = FALSE + ) + ) +} #' Launch shiny app #'