2. Improving a layout

Introduction

In this tutorial, we will show you how to use layouts algorithms and graph properties to obtain a nice an clear graph. To do so, we will first import a file system structure, and then use the graph properties to find specific files. (*.cpp, *.hpp, ...)

File system import

To create a graph from a file system, we have to select the File System Directory import tool which is in the File->Import->Misc menu.

A "file browser dialog" will pop-up for you to select the root directory from which to create the graph. On this dialog, you just need to select a directory, e.g. Home (On Windows : My Documents). Each folder and file will be represented as a node, and an edge will link a node to its parent folder.

The import plug-in will work for some time, and a tree graph will appear representing the chosen file system.

To follow the rest of this tutorial you need to download and load (File->Open) this tulip compressed graph file : Graph.

Using other Layouts

Bubble Tree Layout :

This layout algorithm can be found in the menu Algorithm->Layout->Tree. The bubble tree layout is very useful to notice directories that have a similar structure. In this section, we will try to locate those directories.

To have a better view on the tree, we will create a new Node Link Diagram View. View->Node Link Diagram View. When the new view is created, we need to re-organize the windows. Windows->Tile

Now that we can see both views at the same time, we will zoom in on the right window. Select the magnifying glass tool, and draw a bounding box on the left side of the graph. Just like this :

As you can see, two nodes looks very alike. By using the Get Information tool, we can get their ids : Node 1965 and node 2009. It makes sense that these two directories have the same structure, since they both contain plug-ins source files.

We will now re-center the view (View->Center View or Ctrl+Shift+C).

Let's say that we now want to study our graph without the plug-in directory. To easily delete the whole directory, we have to select it, and then select all its sub directories.

  • Select the plug-in directory : Use the Find tool, (Edit->Find or Ctrl+F) with the field Input property set to "name", filter function set to "=" and filter value set to "plugins".

  • Select all its sub-directories : Use the Algorithm->Selection->Reachable Sub-Graph algorithm with the field distance set to 50.

  • Delete all the selection : press Del

  • Re-run the bubble layout Algorithm->Layout->Tree->Bubble Tree.

Following is what you should see :

As you can see, the bubble tree layout can be quite useful.

The Tree Map layout

This Layout algorithm can be found in Algorithm->Layout->Tree. The treemap layout is very useful to notice large disk usage files. This section will show you how to use the tree map layout

First, make sure that the Options -> Force Ratio item is not checked.

Apply the layout algorithm Algorithm->Layout->Tree->Squarified Tree Map with the following parameters :

  • Metric : set to "size".

  • Aspect Ratio : set to 1

  • TreeMap Type? : checked

Following is what you should see :

As you can see, we easily get a global information on the size of files. Which is the biggest and which is the smallest. But we can also see the structure of directories, since files and directories are nested nodes. See Wikipedia : Tree Maps for more information.

Improved Walker layout :

This layout can be found in the Algorithm->Layout->Tree->Improved Walker.

Use the following parameters :

  • Node Size : viewSize

  • Orientation : Left to right.

  • Orthogonal : Checked.

  • Layer Spacing : Default value.

  • Node Spacing : Default Value.

You should see a tree looking like this :

As you can see, the improved walker layout, is just a hierarchical layout. It is very useful in order to understand the tree structure of a file system.

Showing Labels

First, navigate to the View Editor tab in the left-hand dock. Then, go into the Layer Manager tab, and check the Nodes Label box in the first column.

We will now try to add labels to the nodes. To do so, select the node property called "name" in the info editor window, click on the button To Labels.

You should now see a graph looking like that :

As you can see, the labels don't fit in nodes and it is very hard to read the graph. To fix this go in the Rendering Parameters tab, and check the Scale labels to fit node sizes box.

You should obtain something like this.

By zooming in we can see the labels :

If you want to display the big file (high disk space) with big nodes, use the Algorithm->Size->Metric Mapping algorithm with the parameter called "property" set to "size".

Showing a specific kind of file.

Now that our graph has a nice and clear layout, we would like to locate all of our Source files (*.cpp). To do so, we will use the Find tool (Edit->Find or Ctrl+F).

Use the following parameters :

  • Input Property : name

  • Filter : filter function set to "=" and filter value set to ".*cpp or .*hpp". The filter supports regular expressions, and in regular expressions '.' means any character, and '*' means any number of times, so '.*' means any character, any number of times. Not to be mistaken with wildcard characters. For more details on regular expressions, follow this link : WikiPedia : Regex

  • Options : check the Replace radio button and select On nodes.

Now that our source files are selected, we will apply a different color to them.

In the info editor window, select the node property called "viewColor", check the selected only option. Now that we only see the "viewColor" property of the selected nodes, click on the button Set all and choose the color that you want. (We chose green)

You should see a graph like the following :

Conclusion

As you have seen, tulip implements powerful layouts and tools, to make a complex graph into a simple and understandable one.