Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Populating a graph and retrieving node positions not working #362

Open
critical-pass opened this issue Dec 2, 2023 · 3 comments
Open

Populating a graph and retrieving node positions not working #362

critical-pass opened this issue Dec 2, 2023 · 3 comments

Comments

@critical-pass
Copy link

critical-pass commented Dec 2, 2023

I am trying to use the MSAGL library to generate node positions. I have gone through the samples and have not found a simple example that helps.

I have my own custom Graph object with a list of custom edges and custom nodes. I am iterating through them, adding them to the GeometryGraph, creating a layered layout, running the graph, iterating back through the nodes, and retrieving the node positions. The resulting nodes positions are incorrect, they are just about all overlapping. I tried scaling the positions by 100x but they still overlap. What am I doing wrong?
(Here's my code)

  1. I create nodes and edges. I make a dictionary for the nodes so I can reuse them in my edges.
Dictionary<string, Microsoft.Msagl.Core.Layout.Node> nMap = new Dictionary<string, Microsoft.Msagl.Core.Layout.Node>();
int radius = 12;
foreach (var myNode in myGraph.nodes)
{
    var curve = CurveFactory.CreateCircle(radius, new Point());

    // var node = new Microsoft.Msagl.Core.Layout.Node(curve, id);
    var node = new Microsoft.Msagl.Core.Layout.Node(curve, myNode.id.ToString());

    graph.Nodes.Add(node);
    nMap.Add(myNode.id.ToString(), mNode);
}

foreach (var activity in myGraph.activities)
{
    var source = nMap[activity.chartInfo.source_id.ToString()];
    var target = nMap[activity.chartInfo.target_id.ToString()];
    graph.GeometryGraph.Edges.Add(new Microsoft.Msagl.Core.Layout.Edge(source, target));
}
  1. Then I create my layout settings. I've tried changing properties on the settings to see if they produce different positions
var settings = new SugiyamaLayoutSettings
{
    Transformation = PlaneTransformation.Rotation(Math.PI / 2),
    EdgeRoutingSettings = { EdgeRoutingMode = Microsoft.Msagl.Core.Routing.EdgeRoutingMode.Spline }
};

// Tested these out but they didn't work
settings.MinimalHeight = 700;
settings.MinimalWidth = 1300;
settings.NodeSeparation = 200;

var llayout = new LayeredLayout(graph.GeometryGraph, settings);
llayout.Run();
  1. Then I get my custom nodes (from a dictionary lookup) and set the positions from the GeometryGraph nodes:
foreach(var node in graph.GeometryGraph.Nodes)
{
    var myNode = myGraphNodeMap[node.UserData.ToString()];
    myNode .x = (int)node.Center.X * 100;
    myNode .y = (int)node.Center.Y* 100;
}

Can someone point me in the right direction? What am I doing wrong?

As an aside, how would you create edges that curve around a node?

@levnach
Copy link
Contributor

levnach commented Dec 2, 2023

What is "id" here? var node = new Microsoft.Msagl.Core.Layout.Node(curve, id);
The edge routing in SplineMode is based on https://link.springer.com/content/pdf/10.1007/978-3-642-11805-0_15.pdf, building a sparse visibility graph and routing on it.

@critical-pass
Copy link
Author

Ah it was a typo, it should be:

var node = new Microsoft.Msagl.Core.Layout.Node(curve, myNode.id.ToString());

I'll modify it so it says the right thing.

@levnach
Copy link
Contributor

levnach commented Dec 3, 2023

Sorry, it is difficult to see what is happening without additional information. A full example would help. Maybe you can print out the msagl node positions as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants