Adding the label from the ucinet DL file to graph in a custom app.

May 26, 2010 at 7:33 PM
Hi I am having trouble grabbing the node labels from a DL file export from UCINET. I can load the graph with edges and nodes, but no labels.
May 26, 2010 at 8:47 PM

You have to call SetValue() on each vertex for which you want a label displayed.  Here is sample code that sets the vertex labels to the vertex names:

IGraph oGraph = ( new UcinetGraphAdapter() ).LoadGraphFromFile("FileName.txt");

foreach (IVertex oVertex in oGraph.Vertices)
{
    oVertex.SetValue(ReservedMetadataKeys.PerVertexLabel, oVertex.Name);
}

nodeXLControl1.Graph = oGraph;
nodeXLControl1.DrawGraphAsync(true);

You can also set edge labels using the ReservedMetadataKeys.PerEdgeLabel key, although you will have to construct them yourself because there are no edge labels in the UCINET file.

-- Tony

May 26, 2010 at 9:26 PM
Thanks Tony

This works perfectly, I was sure how to extract the names

Thanks,
joe

On Wed, May 26, 2010 at 2:47 PM, tcap479 <notifications@codeplex.com> wrote:

From: tcap479

You have to call SetValue() on each vertex for which you want a label displayed.  Here is sample code that sets the vertex labels to the vertex names:

IGraph oGraph = ( new UcinetGraphAdapter() ).LoadGraphFromFile("FileName.txt");

foreach (IVertex oVertex in oGraph.Vertices)
{
    oVertex.SetValue(ReservedMetadataKeys.PerVertexLabel, oVertex.Name);
}

nodeXLControl1.Graph = oGraph;
nodeXLControl1.DrawGraphAsync(true);

You can also set edge labels using the ReservedMetadataKeys.PerEdgeLabel key, although you will have to construct them yourself because there are no edge labels in the UCINET file.

-- Tony

Read the full discussion online.

To add a post to this discussion, reply to this email (NodeXL@discussions.codeplex.com)

To start a new discussion for this project, email NodeXL@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe on CodePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at CodePlex.com


May 26, 2010 at 10:07 PM
Hi Tony,

Is there an adapter available for reading binary matrix data (network) created on an excel spreadsheet

I would like to create multiple binary networks using excel spreadsheets and then view the graphs in my custom app.

Thanks,
Joe

On Wed, May 26, 2010 at 2:47 PM, tcap479 <notifications@codeplex.com> wrote:

From: tcap479

You have to call SetValue() on each vertex for which you want a label displayed.  Here is sample code that sets the vertex labels to the vertex names:

IGraph oGraph = ( new UcinetGraphAdapter() ).LoadGraphFromFile("FileName.txt");

foreach (IVertex oVertex in oGraph.Vertices)
{
    oVertex.SetValue(ReservedMetadataKeys.PerVertexLabel, oVertex.Name);
}

nodeXLControl1.Graph = oGraph;
nodeXLControl1.DrawGraphAsync(true);

You can also set edge labels using the ReservedMetadataKeys.PerEdgeLabel key, although you will have to construct them yourself because there are no edge labels in the UCINET file.

-- Tony

Read the full discussion online.

To add a post to this discussion, reply to this email (NodeXL@discussions.codeplex.com)

To start a new discussion for this project, email NodeXL@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe on CodePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at CodePlex.com


May 26, 2010 at 11:41 PM
Edited May 26, 2010 at 11:43 PM

Joe:

There are no adapters for reading Excel spreadsheets.  However, here is a technique you might consider:

1. Install the NodeXL Excel Template (http://www.codeplex.com/NodeXL/Release/ProjectReleases.aspx).

2. In the NodeXL Excel Template, use NodeXL, Import, From Open Matrix Workbook to import your matrix workbook into a NodeXL workbook.  That converts the matrix to an edge list.

3. Save the NodeXL workbook to a tab-delimited file.

4. In your application, use the Microsoft.NodeXL.Adapters.SimpleGraphAdapter class to read the tab-delimited file.

If that workflow is too complicated, is it possible to represent your graph as an edge list instead of a matrix?  In that case, you could just save your workbook directly to a tab-delimited file and use SimpleGraphAdapter to read it, bypassing the need for the NodeXL Excel Template.

Otherwise, you'll have to write your own code to read your matrix workbook.  NodeXL has its own code to do this (http://nodexl.codeplex.com/SourceControl/changeset/view/50400#416159), but because it has to handle edge weights, directed vs. undirected graphs, labels vs. no labels, and so on, it's much more complicated than your code would have to be.

-- Tony