Skip to content

Commit be813e4

Browse files
committed
#334 : Ensure compatibility with the next ggraph release
1 parent ecf52d7 commit be813e4

3 files changed

Lines changed: 29 additions & 11 deletions

File tree

DESCRIPTION

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ Suggests:
3838
colourpicker,
3939
sparkline,
4040
ggraph,
41+
tidygraph,
4142
flashClust
4243
VignetteBuilder: knitr,
4344
rmarkdown

NEWS

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ visNetwork 2.0.8
22
--------------------------------------------------------------------------------
33
* #325 : fix cancel manipulation
44
* #327 : fix "layout_with_sugiyama" for simple graphs
5-
5+
* #334 : Ensure compatibility with the next ggraph release
6+
67
visNetwork 2.0.7
78
--------------------------------------------------------------------------------
89
* #307 : visClusteringByGroup, add collapse on double click

R/visHclust.R

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -240,16 +240,18 @@ visHclust.hclust <- function(object, data = NULL, main = "", submain = "", foote
240240
}
241241

242242

243-
244-
245-
246243
#' Transform data from hclust to nodes and edges
247244
#'
248245
#' @noRd
246+
#'
249247
.convertHclust <- function(hcl, data, drawNames,
250248
minNodeSize, maxNodeSize)
251249
{
252-
ig <- suppressMessages(ggraph::den_to_igraph(hcl))
250+
251+
ig <- suppressMessages({
252+
tidygraph::as.igraph(tidygraph::as_tbl_graph(hcl, directed = TRUE, mode = "out"))
253+
})
254+
253255
neig <- igraph::neighborhood(ig, 150000, mode = "out")
254256
neig <- sapply(1:length(neig), function(i){
255257
neig[[i]][!neig[[i]] == i]
@@ -320,8 +322,14 @@ visHclust.hclust <- function(object, data = NULL, main = "", submain = "", foote
320322

321323
dta$nodes$circular <- NULL
322324
dta$edges$circular <- NULL
325+
dta$nodes$height <- NULL
326+
327+
tmp_layout <- suppressMessages(ggraph::create_layout(hcl, "dendrogram"))
323328

324-
dta$nodes$label <- suppressMessages(ggraph::create_layout(hcl, "dendrogram")$label)
329+
dta$nodes$label <- tmp_layout$label
330+
dta$nodes$x <- tmp_layout$x
331+
dta$nodes$y <- tmp_layout$y
332+
dta$nodes$ggraph.index <- tmp_layout$ggraph.index
325333

326334
names(dta$nodes) <- sub("layout.", "", names(dta$nodes))
327335
names(dta$nodes)[which(names(dta$nodes) == "leaf")] <- "hidden"
@@ -330,6 +338,10 @@ visHclust.hclust <- function(object, data = NULL, main = "", submain = "", foote
330338
dta$nodes$leaf <- dta$nodes$hidden
331339
tpNum <- max(as.numeric(dta$nodes$id)) + 1
332340
dta$edges$horizontal <- FALSE
341+
342+
dta$nodes <- dta$nodes[, c("id", "x", "y", "hidden", "label", "members", "ggraph.index",
343+
"hidden2", "leaf", "neib", "labelComplete")]
344+
333345
outList <- sapply(1:nrow(dta$nodes), function(X){
334346
row <- dta$nodes[X,]
335347
if(row$hidden){
@@ -509,6 +521,10 @@ visHclust.hclust <- function(object, data = NULL, main = "", submain = "", foote
509521
miss_packages <- c(miss_packages, "'igraph'")
510522
}
511523

524+
if(!requireNamespace("tidygraph", quietly = TRUE)){
525+
miss_packages <- c(miss_packages, "'tidygraph'")
526+
}
527+
512528
if(length(miss_packages) == 1){
513529
stop(miss_packages," package is needed for this function", call. = FALSE)
514530
} else if(length(miss_packages) > 1){
@@ -551,7 +567,7 @@ visHclust.hclust <- function(object, data = NULL, main = "", submain = "", foote
551567
horizontal, submain, footer, highlightNearest, export){
552568

553569
res$edges$color <- colorEdges
554-
570+
555571
if(!is.null(cutree)){
556572
if(cutree > 1){
557573
color <- colorGroups
@@ -607,7 +623,7 @@ visHclust.hclust <- function(object, data = NULL, main = "", submain = "", foote
607623
res$nodes$label <- as.character(res$nodes$label)
608624

609625
# res$nodes$label[res$nodes$group %in% "individual" & res$nodes$hidden == FALSE] <- gsub("^(\\n)|(\\n)$", "",
610-
# gsub("", "\\\n", res$nodes$label[res$nodes$group %in% "individual" & res$nodes$hidden == FALSE]))
626+
# gsub("", "\\\n", res$nodes$label[res$nodes$group %in% "individual" & res$nodes$hidden == FALSE]))
611627
if(!horizontal){
612628
colnames(res$nodes)[2:3] <- c("y", "x")
613629
}
@@ -623,9 +639,9 @@ visHclust.hclust <- function(object, data = NULL, main = "", submain = "", foote
623639

624640
if(!horizontal){
625641
vis <- vis %>% visGroups(groupname = "individual",
626-
font = list(size = 200),
627-
color = list(background = "white", border = "white",
628-
highlight = "#e2e9e9", hover = "#e2e9e9"), shape = "box")
642+
font = list(size = 200),
643+
color = list(background = "white", border = "white",
644+
highlight = "#e2e9e9", hover = "#e2e9e9"), shape = "box")
629645
} else {
630646
vis <- vis %>% visGroups(groupname = "individual",
631647
font = list(size = 100),

0 commit comments

Comments
 (0)