Problem with Edge Color

Aug 31, 2010 at 5:12 PM

Hello , I have a GraphMl file that contains the color information for the edges present in the graph. I am also using GraphMLGraphAdapter.

When I load the GraphML file directly into NodeXL application then I get the desired results but when I  trying getting same result through passing the graphML file to the above mentioned adapter, I dont get color edges but the default color Black


for rendering I am just using the example code in the Help.chm

GraphMLGraphAdapter adapter = new GraphMLGraphAdapter();
 ConnectNodeXL.graph = adapter.LoadGraphFromString(gmlstring);

Console.WriteLine("Process 1 :Adapter loaded = {0}", DateTime.Now.ToString()); 

LayoutContext oLayoutContext = new LayoutContext(new Rectangle(0, 0, GraphWidth, GraphHeight));

NodeXLVisual oNodeXLVisual = new NodeXLVisual();


GraphDrawingContext oGraphDrawingContext = new GraphDrawingContext(new Rect(0, 0, GraphWidth, GraphHeight), oLayout.Margin, System.Windows.Media.Color.FromArgb(255, 255, 0, 255));                oNodeXLVisual.GraphDrawer.VertexDrawer.Shape = VertexShape.Label;

oNodeXLVisual.GraphDrawer.DrawGraph(graph, oGraphDrawingContext);



and then I render it to bitmap


Kindly advice me what steps I need to take for getting color edges. I have the color info store in a graphml file.

Thanks a lot in advance.



Aug 31, 2010 at 6:33 PM
Edited Aug 31, 2010 at 6:36 PM

You can do that without too much trouble.  The GraphMLGraphAdapter.LoadGraphFromString() method reads all the edge and vertex GraphML-attribute values it finds in your GraphML file and stores those values as key/value metadata on the edges and vertices in the IGraph object it creates.  The NodeXLVisual class doesn't understand the metadata and ignores it, but if you convert the metadata to a format that NodeXLVisual does understand, then you can get the edge colors you want.

Let's say your GraphML file specifies edge colors using a GraphML-attribute with an of "Color" and an attr.type of "string", like this:

 <graphml ...
     <key id="EdgeColor" for="edge""Color" attr.type="string" />
     <graph edgedefault="undirected">
         <edge source="V3" target="V2">
             <data key="EdgeColor">Red</data>
Then GraphMLGraphAdapter.LoadGraphFromString() will add a "Color" key to the V3-V2 IEdge object, and the key will have a String value of "Red."  The NodeXLVisual class doesn't understand the "Color" key and ignores it, but it does understand the ReservedMetadataKeys.PerColor key, so if you add a ReservedMetadataKeys.PerColor key to each edge and set its value to a System.Drawing.Color, you'll get colored edges.  The code would look something like this:

[Don't try to compile this, as I'm typing it from the top of my head.]

ColorConverter colorConverter = new ColorConverter();

foreach (IEdge edge in graph.Edges)
    // Retrieve the metadata value that GraphMLGraphAdapter.LoadGraphFromString() stored on the edge.

    String colorAsString = (String)edge.GetRequiredValue( "Color", typeof(String) );

    // Convert the color String to a System.Drawing.Color.

    System.Drawing.Color colorAsColor = (System.Drawing.Color)colorConverter.ConvertFromString(colorAsString);

    // Store the converted color on the edge using a key that NodeXLVisual understands.

    edge.SetValue(ReservedMetadataKeys.PerColor, colorAsColor);

Aug 31, 2010 at 6:53 PM

Hey Tony 

U know what... U are simply amazing.. Literally, thanks a lot.. 

With this help of yours I hereby finish my project. haha. Thanks again .. I really appreciate ur time and all the helps ..

NodeXL Team , U guys rock man.. cheers!