automatic locate the vertex's location?

Dec 20, 2012 at 11:47 AM

  Hi! NodeXL is a nice, magic and powerful tool for visual graph analysis. I'm Programming by using NodeXL, C# windows form. But I think there are not many graph algorithms in NodeXL. So I wrote some algorithms, such as dfs, minimum spanning tree, shortest path and so on. Now, I got a problem. There are a NodexlControl and a listviewControl in my program. Listview shows the vertexes in the NodeXl's Vertices (just like excel). when I zoom out the graph,  GraphZoom increases( >1.0, <= 10.0). I click a vertex in listView, this vertex is placed into the  NodeXL's selection. but this vertex's Location is outside of NodeXl's current view. I have to zoom in the graph (GraphZoom=1.0), then I can see the highlighted vertex. I want to know how could I  put the vertex in the center of current view of NodeXL when I click a vertex in magnified graph (GraphZoom> 1.0), API?

Dec 21, 2012 at 5:29 AM
Edited Dec 21, 2012 at 5:44 AM


The NodeXLControl doesn't provide a method for doing that.  If it's a requirement for your project, you'll have to do a bit of custom programming.

The control sets the position of the graph relative to the control's boundaries by internally manipulating a TranslateTransform.  That TranslateTransform is one of two Transform objects the control owns, the other being a ScaleTransform that determines the graph's zoom factor.  Although the control has properties for getting those Transforms, the properties are protected and so you can't get to them directly from your application.  I did that deliberately, because I didn't want applications interfering with the control's internal use of those Transforms.

But you could create your own DougsNodeXLControl that derives from NodeXLControl, and add a PutVertexAtTheCenterOfTheGraph(IVertex) method to your derived class.  Your method could retrieve the TranslateTransform from the protected NodeXLControl.TranslateTransformForRender property, and manipulate the transform to force the vertex to be centered within the control's boundaries.  You'll have to look at how the control is using the Transform internally to figure out how to calculate and set the TranslateTransform.X and Y properties to achieve your desired effect.

You don't need the NodeXL source code to do this, although you can view the control's source code file at  Just create a new control in a new assembly and derive it from NodeXLControl.

-- Tony

Jan 7, 2013 at 1:53 PM

To set the TranslateTransform.X and Y I can move the nodexl's view in the 2-D x-y coordinate system. Now I have a list of all vertices, when I click one row in this list, I hope the clicked vertex in the row can appear in the center of nodexl's current view. For example, there is a vertex and it's location is out of current view when the graph is zoomed out, how can I get the correct value to set TranslateTransform.X and Y? I tried many times, but always moving the view with deviation.

Happy new year 2013, dear tcap479!

Jan 7, 2013 at 1:59 PM

I just want to get a little more detailed ideas about how to calculate the TranslateTransform.X and Y :P

Jan 8, 2013 at 6:19 AM


The origin of the control is at its upper-left corner.  When the TranslateTransform.X and Y values are at their default values of zero, a vertex that has a Vertex.Location value of (0,0) will be at the control's upper-left corner.

The effect of non-zero TranslateTransform values is to shift the entire graph within the control.  If you set TranslateTransform.X to 10 and TranslateTransform.Y to 20, for example, then a vertex that has a Vertex.Location value of (0,0) will now be at the point (10,20) within the control.

So to center a vertex, you need to set TranslateTransform.X to (ControlWidth/2 - Vertex.Location.X) and TranslateTransform.Y to (ControlHeight/2 - Vertex.Location.Y).

Give that a try.

-- Tony

Jan 8, 2013 at 12:41 PM

I have solved this problem yesterday night, thank you very much , dear tcap479 :P