How to change the template system from Jade to HTML with Express

This quick post is just to remember how to change the template engine on Express from Jade to HTML.

  1. Install the ejs view engine with the NPM:
    npm install ejs
  2. Set your template engine in app.js (or in your custom .js app file) as ejs
    app.engine('html', require('ejs').renderFile);
    app.set('view engine', 'html');
  3. In the route file ./routes/index.js  assign template variables like this
    exports.index = function(req, res){
    res.render('index', { title: 'Page title' });};
  4. Create the HTML files in the view folder /views.

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("ui.style")){
     n.setAttribute("ui.style", n.getAttribute("ui.style") + " size:"+ Math.round((scale*maximumsize)+minimumsize) +"px;");
  }
  else{
    n.addAttribute("ui.style", " 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 ui.style 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: https://github.com/agabardo/GraphStream/tree/master/Blog%20Examples

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.