Expose Linqpad's Automatic Graph Layout to Util

Hi. As Linqpad uses it internally it would be great to have MSAGL exposed to Util or some other class to draw graphs from script. Even it can be done via fluen interface:
.Text("x1","Reqest creation start")
.Command("x3","User creates request")
public GraphBuilder Circle(string id,string text){
return this
.WithNodeLabel(x=>x.FontName = "Calibri")
.WithNodeLabel(x=>x.FontSize = 10)
As MSAGL has very cool layout functionality it can be used to draw graphs and activity-diagrams from code as diagram as code approach.
Is it possible to implement?


  • Options

    I'm not sure that anything new is required in LINQPad here. You can add a NuGet package reference to Microsoft.Msagl.GraphViewerGDI and then Dump a GViewer:

    Microsoft.Msagl.GraphViewerGdi.GViewer viewer = new Microsoft.Msagl.GraphViewerGdi.GViewer();
    Microsoft.Msagl.Drawing.Graph graph = new Microsoft.Msagl.Drawing.Graph("graph");
    graph.AddEdge("A", "B");
    graph.AddEdge("B", "C");
    graph.AddEdge ("A", "C").Attr.Color = Microsoft.Msagl.Drawing.Color.Green;
    graph.FindNode ("A").Attr.FillColor = Microsoft.Msagl.Drawing.Color.Magenta;
    graph.FindNode ("B").Attr.FillColor = Microsoft.Msagl.Drawing.Color.MistyRose;
    Microsoft.Msagl.Drawing.Node c = graph.FindNode ("C");
    c.Attr.FillColor = Microsoft.Msagl.Drawing.Color.PaleGreen;
    c.Attr.Shape = Microsoft.Msagl.Drawing.Shape.Diamond;
    viewer.Graph = graph;

    In terms of a fluent interface, this sounds like it should be in library a that be used in other projects as well.

  • Options

    I already did, it's just an idea that came into my mind afrer I googled your post on stackoverflow that you forked your own version of MSAGL without Winforms dependancy especially for linqpad for net core. I played around with MSAGL for a while and wrote a small wrapper for fluent interface for MSAGL to implement a small graph describing DSL. But unfortunatly after I played with SVG writer class from MSAGL it turned out that it's only partly implemented and contains errors (doesn't write font attributed to svg).

  • Options

    I see. The story is that I forked MSAGL in 2019 to make it run on .NET Core (although the viewer still depends on WinForms). It was a very simple port - mainly to remove an unnecessary dependency on System.Data.SqlClient.

    The fork is no longer necessary, because Microsoft released a .NET 6/7 compatible package in 2023.

  • Options

    Ok. Thanks for the reply.

Sign In or Register to comment.