Export and Displaying

Mar 14, 2012 at 8:14 PM

Is there a good way to Export the contents of a Graph, and then to reimport that and be able to display it through the API?

I have created a sample graph using the Excel Plugin, and have exported it as a GraphML file.  I am then able to import it using the GraphMLGraphAdapter.LoadGraphFromFile API, but when I display it I see a graph which only has the edges and the verticies of the one I created.

It is not oriented the same, and does not have the same attributes such as size, color, etc.  I am looking to do something similiar to what you are doing on the NodeXL Graph Gallery.

Mar 15, 2012 at 4:39 AM
Edited Mar 15, 2012 at 4:44 AM


It's not easy to do what you want to do.  The reason is that the NodeXL API is designed for programmers while the workbook is designed for Excel users, and the two groups speak different languages.

For example, a programmer specifies the opacity of a NodeXL edge using an alpha value that ranges from 0 to 255, a concept familiar to .NET programmers.  But Excel users don't know Alpha from Adam, so the workbook presents them with a more sensible Opacity column that ranges from 0 to 100.  When the workbook is read, a translation layer kicks in to convert Opacity column values to alpha values to feed to the API.  The same holds for most other workbook columns.

When the workbook is exported to a GraphML file, no conversions are performed.  It wouldn't make sense to convert anything, because the destination of the GraphML isn't known.  So you end up with Opacity values in the exported GraphML, and when you import the GraphML into the NodeXL API, the Opacity, which has no meaning to the API, is ignored.  The structure of the graph gets properly imported, but not the attributes.

A possible workaround is to convert the GraphML attributes to API values after importing the GraphML into the API.  You could theoretically reuse the same code that the workbook uses to do this; they are all contained in the source code in the folder \NodeXL\ExcelTemplate\WorkbookReader\ValueConverters.  There is an AlphaConverter class, for example, that has this method:

        public Byte WorkbookToGraphAsByte(Single workbookValue)

So you would call GraphMLGraphAdapter.LoadGraphFromFile(), then loop through the graph's vertices and edges, looking for Opacity metadata values and replacing them with alpha values.  (Specifically, you would set the ReservedMetadataKeys.PerAlpha value on the vertices and edges.)

The problem is that those classes were not meant for and have not been tested in other applications, so I can't say how much work would be involved in reusing them or whether it's worth your trouble to try it.

-- Tony

Mar 15, 2012 at 5:13 AM

Thank you Tony, that helps a lot.  I will have to consider whether that is worth doing or not, and maybe test a little to see if I could get reasonable enough results with a subset of the functionality.

I looked at what you did for the NodeXL Graph Gallery from the client side, and that seems to make sense.  I am thinking of building an internal collaboration tool or plugin, so I may try to duplicate what you have with the post to Graph Gallery, to allow a small set of users to export and import their graphs (along with an image of it), thus sharing them and possibly allowing others to leverage them to make their own.



  Chris Achille