Automatically adjusting the size of nodes with the GraphStream Library

This is a complimentary post about showing overlapping communities using the GraphStream Library with Java. When showing information by means of a graph there is the possibility of showing the relationships among the elements in a very intuitive and designing appealing way.  Whit graphs we can express the “importance” of nodes by varying the size of the nodes. For instance, a graph constituting cities can show larger nodes for more populated cities and smaller nodes for villages or small towns. In graph visualization software’s there is usually a tool for achieving this task. See the Gephi example in Figure 1.
Screenshot 2016-03-03 14.00.24

Figure 1 – The node attributes panel on Gephi.

I was looking to achieve the same with the visualizations that I am making for some of my PhD projects. In this small example I’m using the degree of nodes to express the “importance” and size of the nodes. Similar to the Gephi feature I’ve made a Java method in my application which receives the lower (smaller size that a node will appear) and higher (larger size that a node will appear) boundary values and used Feature Scaling Normalization

Feature scaling used to bring all values into the range [0,1].

to normalize and restrict the range from the minimum and maximum sizes of the nodes. The method is pretty simple. See the code bellow.

public void setNodesSizes(int minimumsize,int maximumsize){
  int smaller = -1;
  int greater = -1;
  for(Node n:Karate.getEachNode()){ //Karate is the GraphStream Graph Object.
    if(n.getDegree() > greater || smaller == -1)
      greater = n.getDegree();
    if(n.getDegree() < smaller || greater == -1)
      smaller = n.getDegree();
  for(Node n:Karate.getEachNode()){
    double scale = (double)(n.getDegree() - smaller)/(double)(greater - smaller);
  if(null != n.getAttribute("")){
     n.setAttribute("", n.getAttribute("") + " size:"+ Math.round((scale*maximumsize)+minimumsize) +"px;");
    n.addAttribute("", " size:"+ Math.round((scale*maximumsize)+minimumsize) +"px;");

The first loop discovers the lower and highest degrees in the graph to build the boundaries. The second loop set or add the attribute size to the attribute for each node. If the attribute is null, add, if not null, read and concatenate. The result with the same values (20 for min, 35 max) used on Gephi is shown in Figure 2.

Screenshot 2016-03-03 14.31.21Figure 2 – The Karate Club Network, node sizes are relative to node degree.

The complete source of this example is available on GitHub:

PLEASE NOTE: The static objects were used in this example for learning purposes only. Do not structure your Java Classes like this. Use the proper object instances instead. Thank you for the visit.


PhD Thesis, LaTeX document template.

I have adapted a LaTeX document template for my Ph.D. Thesis, based on the file from Mikhail V. Konnik, you can found the original here (

This is for the University of Newcastle, however, can be easily adapted to other universities and for another kind of documents as well.

The files are available in my GitHub repository: