// Calculate the degree of all nodes right after the network is rendered
vis.ready(function () {
// Get all nodes
var nodes = vis.nodes();
for (var i=0; i < nodes.length; i++) {
var n = nodes[i];
// Get first neighbors by node id
var fn = vis.firstNeighbors([n.data.id]);
// Calculate the degree
// (actually, this is incorrect, as loops must be counted twice!)
var degree = fn.edges.length;
// Set the degree to the node as an attribute
// (make sure the nodes schema has this field!!!)
n.data.degree = degree;
}
// Ask CW to update the data
vis.updateData(nodes);
// Now create a new visual style (or get the current one) and register
// the continuous mapper to one or more visual properties:
var style = vis.visualStyle();
style.nodes.size = { continuousMapper: { attrName: "degree", minValue: 24, maxValue: 72 } };
// Finally set the visual style again
vis.visualStyle(style);
});
Hi, I am new to using Cytoscape, and have found it very user friendly.I have a some quick query's. 1) how to make the size of the target node adjust according to the number of connections with source nodes (and vice-versa). 2) Is it possible to adjust the transparency of the color according to the number of connections? 3) Is there a resource to import additional visual styles?This is my first time doing SNA, so it is taking me a little bit longer to learn the potential uses of the software.thank you,
vis.ready(function(){
var field = { name: "degree", type: "number", defValue: 24 };
vis.addDataField("nodes", field);
// Get all nodes
var nodes = vis.nodes();
for (var i=0; i < nodes.length; i++) {
var n = nodes[i];
// Get first neighbors by node id
var fn = vis.firstNeighbors([n.data.id]);
// Calculate the degree
// (actually, this is incorrect, as loops must be counted twice!)
var degree = fn.edges.length;
// Set the degree to the node as an attribute
// (make sure the nodes schema has this field!!!)
n.data.degree = degree;
}
// Ask CW to update the data
vis.updateData(nodes);
// Now create a new visual style (or get the current one) and register
// the continuous mapper to one or more visual properties:
var style = vis.visualStyle();
style.nodes.size = { continuousMapper: { attrName: "degree", minValue: 30, maxValue: 80 } };
// Finally set the visual style again
vis.visualStyle(style);
vis.removeListener("error", onDrawError);
$("#metascape_container").trigger("available");
//vis.removeDataField("nodes", field);
});