Unable to get color image

Jun 25, 2010 at 8:59 PM
hey , I am trying to save a static image to the disk. So far I am successful in generating a graph and saving it on disk but I tried various things to set different color for nodes and edges which I am unable to do so. Though, following example from help file I am getting colors but problem is I have to manually add vertices..... In my case I am reading node and edges from a file and then using SimpleGraphAdapter. Please suggest me how can I add color to edges and nodes.. also how can I change size of the nodes. I am making a console application. It will be of great help if you can explain the steps. Thank you so much
Jun 26, 2010 at 4:09 AM
Edited Jun 26, 2010 at 4:10 AM

If your color and size information is stored in the file, then the SimpleGraphAdapter isn't going to help you.  All it reads is a two-field edge list (the two fields being the vertex names), which is why it's called "Simple."  There is another graph adapter called GraphMLGraphAdapter that will read color and size information, but only if the file is in GraphML format.  If you are reading some custom file format, then you are going to have to write your own file parser to read the file and create a Graph object from it, setting the color and size attributes on the graph's vertices in the process.

-- Tony

Jun 26, 2010 at 1:41 PM

Hey Tony, I think its my bad that I didn put the question right .. Actually I am reading just nodes and edges from the file and not the color information. What I want to achieve is the color image like one on NodeXL home page . I mean while generating graphs say 100 nodes are of same group so I want to give them say red color and also increase the size of the nodes . To put in straight way, how can I get colorful images while reading just nodes and edges from a file .. like passing the file to some adapter, laying out graphs and then saving the file and I get color image instead of black and white.

Jun 27, 2010 at 6:01 PM
Edited Jun 27, 2010 at 6:02 PM

Well, one thing you can do is to identify "vertex clusters" in your graph, and then assign different vertex color/size pairs to each cluster.  Clusters can be identified using a mathematical algorithm that analyzes the connections between vertices.  In NodeXL, clusters are identified using the Microsoft.NodeXL.Algorithms.ClusterCalculator class, which takes a Graph object and returns a collection of Community objects.  Each Community contains a collection of Vertex objects.  So all you need to do is pass your Graph to ClusterCalculator.CalculateGraphMetrics(), loop through the returned Community objects, and assign a unique color/size attribute pair to the vertices in each Community.  That will give you colorful, visually interesting results for many graphs.

How you choose your colors and sizes is entirely up to you.  In the NodeXL Excel Template, we assign color/shape pairs to clusters instead of color/size pairs.  This is done in the Microsoft.NodeXL.ExcelTemplate.ClusterCalculator2.GetVertexAttributes() method, which as of June 27, 2010 can be found here:

http://nodexl.codeplex.com/SourceControl/changeset/view/51265#395481

-- Tony

Jun 28, 2010 at 3:38 PM
I will follow the way you suggested . thanks Tony, you been great help
Feb 15, 2011 at 4:53 PM

Hi,

 

My problem is... I can change the colors on the vertex group menu (I enter colors for my vertexs- G1, G2, etc).  But then, when I save my file, the colors go away and everything is one color (purple).  How do I change it back?

Feb 15, 2011 at 5:22 PM

Amanda:

If I understand correctly, you are manually entering colors in the Vertex Color column on the Groups worksheet.  Two questions:

1. When you save the workbook and then reopen it, are your manually-entered colors sill there in the Groups worksheet?

2. In the Excel ribbon, is NodeXL, Show/Hide, Graph Elements, Groups checked?

-- Tony

Feb 15, 2011 at 5:31 PM
Yes, the colors are still listed. They go away when I refresh the graph and when I save it. The shapes aren't there either. I have tried it with the groups checked and unchecked- no difference.
Feb 15, 2011 at 5:47 PM
Edited Feb 15, 2011 at 5:48 PM

I don't understand what you mean when you say that the colors are still listed when you reopen the workbook, but they go away when you save it.  To clarify the situation, please do the following:

1. Enter colors and shapes for your groups on the Groups worksheet.  (This is usually done automatically using the NodeXL, Analysis, Groups menu, but it sounds like you want to do it manually, which is fine.)

2. Click Refresh Graph.

3. Do your shapes and colors show up in the graph pane on the right side of the Excel window?

4. Save the workbook.

5. Close the workbook.

6. Reopen the workbook.  Are your shapes and colors still listed in the Groups worksheet?

7. Click Show Graph.  Do your shapes and colors show up in the graph pane?

-- Tony

Feb 16, 2011 at 3:38 AM
They're actually listed, they just aren't showing up. The colors next to the groups say "cyan, yellow, etc" but the colors on the vertexs on the actual graph are all purple.
Feb 16, 2011 at 4:41 PM

Amanda:

The only way I know of that the group colors won't show up is to have NodeXL, Show/Hide, Graph Elements, Group unchecked.  Can you please verify again that that checkbox is indeed checked when you refresh the graph?

If that doesn't fix it, you can post a small sample workbook that demonstrates the problem on the Issue Tracker tab of our CodePlex Web site:

http://nodexl.codeplex.com/workitem/list/basic

If you do that, I'll look at your workbook and see if I can figure out what's going on.

-- Tony