cytoscape / RCy3

New version of RCy3, redesigned and collaboratively maintained by Cytoscape developer community
MIT License
48 stars 20 forks source link

New function for node size legend? #84

Open AlexanderPico opened 4 years ago

AlexanderPico commented 4 years ago

Could be something like...

# Set your current style name
style.name <- "galFiltered Style"

# Extract min and max node size
res<-cyrestGET(paste0("styles/",style.name,"/mappings/NODE_SIZE"))
size.col <- res$mappingColumn
min.size <- res$points[[1]]$equal
min.value <- res$points[[1]]$value
max.size <- res$points[[length(res$points)]]$equal
max.value <- res$points[[length(res$points)]]$value

# Prepare as data.frame
legend.df <-data.frame(c(min.size, max.size), c(min.value, max.value))
colnames(legend.df) <- c("legend.label",size.col)
rownames(legend.df) <- c("legend.size.min", "legend.size.max")

# Add legend nodes and data
addCyNodes(c("legend.size.min", "legend.size.max"))
loadTableData(legend.df)

# Style and position
setNodeColorBypass(c("legend.size.min", "legend.size.max"),"#000000")
setNodePropertyBypass(c("legend.size.min", "legend.size.max"), 
                      c("E,W,l,5,0", "E,W,l,5,0"),  # node_anchor, label_anchor, justification, x-offset, y-offset
                      "NODE_LABEL_POSITION")
setNodeLabelBypass(c("legend.size.min", "legend.size.max"), legend.df$legend.label)
setNodePropertyBypass("legend.size.max", 
                      as.numeric(max.size)/2 + as.numeric(min.size)/2 + 10, # vertical spacing
                      "NODE_Y_LOCATION")
setNodeFontSizeBypass(c("legend.size.min", "legend.size.max"), c(20,20))
AlexanderPico commented 4 years ago

Note: should handle continuous, passthrough and discrete NODE_SIZE mappings

bdemchak commented 3 years ago

New function for node size legend?