I am not familiar with cytoscape or Java, so I do not know if there is a way to define a node size which depend on node's degree.
Currently I am using the following:
cytoscapeobj.set_style(
[
{
'selector':node,
'style': {
'font-family': 'helvetica',
'font-size': '20px',
'label': 'data(id)'
}
},
{
'selector': 'edge',
'style': {
'font-family': 'helvetica',
'font-size': '20px',
'width' : 'mapData(weight)' # it is actually not working
}
},
{
'selector': 'node[Degree>0]',
'style': {
'width': '100px',
'height': '100px'
}
},
{
'selector': 'node[Degree>1]',
'style': {
'width': '150px',
'height': '150px'
}
},
{
'selector': 'node[Degree>2]',
'style': {
'width': '200px',
'height': '200px'
}
}
]
)
I have thousands of nodes, some of them has degree 1 (most of them), then I have nodes with degree 2, 3, 4, 5 ,... 100, ...
It would be not easy to add a selector for each of them.
Do you know if there is an easier way to plot any node's degree?
You can define any required parameters in the node's data and then use style mappers to apply that data to style properties like width
or any other. So your code is actually the right way to do that.
It doesn't work because mapData()
and data()
works in a different ways. While data()
will just apply the data
value to that property, as it does to label
in your example, the mapData()
requires additional parameters to be set.
Check this out:
width: mapData(weight, 0, 100, 1, 3)
In that case, mapData
will take the value of data.weight
and then check where is that value between 0 and 100 and proportionally set width
to the according value between 1 and 3.
In my experience, I find it more convenient to use values, precalculated in the code. So I'd go with creating the data.width
param and setting to the desired width and then just map the simple data()
mapper to that value.