microsoft / automatic-graph-layout

A set of tools for graph layout and viewing
Other
1.36k stars 304 forks source link

Graph spacing #358

Open bbenami opened 1 year ago

bbenami commented 1 year ago

I use custom node size and the graph looks too dense. I tried to make more space between the nodes by setting the node separation and layer separation but they both do not seems to make any effect.

       Microsoft.Msagl.Drawing.Graph graph = new Microsoft.Msagl.Drawing.Graph("");
        graph.AddEdge("A", "B");
        graph.AddEdge("B", "C");
        graph.AddEdge("C", "D");
        graph.AddEdge("C", "E");
        graph.AddEdge("C", "F");
        graph.AddEdge("C", "G");
        graph.AddEdge("A", "H");
        graph.AddEdge("E", "H");
        graph.AddEdge("F", "H");

        foreach (var node in graph.Nodes)
        {
            int w = 150;
            int h = 80;

            node.NodeBoundaryDelegate = new DelegateToSetNodeBoundary(p => CurveFactory.CreateRectangle(w, h, new Microsoft.Msagl.Core.Geometry.Point()));
        }

        graph.Attr.LayerDirection = LayerDirection.LR;
        graph.Attr.NodeSeparation = 200;
        graph.Attr.LayerSeparation = 200;

        Microsoft.Msagl.GraphViewerGdi.GraphRenderer renderer = new Microsoft.Msagl.GraphViewerGdi.GraphRenderer(graph);
        renderer.CalculateLayout();

        int width = 1500;
        Bitmap bitmap = new Bitmap(width, (int)(graph.Height * (width / graph.Width)), PixelFormat.Format32bppPArgb);
        renderer.Render(bitmap);
        bitmap.Save("c:\\temp\\test2.png");

image

levnach commented 1 year ago

Try to use SugiyamaLayoutSettings.LayerSeparation and SugiamaLayoutSettings.NodeSeparation