Need Help with calculation of graph matrics

Jul 28, 2010 at 9:16 PM
Edited Jul 28, 2010 at 10:21 PM

Hello ,
I have a graphML file that contains information about vertex1 vertex2 and edge weight along with instruction to draw undirected graph.Is there is way in NodeXL through which I can get things like:
1. Calculate All the graph Matrics like    a. Betweenness and closeness centralities   b. Eigenvector centrality   c. PageRank etc.
2. Draw edges width according to edge weight provided in my GraphML file.
3. How to label the nodes, so that I get nodes names as well in my image like Pierre de Vries graph or Marc Smith graph shown on HOME page.
Right now I am simply loading file using graphml adapterdrawing the graph as discussed in one of the posts here but I am getting weidth for all edges same though my file contains different edige weights. 
I am doing console application and saving graph on disk. I will be thankfull for Explanation and steps .  
Thanks for the help in advance 


Jul 29, 2010 at 12:36 AM
Edited Jul 29, 2010 at 12:38 AM

To calculate graph metrics, see the "Microsoft.NodeXL.Algorithms Namespace" topic in the NodeXLApi.chm help file.  This namespace contains a set of classes that take a graph and calculate a set of metrics for the graph's vertices.  For example, the BrandesFastCentralityCalculator class calculates the betweenness and closeness centralities you asked about.  You can call either the CalculateGraphMetrics() or TryCalculateGraphMetrics() method on the class, whichever is more convenient for you.  If you call TryCalculateGraphMetrics() from your single-threaded console application, pass null for the backgroundWorker argument.

You control an individual edge's width by storing special metadata on the edge using the Edge.SetValue() method.  The key should be the constant ReservedMetadataKeys.PerEdgeWidth, which is documented in the Microsoft.NodeXL.Core.ReservedMetadataKeys help topic, and the value should be the numerical edge width.  It is up to you to calculate the edge widths, which you can do using a linear mapping from the minimum and maximum edge weights in your GraphML file, or whatever other technique is appropriate for your application.

Similarly, you can label the vertices using the ReservedMetadataKeys.PerVertexLabel key.  Be sure to read the help topic for that key, because it explains that there are actually two types of vertex labels.

-- Tony

Jul 30, 2010 at 8:22 PM

Thanks Tony.. I really appreciate your time and effort 


Jul 30, 2010 at 10:10 PM

Hey Tony, 

I am sorry to say that I tried  but I could not figure out how to change the vertex shape from Disk to Label. I mean I want vertex name instead of "dot"representation and also how to use ReservedMetadataKeys.PerVertexLabel
as that is readonly  value. 


I am doing "new VertexDrawer().Shape = VertexShape.Label"; and then calling string method on ReservedMetadataKeys.PerVertexLabel to check if something changes BUT no its still ~VDLable.. 

defiantly I am missing some concept here .. please help me out with this.

The image shown in
 is what I am trying to get as Jpeg or bitmap 

Jul 31, 2010 at 8:31 PM
Edited Jul 31, 2010 at 8:31 PM

The VertexDrawer.Shape property sets the default shape of the graph's vertices.  So if you do this:

vertexDrawer.Shape = VertexShape.Sphere;

and you do not do anything to the individual vertices, then all the graph's vertices will be spheres.

You can show most of your vertices as the default shape but change the shape of one of them by storing special metadata on that vertex using the Vertex.SetValue() method.  That method takes a key, which is normally one of the read-only values in the ReservedMetadataKeys class, and a value, the nature of which varies with the key.  The ReservedMetadataKeys.PerVertexShape, for example, will change the shape of an individual vertex.  So if you do this:

vertexDrawer.Shape = VertexShape.Sphere;
specialVertex.SetValue(ReservedMetadataKeys.PerVertexShape, VertexShape.Square);

then all the graph's vertices will be spheres, except for the special vertex, which will be square.

Now for labels, there are two types: label shapes, which are boxes with text inside them, and label annotations, which are pieces of text drawn next to the vertex.  You want label shapes.  To get label shapes, do this:

vertexDrawer.Shape = VertexShape.Label;
vertexA.SetValue(ReservedMetadataKeys.PerVertexLabel, "Vertex A");
vertexB.SetValue(ReservedMetadataKeys.PerVertexLabel, "Vertex B");

-- Tony


Aug 2, 2010 at 5:15 PM

Thanks a ton Tony .. I got the name of the vertices adjacent to there nodes for eg (    xxx (dot)---->(dot) YYY    ) and I am happy with this also but still I am unable to get like ( |xxx|--->|YYY | ) . I did what u suggested  

new VertexDrawer().Shape = VertexShape.Label;

var nodes = graph.Vertices;              

 foreach (var v in nodes)                

{ v.SetValue(ReservedMetadataKeys.PerVertexLabel, v.Name);                  



but this is giving me (    xxx (dot)---->(dot) YYY    ) this result . 

if you please would you help me with getting result like ( |xxx|--->|YYY | ) instead of (    xxx (dot)---->(dot) YYY    )

Thanks again for your help

Aug 2, 2010 at 5:54 PM
Edited Aug 2, 2010 at 5:56 PM

The problem is with the first line of your code:

new VertexDrawer().Shape = VertexShape.Label;

This is creating a new VertexDrawer object, setting its Shape property, and then immediately discarding the VertexDrawer object.  That won't accomplish anything.

I assume that you are using the NodeXLVisual component in your console application. If so, here is how to set its default shape to Label:

nodeXLVisual.GraphDrawer.VertexDrawer.Shape = VertexShape.Label;

This code gets the VertexDrawer owned by your NodeXLVisual object and set its default shape to Label. Now, anytime a vertex is drawn within your NodeXLVisual object, it will be drawn as a Label.

-- Tony

Aug 2, 2010 at 6:12 PM

ahh Bingoo, Its completely my bad .. Thanksssssss a lot. The Problem was 

I was doing :

I was drawing the graph and then changing the value ..haha .. My bad

but when u said "creating a new VertexDrawer object, setting its Shape property, and then immediately discarding " It struck to me what was going wrong .. :) 

and I switched the lines :

oNodeXLVisual.GraphDrawer.VertexDrawer.Shape = VertexShape.Label;

oNodeXLVisual.GraphDrawer.DrawGraph(graph, oGraphDrawingContext);

Extremely sorry for the trouble ..


Aug 2, 2010 at 6:14 PM

No trouble at all.  I'm glad you have it working now.

-- Tony