Laying out selective vertices...

Jun 28, 2014 at 7:14 AM

I am developing simple C# application using NodeXL.

I have added few vertices and edges to the graph.
Then used ConnectedComponentCalculator algorithm to find out strongly connected components.

With this steps, I am getting vertices groups.

Now I am trying to draw vertices of each group one at a time using LayOutTheseVerticesOnly & LayOutTheseVerticesWithinBounds keys.

But it's not working, It always show a point where all vertices of the graph overlapped.
Am I missing something?

Any help or sample code will be very helpful.

Jun 30, 2014 at 5:09 PM
Edited Jun 30, 2014 at 5:11 PM
Here is the documentation for the LayOutTheseVerticesWithinBounds key:
The key is used only if the LayOutTheseVerticesOnly key is also added to the graph. If both keys are present, the specified vertices are laid out within the rectangle defined by the current locations of the outermost vertices in the set. 

The value of the LayOutTheseVerticesWithinBounds key is null. 
Note the "current locations" part. Has the graph ever been laid out? If not, the current vertex locations are all at their default value of (0,0), and the bounding rectangle has zero size.

I'm wondering if you are attempting to reproduce the layout effect common called "group in a box." If so, this isn't the way to do that. If you want "group in a box," you can get it by setting Layout.LayoutStyle to LayoutStyle.UseGroups. You also have to store the group information on the graph for this to work--see the "LayoutStyle Enumeration" topic in the NodeXLApi help file for details.

-- Tony
Jul 1, 2014 at 5:57 AM

I don't want "group in a box" kind of a layout.
What I have is Mobile Call Detail Records, where each record contain 2 numbers (i.e. A Party & B Party)

This are the steps I have followed...
  1. Create "Undirectional" graph (I specifically need this type)
  2. Added unique numbers as vertices
  3. Added each pair of numbers in a record as edges
  4. Used ConnectedComponentCalculator.CalculateStronglyConnectedComponents(IGraph, Boolean) method, to find out connected components.
  5. Above method returns "A list of LinkedLists of vertices. Each LinkedList of vertices comprises a strongly connected component of the graph."
  6. And finally I want to show "Each LinkedList of vertices" one at a time (i.e. sub-graph) as user request/selection.
So I never want to layout or draw, the entire graph as a whole, but want to layout only connected component vertices at a time.

Please guide, how to achieve this.

Jul 1, 2014 at 6:53 PM
Edited Jul 1, 2014 at 7:06 PM
Okay, I think I understand your requirements.

To lay out and show only the vertices in a strongly connected component, do the following:
  1. Add the LayOutTheseVerticesOnly key to the graph. By default, this causes the specified vertices to be laid out within the full graph rectangle.
  2. Do NOT add the LayOutTheseVerticesWithinBounds key. You want the bounds to be the full graph rectangle, and you've already accomplished that in step 1.
  3. For each vertex not in the strongly connected component, set the Visibility key on the vertex to VisibilityKeyValue.Hidden. That will prevent those vertices from being drawn in the next step.
  4. Lay out and draw the graph. If you are using the NodeXLControl, you would call its DrawGraph(true) method. The "true" argument forces a layout.
-- Tony
Jul 3, 2014 at 6:08 AM

Thank you very much!
The code/program is working fine as per your suggestions.

Can you further suggest some points (if any) to optimize it for large data sets?

Thanks again.
Jul 3, 2014 at 5:10 PM
Do you mean that you're not happy with the way the vertices are getting laid out?

If so and if you are using a FruchtermanReingoldLayout object, you can increase its "Iterations" property from its default value of 10. This property determines how many times the algorithm runs--larger values result in vertices getting shoved further apart. Here is a description from the NodeXLApi help file:
The number of times to run the Fruchterman-Reingold algorithm when the graph is laid out, as an Int32. Must be greater than zero. The default value is 10.
The FruchtermanReingoldLayout class also has a "C" property that determines the strength of repulsive and attractive forces. (It's called "C" because that's the name Fruchterman and Reingold used in their research paper.) From the help file:
The "C" constant in the "Modelling the forces" section of the Fruchterman-Reingold paper. Must be greater than 0. The default value is 1.0.

Increasing C decreases the attractive forces and increases the repulsive forces; decreasing C increases the attractive forces and decreases the repulsive forces.
There are no hard-and-fast rules concerning how you should set these. If you have the NodeXL Excel Template, you can use it to experiment with different values. In the Template, the values are available at NodeXL, Graph, Layout, Layout Options.

-- Tony
Jul 3, 2014 at 5:45 PM
Hi Tony, Would it be possible to make the number of iterations and the "C" constant for the Fruchterman-Reingold layout available to the user through the NodeXL gui (I am not a programmer)? Thanks. Peter
Jul 3, 2014 at 6:12 PM
Edited Jul 3, 2014 at 6:13 PM
Hello, Peter:

Yes. Go to NodeXL, Graph, Layout, Layout Options in the Excel ribbon. In the Layout Options dialog box, you can adjust "strength of the repulsive force between vertices" and "iterations per layout."

-- Tony