Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to set node width #91

Open
mtill opened this issue May 18, 2019 · 2 comments
Open

how to set node width #91

mtill opened this issue May 18, 2019 · 2 comments

Comments

@mtill
Copy link

mtill commented May 18, 2019

Hello,
how can I resize the nodes of a graph depending on the length of their labels?
I.e., a node with a "long" label should be wider than a node with a "short" label.

Thank you very much for your help -- and for this great library!
Best regads
mtill

Cytoscape:3.7.1
Java:1.8

@jorgeboucas
Copy link
Member

you can create a column with the size of node, upload the table:

cytoscape.table.loadTableData(<dataframe>, df_key=<df_key>, table_key_column=< table_key_column >)

and then use that to define NODE_SIZE:

NODE_SIZE=cytoscape.vizmap.mapVisualProperty(visualProperty="NODE_SIZE",\
                                                   mappingType="passthrough",\
                                                   mappingColumn="word_size")
cytoscape.vizmap.update_style("dataStyle",mappings=[NODE_SIZE])

@g-simmons
Copy link

g-simmons commented Aug 14, 2019

Is cytoscape in the above example supposed to be a CyRestClient object?

If it is, I get an AttributeError when trying to access cytoscape.vizmap

Here are some alternate instructions that worked for me, assuming that the labels for the nodes are already in the node table for your network.

#imports
from py2cytoscape.data.cyrest_client import CyRestClient
import pandas as pd

cy = CyRestClient()

#load some data
data = pd.read_csv('../data/<your_data_file.csv>')

#initialize the network
net = cy.network.create_from_dataframe(data,name="<network_name>",collection="<network_collection>")

# get the node table
node_table = net.get_node_table()

# get the label lengths
node_table['size'] = node_table.<label_column>.apply(len)

# update the node table
net.update_node_table(df=table,network_key_col="SUID",data_key_col="SUID")

# choose your favorite default style or skip if you already have a style object
my_style = cy.style.create('Marquee')

# create a mapping from the column value to NODE_SIZE and apply the style
my_style.create_passthrough_mapping(column='size',vp='NODE_SIZE',
            col_type='Integer')
cy.style.apply(my_style, net)

This is more verbose than the above, but in the above answer it's not really clear (at least to me) what the cytoscape object is.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants