SGNet

SGNet
SGNet provides visualization for network graphs and more…

One of the challenges while implementing the front-end of the TALOS Computation Server was visualizing network graphs and then reusing this solution for more advanced features. The features you expect from such visualization would be showing the nodes and arcs. When it comes to solving shortest path problems you also need to highlight the optimal path.

Let’s make things more complicated. Suppose that you have an attacker-defender model (a popular optimization problem), now you also need to highlight the blocked roads. SGNet provides all these features with minimal configuration.

The following is a demo of SGNet with simple nodes.

One of my favorite sayings: “Everything is a network!

Now assume that we would like to build a user interface to facilitate creating a system which includes sequential tasks. That is; the user tells “first run this script”, and then “run the second one”. Is that all? No! The user wants to feed the second script with the output of the first script. Just like the pipe-filter architecture or simply the pipe “|” in UNIX shell.

Well, this design is a network. Each script is a primary node. Now go ahead and click on the script node. You should see input files on the left and output files on the right. Our nodes are not simple nodes anymore. They contain internal elements which can be regarded as the secondary nodes.

And run sequences are the primary arcs. Now switch on the design mode by clicking on toolbox below. Now you can draw a sequence arc from one primary node to another. Run sequence is done. How about data exchange? Now right click on the primary arc in orange color. You should see all secondary nodes displayed. You can connect those elements using their colorful circles. This secondary arc means “this file overrides that file”. When you are done just right click on the main arc, and then switch off the design mode. Let’s call this design a super-system (system of systems) design. And the super-system information is stored in JSON format ready to be used by developer.

So how to use this SGNet Library?
Network Graph with Simple Nodes
First, clone or fork the library from my repository.

Include the external dependencies as shown in line 1-2. You can use jquery from another source too. However, I strongly recommend using my raphael library which includes a bug fix about arc arrows. And finally include sgnet.js file.

Now, create a div for the network graph.

And some styling:

  • Now, define array of node arrays with length 3 (Name of node, x coordinate, y coordinate) as shown below. You do not need to provide coordinates. But this will generate randomly located nodes. How about the ranges of coordinates? Never mind, SGNet will regularize whatever you provide.
  • Define arcs to connect these nodes. And finally define flow arcs and road block arcs. Flow will be in green color while block is represented in red color.
  • Create an SGNet object called myGraph with parameters: div id for graph, width and height in pixels.
  • Draw the nodes, arcs, blocks, and flow using the SGNet object methods.
  • That’s it.

    Network Graph with Complicated Nodes

    I won’t repeat all steps above. I am just providing the difference.

    As shown below, we need to provide script information as an object with the keys: “modelName”, “input files” and “output files”.
    And this object will be the last item in node array (either with or without coordinates).

    Cheers…