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

Node BoundaryCurve has no effect #357

Open
bbenami opened this issue Aug 20, 2023 · 1 comment
Open

Node BoundaryCurve has no effect #357

bbenami opened this issue Aug 20, 2023 · 1 comment

Comments

@bbenami
Copy link

bbenami commented Aug 20, 2023

I'm trying to define the size of a node explicitly. I've tried setting the label width/height as well as setting the node's boundarycurve. Both does to seem to make any effect of the node size.
Below is my sample code.
What am I missing?

        Microsoft.Msagl.Drawing.Graph graph = new Microsoft.Msagl.Drawing.Graph("");
        graph.AddEdge("A", "B");
        graph.AddEdge("B", "C");

        int nwidth = 100;
        int nheight = 100;

        var geometryGraph = graph.CreateGeometryGraph();
        var n = graph.FindNode("A");
        n.Label.GeometryLabel = new Microsoft.Msagl.Core.Layout.Label();
        n.Label.GeometryLabel.Width = nwidth;
        n.Label.GeometryLabel.Height = nwidth;
        n.Label.Width = nwidth;
        n.Label.Height = nheight;
        int r = n.Attr.LabelMargin;
        n.GeometryNode.BoundaryCurve = CurveFactory.CreateRectangleWithRoundedCorners(nwidth + r * 2, nheight + r * 2, r, r, new Point());

        graph.Attr.LayerDirection = LayerDirection.LR;
        geometryGraph.UpdateBoundingBox();

        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\\test.png");
@levnach
Copy link
Contributor

levnach commented Aug 20, 2023

It seems GraphRenderer creates new geometry blindly, even when the drawing graph already has the geometry associated with it. The way to control the shape of the nodes is to use a delegate for the geometry node boundary curve: the code below demonstrates it:
` Microsoft.Msagl.Drawing.Graph graph = new Microsoft.Msagl.Drawing.Graph("");
graph.AddEdge("A", "B");
graph.AddEdge("B", "C");

            int nwidth = 100;
            int nheight = 100;

            var n = graph.FindNode("A");
            int r = n.Attr.LabelMargin;
            n.NodeBoundaryDelegate = new DelegateToSetNodeBoundary(p => CurveFactory.CreateRectangleWithRoundedCorners(nwidth + r * 2, nheight + r * 2, r, r, new Microsoft.Msagl.Core.Geometry.Point()));

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

            int lwidth = 1500;
            Bitmap bitmap = new Bitmap(lwidth, (int)(graph.Height * (lwidth / graph.Width)), PixelFormat.Format32bppPArgb);
            renderer.Render(bitmap);
            bitmap.Save("c:\\tmp\\test.png");`

test

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