PerVertexLabels no being displayed on exported image

Oct 20, 2014 at 11:25 AM
Edited Oct 20, 2014 at 11:26 AM
I am creating a graph using NodeXL through C#, When adding the Vertex i use "ReservedMetadataKeys.PerVertexLabel" to change the label, however when saving and viewing the outputed image of the graph, some vertices do not have labels. I have made sure that I am indeed passing through a label that has text. Even hard coding all the labels to a fixed string still results in empty labels.

Bellow is the code.
int GraphWidth = 100 * reconObjects.networkRelationshipDiagramDictionary.Keys.Count;
int GraphHeight = 100 * reconObjects.networkRelationshipDiagramDictionary.Keys.Count;

Graph oGraph = new Graph(GraphDirectedness.Undirected);
// Get the graph's vertex collection.

IVertexCollection oVertices = oGraph.Vertices;
IEdgeCollection oEdges = oGraph.Edges;

// Add vertices and edges.
Dictionary<string, IVertex> vertices = new Dictionary<string, IVertex>();

foreach (string outerKey in reconObjects.networkRelationshipDiagramDictionary.Keys)
{
    if (outerKey.Equals("centurion"))
    {
        Console.WriteLine("hi");
    }

    if (!vertices.ContainsKey(outerKey))
    {
        vertices.Add(outerKey, oVertices.Add());
        //vertices[outerKey].SetValue(ReservedMetadataKeys.PerVertexLabel, "ww");
        vertices[outerKey].SetValue(ReservedMetadataKeys.PerVertexLabel, outerKey);
    }

    foreach (string innerKey in reconObjects.networkRelationshipDiagramDictionary[outerKey].Keys)
    {

        if (!vertices.ContainsKey(innerKey))
        {
            vertices.Add(innerKey, oVertices.Add());
            //vertices[innerKey].SetValue(ReservedMetadataKeys.PerVertexLabel, "iiiiiiiiiiiiiiiiiiiiiiiii");
            vertices[innerKey].SetValue(ReservedMetadataKeys.PerVertexLabel, innerKey);
            vertices[innerKey].SetValue(ReservedMetadataKeys.PerVertexLabelFontSize, 25F);
        }

        IEdge edge = oEdges.Add(vertices[outerKey], vertices[innerKey], false);
        edge.SetValue(ReservedMetadataKeys.PerEdgeWidth, 5F);
        edge.SetValue(ReservedMetadataKeys.PerEdgeLabel, reconObjects.networkRelationshipDiagramDictionary[outerKey][innerKey].ToString());
        edge.SetValue(ReservedMetadataKeys.PerColor, System.Drawing.Color.FromArgb(255, 0, 255, 0));
    }
}

ILayout oLayout;

switch (layoutIndex)
{
    case 0:
        {
            oLayout = new FruchtermanReingoldLayout();
            break;
        }
    case 1:
        {
            oLayout = new CircleLayout();
            break;
        }
    default:
        {
            throw new IndexOutOfRangeException("The index for selecting a layout for the network relationship diagram is incorrect.");
        }
}

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

oLayout.LayOutGraph(oGraph, oLayoutContext);


// Create an object that can render a NodeXL graph as a Visual.

NodeXLVisual oNodeXLVisual = new NodeXLVisual();

// Use the NodeXLVisual object's GraphDrawer to draw the graph onto the visual.

GraphDrawingContext oGraphDrawingContext = new GraphDrawingContext(
    new Rect(0, 0, GraphWidth, GraphHeight), oLayout.Margin,
    System.Windows.Media.Color.FromRgb(255, 255, 255));

oNodeXLVisual.GraphDrawer.DrawGraph(oGraph, oGraphDrawingContext);

// Convert the Visual to a Bitmap.

RenderTargetBitmap oRenderTargetBitmap;

oRenderTargetBitmap = new RenderTargetBitmap(GraphWidth, GraphHeight, 96, 96, PixelFormats.Default);

oRenderTargetBitmap.Render(oNodeXLVisual);
BmpBitmapEncoder oBmpBitmapEncoder = new BmpBitmapEncoder();
oBmpBitmapEncoder.Frames.Add(BitmapFrame.Create(oRenderTargetBitmap));
MemoryStream oMemoryStream = new MemoryStream();
oBmpBitmapEncoder.Save(oMemoryStream);
Bitmap oBitmap = new Bitmap(oMemoryStream);

// Write the Bitmap's contents to the response stream.
oBitmap.Save(outputLocalFullFileNamePathWithoutExtension + ".gif", ImageFormat.Gif);