microsoft / automatic-graph-layout

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

How to move Node Labels above the node circle? #293

Closed NiklasVJM closed 3 years ago

NiklasVJM commented 3 years ago

Hi!

I have tried to move the labels of the nodes around, but with no success. I would like to place the node above the node circle (and for some, below the node circle), but this code provided seems to make no difference. Can you help me out with this?

       private static void SetNodeBoundary(Node drawingNode)
        {
        var font = new System.Drawing.Font(drawingNode.Label.FontName, (float) drawingNode.Label.FontSize);
        StringMeasure.MeasureWithFont(drawingNode.LabelText, font, out var width, out var height);
        drawingNode.Label.GeometryLabel = new Microsoft.Msagl.Core.Layout.Label();
        drawingNode.Label.GeometryLabel.Side = Label.PlacementSide.Top;

        drawingNode.Label.GeometryLabel.Width = width;
        drawingNode.Label.GeometryLabel.Height = width;

        drawingNode.Label.Width = width;
        drawingNode.Label.Height = -30;

        var r = drawingNode.Attr.LabelMargin;

        drawingNode.GeometryNode.BoundaryCurve =
            CurveFactory.CreateRectangleWithRoundedCorners(height + r * 2, height + r * 2, r, r, new Point(0,0));

    }
levnach commented 3 years ago

It seems you need to get into routine that draws a node and modify it.

NiklasVJM commented 3 years ago

Hi!

Thank you for the reply!

Can you explain a little further? You mean I need to modify the labels in some other place, or something? A small code snippet would be awesome. Thank you!

levnach commented 3 years ago

I was suggesting that you modify method DGraph::DrawNode. Actually, you can get around it by using DrawNodeDelegate, as in sample NodesWithImages. Anyway, you need a customized node drawing routine, and I seem do not have a sample for it, except of DrawNode() in NodesWithImages.

NiklasVJM commented 3 years ago

Ok! Thank you so much for this help! I will give this a try, of course it would be awesome to see, how a "pro" would do it, but I'll give this a go. Thank you!