microsoft / automatic-graph-layout

A set of tools for graph layout and viewing
Other
1.34k stars 301 forks source link

How to move Node position programatically? #331

Closed GlennOwen closed 1 year ago

GlennOwen commented 1 year ago

I have a graph on which nodes are drawn and use the Sugiyama layout. I want the blue nodes to come perpendicular to the circle node. Is there a way that a node's position can be changed programmatically? I tried looking around a lot, but couldn't find it. I also tried using the below code, but I am getting an object reference error message.

graph.FindNode("I" + actionId).GeometryNode.Center = new Microsoft.Msagl.Core.Geometry.Point(100, 100);

image

Any help or pointers will be appreciated.

levnach commented 1 year ago

This approach has two issues. The first one is that the edge geometries are not recalculated. The second one is that the changes in the geometry, the new node positions, are not communicated to the viewer. The viewer can be notified by calling public void Invalidate(IViewerObject objectToInvalidate); of GViewer, or GViewer.Invalidate() without parameters to redraw everything. Another approach, which seems to be cleaner, is to add a delegate to GeometryGraph that applies the user changes at the very end of the layout. Something like `public delegate void GeometryGraphDelegate(GeometryGraph g);

public class GeometryGraph : GeometryObject { public GeometryGraphDelegate UserAdditionalLayout;`

This way the user's changes of the geometry will be passed to the viewer by the standard procedure.

GlennOwen commented 1 year ago

Thanks a ton Lev. I will work on this.