Skip to content

Commit

Permalink
Fixed color problem in 2DVisualizer.
Browse files Browse the repository at this point in the history
  • Loading branch information
zaynabhammoud committed Jan 19, 2023
1 parent 2cdcace commit 37a833e
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions R/mully_visualization.R
Original file line number Diff line number Diff line change
Expand Up @@ -65,24 +65,30 @@ getMarkGroups <- function(g) {
plot.mully <- function(x, layout,...) {
gps = getMarkGroups(x)

cols = randomColor(count = x$iLayer)
usedCols = unique(V(x)$color)
colrs = randomColor(count = x$iLayer)

assignedColors=V(x)$color
usedCols = unique(assignedColors)
if (is.null(V(x)$color))
V(x)$color = NA

for (i in 1:dim(x$layers)[1]) {
nodesinlayer=getLayerByID(x,i)
if (NA %in%nodesinlayer$color) {
if (!cols[i] %in% usedCols) {
nodesinlayer$color[which(is.na(nodesinlayer$color))] = cols[i]
usedCols = c(usedCols, cols[i])
idLayer=as.integer(x$layers$ID[i])
nodesid=which(V(x)$n == idLayer)
if(is.null(nodesid) || length(nodesid)==0)
next
if (NA%in%V(x)[nodesid]$color) {
if (!colrs[idLayer] %in% usedCols) {
V(x)[nodesid]$color = colrs[idLayer]
usedCols = c(usedCols, colrs[idLayer])
}
else{
c = randomColor(count = 1)
while (c %in% usedCols) {
c = randomColor(count = 1)
}
usedCols = c(usedCols, c)
V(x)[which(V(x)$n == i)]$color = c
V(x)[nodesid]$color = c
}
}
}
Expand Down

0 comments on commit 37a833e

Please sign in to comment.