C# MSAGL - How to create: Title, Subtitle on nodes and Tooltip on edge

571 views Asked by At

I'm trying to build a graph that will represent DB relations so I would like each node to have a title with the table name and sub title which will represent the different keys of the table and on the edge a string with the relation such as:"each table1 may have many table2".

is it possible and if so how?

Thanks.

1

There are 1 answers

1
amonroejj On

Here's how I did it:

        Microsoft.Msagl.Drawing.Node visnode = new Microsoft.Msagl.Drawing.Node($"{n.NodeId}: {n.NodeName}") { UserData = n };
        visnode.NodeBoundaryDelegate    = GetNodeBoundary;
        visnode.DrawNodeDelegate        = DrawNode;
        ICurve GetNodeBoundary(Microsoft.Msagl.Drawing.Node node) {
            return CurveFactory.CreateRectangle(500, 50, new Microsoft.Msagl.Core.Geometry.Point(0,0) );
        }

        private bool DrawNode(Microsoft.Msagl.Drawing.Node node, object graphics)
        {
            Graphics g = (Graphics)graphics;
            Node n = (Node)node.UserData;

            // fiddle with g.transform (this took a ton of trial and error, and cribbing from 
            // the NodesWithImages sample code from MSAGL)
            // see also https://stackoverflow.com/q/70855662/2112855
            // g.FillRectangle, g.DrawString...
        }